hi i'm trying to make a new foreignkey from different fields using to_field
but it return product
values instead no_invoice
class Model1(models.Model):
admin = models.ForeignKey(User,on_delete=models.CASCADE)
product = models.ForeignKey(Products,on_delete=models.CASCADE)
no_invoice = models.IntegerField(unique=True)
def __str__(self):
return self.product.name
class Model2(models.Model):
admin = models.ForeignKey(User,on_delete=models.CASCADE)
invoice = models.ForeignKey(Model1,to_field='no_invoice',on_delete=models.CASCADE)
is there something else i have to add ? thanks