Django Admin 中缺少内联
请参阅下面的 models.py/admin.py
当我尝试更改或添加 FashionMaleModel 时,内联不会出现,但它们会出现在 FashionFemaleModel 中。如果我更改管理站点的注册顺序,将男性置于女性之下,则内联仅显示在 FashionMaleModel 中,而不显示在 FashionFemaleModel 中。
为什么我的内联只出现在其中之一中?
谢谢!
我已经截断了这些模型,因为它们太多了。此外,FashionObject/FashionPage 是我作为自定义 CMS 的一部分创建的基类,其中包含 id、名称、publish_date 等。
models.py:admin.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)
:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从 FashionMaleModelAdmin 和 FashionFemaleModelAdmin 类中取出了 __init__ 函数,然后在每个函数中分别定义了内联:
似乎有效。感谢所有看过此内容的人。
I took out the
__init__
functions from the FashionMaleModelAdmin and FashionFemaleModelAdmin classes, then I defined the inlines separately inside each one:Seems to work. Thanks to everyone who took a look at this.