请参阅下面的models.py/admin.py
当我尝试更改或添加FashionMaleModel时,内联不会出现,但它们会在FashionFemaleModel中出现。如果我更改管理网站的注册顺序,将男性放在女性下面,那么内联只显示在FashionMaleModel中,而不是FashionFemaleModel。
为什么我的内联只显示在一个或另一个?
谢谢!
我已经截断了这些模型,因为有很多。另外,FashionObject / FashionPage是我创建的基类,它是id,name,publish_date等自定义CMS的一部分。
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)
答案 0 :(得分:1)
我从FashionMaleModelAdmin和FashionFemaleModelAdmin类中取出了__init__
函数,然后我在每个函数中单独定义了内联:
inlines = (FashionModelPhotoInline, FashionExperienceInline)
似乎工作。感谢所有看过这个的人。