Nested inlines in the Django admin?

后端 未结 5 819
春和景丽
春和景丽 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 13:18

    I have done this using https://github.com/theatlantic/django-nested-admin, for the following Data structure:

    • Contest
      • Judges
      • Contestants
        • Singers
        • Songs

    My admin.pyfile:

    from django.contrib import admin
    import nested_admin
    
    from .models import Contest, Contestant, Judge, Song, Singer    
    
    class SongInline(nested_admin.NestedTabularInline):
        model = Song
        extra = 0
    
    class SingerInline(nested_admin.NestedTabularInline):
        model = Singer
        extra = 0
    
    class ContestantInline(nested_admin.NestedTabularInline):
        model = Contestant
        inlines = [SongInline, SingerInline]
        extra = 0
    
    class JudgeInline(nested_admin.NestedTabularInline):
        model = Judge
        extra = 0
    
    class ContestAdmin(nested_admin.NestedModelAdmin):
        model = Contest
        inlines = [ContestantInline, JudgeInline]
        extra = 0
    
    admin.site.register(Contest, ContestAdmin)
    

    https://github.com/theatlantic/django-nested-admin appears to be much more actively maintained than the other apps already mentioned (https://github.com/BertrandBordage/django-super-inlines and https://github.com/Soaa-/django-nested-inlines)

提交回复
热议问题