class UserModel(AbstractUser):
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email', 'password']
email = models.EmailField(unique=True)
profile_image = models.ImageField(upload_to='user/profile_image', null=True, blank=True)
phone = models.CharField(max_length=12, unique=True, blank=True, null=True)
gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
emp_id = models.CharField(max_length=20, unique=True, blank=True, null=True)
class IndividualWorkAnalysis(models.Model):
user_id = models.ForeignKey(UserModel, to_field="emp_id", on_delete=models.CASCADE, null=True,
related_name="user_id")
Here above I need to access 'emp_id' from 'UserModel'.
All my migrations went correct, but not able to fetch the 'emp_id' on the admin panel of Django.
There it just lists the usernames.
question from:
https://stackoverflow.com/questions/65838763/foreign-key-of-models-should-refer-to-a-particular-filed-in-db-django 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…