Django admin can't create records for model with self-referential foreign key

This is my model:

class Customer(models.Model):
    name = models.CharField(max_length=100, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    referee = models.ForeignKey('self', on_delete=models.RESTRICT, blank=True, null=True)

    def __str__(self):
        return self.name

When I try to create a customer via admin site I got this error:

TypeError at /admin/customer/customer/add/
Field 'id' expected a number but got <Customer: my_customer_name>.

How can I fix this? Thank you.

I found the cause of this error. This is not caused by the model or the admin but by a custom model method I made. Sorry for wasting your time

Back to Top