Missing inlines in Django Admin

1.2k views Asked by At

See below for models.py/admin.py

When I try to change or add a FashionMaleModel, the inlines don't appear, but they do in FashionFemaleModel. If I change the order in which the admin sites are registered, putting Male below Female, then the inlines only show up in FashionMaleModel, and not FashionFemaleModel.

Why are my inlines only showing up in one or the other?

Thanks!


I've truncated these models because there's a lot. Also, FashionObject/FashionPage are base classes I've created as part of a custom CMS with id, name, publish_date, etc.

models.py:

class FashionModelRole(models.Model):
    title = models.CharField(max_length=255,)

class FashionModelContributor(models.Model):
    role = models.ForeignKey(FashionModelRole)
    person = models.ForeignKey(FashionModelPerson, related_name='contributions')

class FashionModel(FashionObject):
    gender = models.CharField(max_length=1,choices=(('F','Female'),('M','Male')), 
editable=False)

class FashionExperience(models.Model):
    model = models.ForeignKey(FashionModel, related_name = 'experience')
    division = models.ForeignKey(FashionDivision, related_name = 'levels')
    experience = models.CharField(max_length=1,choices=(('5','Professional'),('4','Advanced'),('3','Intermediate'),('2','Developing'),('1','Recreational'),))

class FashionMaleModel(FashionModel):
    jacket_size = MeasurementField(max_length=6, blank=True, null=True)

    def __init__(self, *args, **kwargs):
        super(FashionMaleModel, self).__init__(*args, **kwargs)
        self.gender = 'M'

class FashionFemaleModel(FashionModel):
    dress_size = MeasurementField(max_length=6, blank=True, null=True)

    def __init__(self, *args, **kwargs):
        super(FashionFemaleModel, self).__init__(*args, **kwargs)
        self.gender = 'F'

class FashionModelPhoto(models.Model):
    model = models.ForeignKey(FashionModel, related_name = 'photos')
    contributors = models.ManyToManyField(FashionModelContributor, null=True, blank=True)

admin.py:

class FashionExperienceInline(admin.TabularInline):
    model = FashionExperience

class FashionModelPhotoInline(admin.TabularInline):
    model = FashionModelPhoto

class FashionDivisionAdmin(FashionPageAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionDivisionAdmin, self).__init__(*args, **kwargs)

class FashionModelAdmin(FashionObjectAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionModelAdmin, self).__init__(*args, **kwargs)
        self.inlines += (
            FashionModelPhotoInline,
            FashionExperienceInline,
            )

class FashionMaleModelAdmin(FashionModelAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionMaleModelAdmin, self).__init__(*args, **kwargs)

class FashionFemaleModelAdmin(FashionModelAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionFemaleModelAdmin, self).__init__(*args, **kwargs)

class FashionModelPersonAdmin(admin.ModelAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionModelPersonAdmin, self).__init__(*args, **kwargs)

class FashionModelRoleAdmin(admin.ModelAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionModelRoleAdmin, self).__init__(*args, **kwargs)        

class FashionModelContributorAdmin(admin.ModelAdmin):
    def __init__(self, *args, **kwargs):
        super(FashionModelContributorAdmin, self).__init__(*args, **kwargs)

admin.site.register(FashionMaleModel, FashionMaleModelAdmin)
admin.site.register(FashionFemaleModel, FashionFemaleModelAdmin)
admin.site.register(FashionDivision, FashionDivisionAdmin)
admin.site.register(FashionModelPerson, FashionModelPersonAdmin)
admin.site.register(FashionModelRole, FashionModelRoleAdmin)
admin.site.register(FashionModelContributor, FashionModelContributorAdmin)
1

There are 1 answers

1
Lexo On BEST ANSWER

I took out the __init__ functions from the FashionMaleModelAdmin and FashionFemaleModelAdmin classes, then I defined the inlines separately inside each one:

inlines = (FashionModelPhotoInline, FashionExperienceInline)

Seems to work. Thanks to everyone who took a look at this.