如何让 Django 在后端将 AnotherAim.aimid.code 的外键显示到 AnotherAimAdmin 的一个表中?
这是一个经典的管理“视图”,在后端由两个不同的表格分隔:
class AimAdmin(admin.ModelAdmin):
list_display = ('code')
# AnotherAim and AIM are connected via a foreight key
class AnotherAimAdmin(admin.ModelAdmin):
list_display = ('name','sur_name', 'email')
search_fields = ['name','sur_name']
admin.site.register(Aim,AimAdmin)
admin.site.register(AnotherAim, AnotherAimAdmin)
我的模型如下所示:
class AnotherAim(models.Model):
email=models.EmailField(null=True)
name= models.CharField(max_length=100)
sur_name= models.CharField(max_length=100)
code = models.OneToOneField(Aim,null=True)
class Aim(models.Model):
code = models.CharField(max_length=5, null=False)
....
....