我在django管理站点中看不到对象的标题。只需看一下即可:modelName对象(2)

时间:2019-03-06 09:22:16

标签: python django django-models django-admin

我有一个名为“网络”的应用程序。在models.py中,我写了收入模型:

models.py

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Income(models.Model):
    text = models.CharField(max_length=255)
    date = models.DateTimeField()
    amount = models.BigIntegerField()
    user = models.ForeignKey(User, on_delete=models.CASCADE)

但是我看到了:收入对象(1),但是我想看工资!

image of problem

1 个答案:

答案 0 :(得分:0)

__str__函数添加到模型中

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Income(models.Model):
    text = models.CharField(max_length=255)
    date = models.DateTimeField()
    amount = models.BigIntegerField()
    user = models.ForeignKey(User, on_delete=models.CASCADE)    

    def __str__(self):
        self.amount`