49👍
You can use “Inlines” to visualize and edit Things of a certain Category in the admin detail for that category:
In the admin.py file, create an Inline object for Thing (ThingInline) and modify your CategoryAdmin class to have an inline of type ThingInline like this:
...
class ThingInline(admin.TabularInline):
model = Thing
class CategoryAdmin(admin.ModelAdmin):
inlines = [
ThingInline,
]
...
For further details, this is the docs for admin inlines: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects
10👍
update admin.py
file like this.
from django.contrib import admin
from .views import Category, Thing
class CategoryAdmin(admin.ModelAdmin):
inlines = [
ThingInline,
]
class ThingInline(admin.TabularInline):
model = Thing
admin.site.register(Category, CategoryAdmin)
admin.site.register(Thing)
There are two inline options TabularInline
and StackedInline
- [Django]-Use "contains" and "iexact" at the same query in DJANGO
- [Django]-Manager isn't accessible via model instances
- [Django]-Django: using <select multiple> and POST
4👍
Few minutes ago, searching how to solve a similar problem, I finally found a solution.
You actually have to follow @Matteo Scotuzzi answer as well, then
Inside admin.py located in the app your created those models, you have to declare as follows right bellow @Matteo snippet:
admin.site.register(Category, CategoryAdmin)
and that would be enough to make all "Things" appear in "Category" inside your Django Administration respective page which is "Category".
- [Django]-Getting 'str' object has no attribute 'get' in Django
- [Django]-How to check if an element is present in a Django queryset?
- [Django]-(13: Permission denied) while connecting to upstream:[nginx]