Администратор Django: Как показать модель как встроенную внутри другой модели, которая связана косвенноPython

Программы на Python
Гость
Администратор Django: Как показать модель как встроенную внутри другой модели, которая связана косвенно

Сообщение Гость »


У меня есть модели с именами 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)
I need to show the userdevice inside the user detail page in admin panel as inline.

Django Error admin.E202 'userdevice' has no ForeignKey to
'accounts.user'

Getting this error. Any help will be much appreciated.


Источник: https://stackoverflow.com/questions/781 ... ch-is-indi

Вернуться в «Python»