Django:如何在模型中使用 get() 方法
模型.py
class WorkDailyRecord(models.Model):
user = models.ForeignKey(User)
date = models.DateTimeField(auto_now_add=True)
contents = models.TextField()
check_user = models.ManyToManyField(
User,
related_name='checked_user_record_set',
)
target_user = models.ManyToManyField(
User,
related_name='target_user_record_set',
)
ONGOING_OR_END =(
('ing', 'ing'),
('end', 'end'),
)
ongoing_or_end = models.CharField(
max_length=3,
choices=ONGOING_OR_END,
default='ing',
)
>>>WorkDailyRecord.objects.get(ongoing_or_end='ing') 回溯(最近一次通话最后): 文件“”,第 1 行,在 文件“/usr/lib/python2.7/site-packages/django/db/models/manager.py”,第 131 行,在 get 返回 self.get_query_set().get(*args, **kwargs) 文件“/usr/lib/python2.7/site-packages/django/db/models/query.py”,第 368 行,在 get % (self.model._meta.object_name, num, kwargs)) MultipleObjectsReturned:get() 返回了多个 WorkDailyRecord —— 它返回了 12 个!查找参数为 {'ongoing_or_end': 'ing'}
我只想得到'ing'数据......
我该怎么办?