How to implement browse by field type


#1

Hi there! I’m trying to allow users to browse my Things by category. So far I created a new field in my Thing model, say “Tag1”, which will be one of maybe 10 options like Womens, Mens, Shoes, Accessories (maybe many in the future)

I’ve been trying to use the example of the Browse by Initial example but can’t seem to translate it for this.

I should be able to do the url and view, but going through and displaying the Things and only picking ones with same tag1’s has tripped me up


#2

Nevermind I figured it out all on my own!


#3

Yay, glad to hear that! How did you solve it?


#4

Something like this:

In views.py
def browse_women(request):
brands = Brand.objects.filter(
tag1=“Women”).order_by(‘name’)
return render(request, ‘search/women.html’, {
‘brands’: brands,
})

And then in women.html
{% for brand in brands %}

Probably not the best way because I have to duplicate a new template and view for each category rather than looping but it’s ok!