How to properly manage categories in django admin?
I have register my models in admin.py
as
admin.site.register(Food_Gallery)
admin.site.register(Gym)
admin.site.register(Gym_Gallery)
admin.site.register(Gym_Pricing_Plans)
admin.site.register(Gym_Programs)
admin.site.register(Trainer)
admin.site.register(Farm)
admin.site.register(Farm_Gallery)
admin.site.register(Farm_Products)
This shows all the models in a single page in django admin
I want to categorize these models into certain categories and display their respective models.How to manage this?
Certain examples as
Food
Gym
Farm
you need declare new app and add it to installed_apps
and then add app_label
to your models
see app_label
here
In Simple Way Please Create separate App for separate model categories.
You Have To Create App like.
python manage.py startapp food
python manage.py startapp gym
python manage.py startapp farm
INSTALLED_APP += [
'farm',
'food',
'gym',
]
Then Add in admin.py
admin.site.register(food)
admin.site.register(gym)
admin.site.register(farm)
This is write way.
Hmm, I can't think of an easy way to do this as django admin has no notion of hierarchies besides apps and models. You could try the approach Akash suggested, use custom admins pages with StackedInline
s or you could use django-admirarchy but I'm not sure that's what you want either.
There are two ways.
1. Customize the Django admin site.
https://docs.djangoproject.com/en/4.0/intro/tutorial07/#customize-the-admin-index-page
2. Create different apps for each categories.
In terminal,
python manage.py startapp food
python manage.py startapp gym
python manage.py startapp farm
In food/admin.py file,
admin.site.register(Food_Gallery)
In gym/admin.py file,
admin.site.register(Gym)
admin.site.register(Gym_Gallery)
admin.site.register(Gym_Pricing_Plans)
admin.site.register(Gym_Programs)
admin.site.register(Trainer)
In farm/admin.py file,
admin.site.register(Farm)
admin.site.register(Farm_Gallery)
admin.site.register(Farm_Products)
You also have to add your apps in settings.py
file and maybe you need to modify some of your code.
Each method has its pros and cons, so it is up to you which to use.