我有一个名为“网络”的应用程序。在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),但是我想看工资!
答案 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`