Django admin inline model for User

前端 未结 1 549
野趣味
野趣味 2021-02-06 02:05

I have model as

class Employer(models.Model):
    create_user = models.ForeignKey(User,unique=False,null=True, related_name=\'%(class)s_user_create\')
    updat         


        
相关标签:
1条回答
  • 2021-02-06 03:03

    The particular error you mention doesn't seem to have anything to do with what's going on in your code, so I'm not sure about that particularly. However, you have other errors here, so potentially fixing those will resolve that error as well.

    First, you need to specify fk_name on your EmployerInline. Django resolves the foreign key automatically in most circumstances, but since you have two foreign keys to the same model, you have to give Django some help.

    class EmployerInline(admin.TabularInline):
        model = Employer
        fk_name = 'create_user'
    

    Second, you may have just omitted it, but you must unregister User before registering it. You also need to specify the model when registering:

    admin.site.unregister(User)
    admin.site.register(User, UserAdmin)
    
    0 讨论(0)
提交回复
热议问题