1 | initial version |
To use Django admin inlines from a second model when the child of the first model has a OneToOne relationship with the second model, you can follow these steps:
class FirstModel(models.Model):
# fields for FirstModel here
class SecondModel(models.Model):
first_model = models.OneToOneField(FirstModel, on_delete=models.CASCADE)
# fields for SecondModel here
class SecondModelInline(admin.StackedInline):
model = SecondModel
class FirstModelAdmin(admin.ModelAdmin):
inlines = [SecondModelInline]
admin.site.register(FirstModel, FirstModelAdmin)
Now you should be able to manage SecondModel objects inline in the admin interface for a FirstModel object.