我有一个Person类和一个Contract类。在管理界面中,我想在进入Person页面时显示与每个人相关的合同,而不仅仅是我在Person类中拥有的数据。
那么,首先,我可以在Person中显示我在合同中的数据吗?
其次,我如何能够展示与该人有关的合同而不是所有合同?我的意思是,我不想在每个人的合同中只显示与该特定人有关的合同。
感谢。
class Person(models.Model):
name = models.CharField(max_length=32, verbose_name=_(u"Name"))
surname = models.CharField(max_length=32, verbose_name=_(u"Surname"))
address = models.CharField(max_length=32, verbose_name=_(u"Address"))
class Contract(models.Model):
person = models.ForeignKey(Person) #person hired
contract = models.OneToOneField('self', blank = True, null = True) #allows to extend a contract
project = models.ForeignKey(Project, blank = True, null = True) #related project
答案 0 :(得分:0)
class ContractInline(admin.TabularInline):
model = Contract
extra = 1
@admin.register(Person)
class Person(admin.ModelAdmin):
list_filter = ["........"]
list_display = ["........"]
inlines = [ ContractInline, ]