23👍
The inline model should be having a ForeignKey to the parent model. To get Photo
as inline in Author
your models code is fine. But your admin code should be as follows:
class PhotoInline(admin.StackedInline):
model = Photo
class AuthorAdmin(admin.ModelAdmin):
list_display = ('display_name','user_email')
inlines = [PhotoInline]
Read more info here.
4👍
That’s because Author
doesn’t have a foreign key to photo. I think you need to switch the model for the inline like this:
class PhotoInline(admin.StackedInline):
model = Photo
class AuthorAdmin(admin.ModelAdmin):
list_display = ('display_name','user_email')
inlines = [PhotoInline]
- Using a Django variable in a CSS file
- Django: Natural Sort QuerySet
- Django – Import views from separate apps
- Django update on queryset to change ID of ForeignKey
- How to override template in django-allauth?
0👍
Maybe you need to install django-nested-admin library, and later try with NestedStackedInline.
django-nested-admin
- Django and Celery – ModuleNotFoundError: No module named 'celery.task'
- Django QuerySet Custom Ordering by ID
- Adding prefix path to static files in Angular using angular-cli
- 'Questions ' object is not iterable Django
Source:stackexchange.com