我有名为 user、authtoken 和 userdevice 的模型。
class User(LifecycleModelMixin, AbstractUser): email = models.EmailField(unique=True) slug = models.SlugField(max_length=100, unique=True, blank=False, null=True) class AuthToken(models.Model): objects = AuthTokenManager() digest = models.CharField( max_length=CONSTANTS.DIGEST_LENGTH, primary_key=True) token_key = models.CharField( max_length=CONSTANTS.TOKEN_KEY_LENGTH, db_index=True) user = models.ForeignKey(User, null=False, blank=False, related_name='auth_token_set', on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True) expiry = models.DateTimeField(null=True, blank=True) class UserDevice(models.Model): token = models.OneToOneField(AuthToken, on_delete=models.CASCADE, related_name="auth_token") device_type = models.CharField(max_length=100, choices=DevicesChoices.choices) access_type = models.CharField(max_length=100, choices=AccessChoices.choices) device_brand = models.CharField(max_length=100, null=True, blank=True)
我需要将管理面板中的用户详细信息页面内的用户设备显示为内联。
Django 错误 admin.E202 'userdevice' 没有外键 '账户.用户'
出现此错误。任何帮助将不胜感激。
管理员.py
from django.contrib import admin
class UserDeviceInline(admin.TabularInline):
model = UserDevice
extra = 0
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = ['email', 'slug']
inlines = [UserDeviceInline]
现在在用户详细信息中您有设备信息