I'm trying to create a order
model that is referencing the non primary-key field rfid
of my user model. In order to do that I'm using a foreign-key relationship using the attribute to_field
.
My user model is inheriting from AbstractUser
and I added the rfid
field with unique=True
that is necessary for the to_field
attribute:
class CustomUser(AbstractUser):
rfid = models.IntegerField(unique=True, null=True, blank=True)
Following the order model:
class Order(models.Model):
rfid = models.ForeignKey('CustomUser', on_delete=models.CASCADE, to_field="rfid")
coffee = models.ForeignKey('Coffee', on_delete=models.DO_NOTHING)
amount = models.IntegerField(null=True, blank=True)
datetime = models.DateTimeField()
Having a look in the django-admin there still are the usernames listed for the rfid
reference instead of the actual rfid
entries that are made in the database. I attatched a picture on Imgur as I haven't got he reputation yet to post images on here.
Why is that? I studied other posts but couldn't figure it out.