In django admin module, foreignkey shows xxx_object(xx) instead the real name
I am new to Django. I had two model and want to manage them in admin module. The 1st module like this:
class Domain(models.Model): id = models.AutoField(primary_key=True) domain = models.CharField(max_length=250, blank=False) deptname = models.ForeignKey(to="Department", to_field="dwmc", on_delete=models.CASCADE, related_name='+',) class Meta: verbose_name = 'Domain' verbose_name_plural = 'Domains' pass
The second like this:
class Department(models.Model): dwdm = models.CharField(max_length=250, null=False, default='') dwmc = models.CharField(unique=True, max_length=200, blank=True) class Meta: verbose_name = 'Demartment' verbose_name_plural = 'Department' pass
While domain is all my domains, and department is all my departmenst. In department model, dwdm is the dapartment id(numbers, such as 001,002...), dwmc is the real department name(such as IT, HR). And in the database, the data is correct.
In admin module, I can add/edit the entries, but the deptname show not the real name, it shows like this: enter image description here
Well, which step I made the mistake?