Django管理员GenericForeignKey内联

时间:2013-05-21 18:42:08

标签: django django-models django-admin

class MyUser(AbstractBaseUser):
    ...
    content_type = models.ForeignKey(ContentType, limit_choices_to={"model__in": ("agentprofile", "clientprofile"))
    object_id = models.PositiveIntegerField()
    profile = generic.GenericForeignKey('content_type', 'object_id')

class AgentProfile(models.Model):
    license_number = models.CharField(max_length=50, blank=True)

class ClientProfile(models.Model):
    address = models.CHarField(max_length=250)

我有3个模型:MyUser(自定义用户模型),ClientProfile,AgentProfile。如何在MyUser管理页面上编辑ClientProfile / AgentProfile(如内联)?

1 个答案:

答案 0 :(得分:17)

您需要使用GenericTabularInline。请参阅Django docs