Categories and shoe Subcategories according to the parent category.

67 views
Skip to first unread message

saqlain abbas

unread,
May 18, 2020, 7:50:19 AM5/18/20
to Django users
Hi, if i add Categories , for example 
1)accessories
2)sports
3)books
Subcategories:
accessories is the parent category
child categories are 
watches
jewlry
caps 
how can i show if  user selects the parent category accessories then the subcategories show according to parent categories like subcategories are watches jewlry etc

saqlain abbas

unread,
May 19, 2020, 6:27:48 PM5/19/20
to django...@googlegroups.com
Please tell me if anyone knows about this.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1530c511-072f-44ee-83fa-3555bd090a89%40googlegroups.com.

Antje Kazimiers

unread,
May 19, 2020, 6:52:51 PM5/19/20
to django...@googlegroups.com

you could have a field "parent" in your Model Category which is a ForeignKey to Category itself, so Category is a self-referencing table.

Then in your first dropdown you only show those entries where parent is None and in your second one where parent == accessories.

you need to get this right with your view which would be show_child_categories where you pass the id of your parent and filter for it in your view function.

hope that helps, antje

Clive Bruton

unread,
May 19, 2020, 7:45:57 PM5/19/20
to django...@googlegroups.com
There are django modules for hierarchical navigation

https://djangopackages.org/grids/g/navigation/


-- Clive
> d/msgid/django-users/CAP6Ddn3zr%2BsfaL6DGMHb-
> xsLpE1zKcToKjKEqoPU6PCgGqjh1w%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages