Django Admin 嵌套内联 [英] Django Admin nested inline
问题描述
我需要一个嵌套的 django 管理内联,我可以将日期字段内联包含在如下所示的其他内联中.
I need a nested django admin inline, which I can include the date field inlines in an other inline like 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)
和下面的管理员:
class CertificateInline(admin.StackedInline):
model = Certificate
class PersonAdmin(admin.ModelAdmin):
inlines = [CertificateInline,]
admin.site.register(Person,PersonAdmin)
但我需要将 Training_Date 模型作为内联模型包含在内,这是证书管理员内联的一部分.
but i need to include the Training_Date model as inline which is part of Certificate admin inline.
有什么想法吗?
推荐答案
AFAIK,您不能在默认的 Django 管理员中设置第二级内联.
AFAIK, you can't have a second level of inlines in the default Django admin.
Django admin 只是一个普通的 Django 应用程序,因此没有什么可以阻止您实现第二级嵌套表单,但恕我直言,这将是一种复杂的设计.也许这就是为什么没有规定的原因.
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 Admin 嵌套内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!