Django管理嵌套内联 [英] Django Admin nested inline
问题描述
我需要一个嵌套的django管理员内联
,我可以在其他内联中包含日期字段内嵌,如下所示。
我有以下模型:
class Person(models.Model):
name = models.CharField(max_length = 200)
id_no = models.IntegerField()
类证书(models.Model):
cerfificate_no = models.CharField(max_length = 200)
certificate_date = models.DateField(max_length = 100)
person = models.ForeignKey(Person)
training = models.CharField(max_length = 200)
class Training_Date(models.Model):
date = models.DateField()
certificate = models.ForeignKey(Certificate)
和管理员下面:
class CertificateInline(admin.StackedInline):
model = Certificate
class PersonAdmin (admin.ModelAdmin):
inlines = [CertificateInline,]
admin.site.register(Person,PersonAdmi n)
但是,我需要将Training_Date模型作为内部证书管理的一部分内联。 / p>
任何想法?
AFAIK,您不能在默认Django管理员中具有第二级内联。
Django管理员只是一个正常的Django应用程序,所以没有什么可以阻止您实现第二级嵌套表单,但是IMHO将是一种复杂的设计来实现。也许这就是为什么没有条款。
I need a nested django admin inline, which I can include the date field inlines in an other inline like below.
I have the models below:
class Person(models.Model):
name = models.CharField(max_length=200)
id_no = models.IntegerField()
class Certificate(models.Model):
cerfificate_no = models.CharField(max_length=200)
certificate_date = models.DateField(max_length=100)
person = models.ForeignKey(Person)
training = models.CharField(max_length=200)
class Training_Date(models.Model):
date = models.DateField()
certificate = models.ForeignKey(Certificate)
and the admin below:
class CertificateInline(admin.StackedInline):
model = Certificate
class PersonAdmin(admin.ModelAdmin):
inlines = [CertificateInline,]
admin.site.register(Person,PersonAdmin)
but i need to include the Training_Date model as inline which is part of Certificate admin inline.
Any idea ?
AFAIK, you can't have a second level of inlines in the default Django admin.
The Django admin is just a normal Django application, so nothing prevents you from implementing a second level of nested forms, but IMHO it would be a kind of convoluted design to implement. Perhaps that is why there is no provision for it.
这篇关于Django管理嵌套内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!