[Django]-How to categorize in django admin?

4👍

Simply please create a separate App for separate model categories.

You can create app like this (settings.py):

python manage.py startapp food
python manage.py startapp gym
python manage.py startapp farm

INSTALLED_APP += [
   'farm',
   'food',
   'gym',
]

And in admin.py:

admin.site.register(food)
admin.site.register(gym)
admin.site.register(farm)

This is right way.

1👍

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.

Leave a comment