Nested inlines in the Django admin?

后端 未结 5 813
春和景丽
春和景丽 2020-11-28 12:28

Alright, I have a fairly simple design.

class Update(models.Model):
    pub_date = models.DateField()
    title = models.CharField(max_length=512)

class Pos         


        
5条回答
  •  春和景丽
    2020-11-28 12:54

    I ran into a similar issue to this. My approach was to make an UpdateAdmin that held inlines for both Media and Post... it basically just makes it so you have a list of all of the media entries followed by all of the posts in an update.

    class MediaInline(admin.StackedInline):
            model = Media
    
    class PostInline(admin.StackedInline):
            model = Post
    
    class PostAdmin(admin.ModelAdmin):
            inlines = [MediaInline,]
    
    class UpdateAdmin(admin.ModelAdmin):
            inlines = [MediaInline,PostInline]
    

    It isn't an ideal solution but it works for a quick and dirty work around.

提交回复
热议问题