[英]django model - queryset issue
I am trying to search for an item in db. 我正在尝试在db中搜索项目。 there are two items in db, but i cannot get the second one somehow.
在数据库中有两个项目,但我无法以某种方式获得第二个项目。 with my code below the result is only the first row of
Bewertung
but not the second one. 我的代码在下面,结果仅是
Bewertung
的第一行,而不是第二行。
my code is simple: 我的代码很简单:
locations = Location.objects.all()[:5]
bewertungs = Bewertung.objects.filter(von_location__in=locations)
what can be the reason of why i cannot find the second entry in db? 为什么我无法在db中找到第二个条目是什么原因? i am getting the first record where
bewertung
is 4, but the second isnot coming up in the result. 我得到的第一个记录是
bewertung
是4,但是第二个记录bewertung
出现在结果中。
EDIT : 编辑 :
this is the Bewertung Model. 这就是Bewertung模型。
class Bewertung(models.Model):
von_location= models.ForeignKey(Location,related_name="locations_bewertung",default="")
von_user = models.ForeignKey(User,related_name="users_bewertung",default="")
price_leistung = models.IntegerField(max_length=5,default=00)
romantic = models.IntegerField(max_length=3,default=00)
bewertung = models.IntegerField(max_length=3,default=00)
def __unicode__(self):
return self.bewertung
these are the records: 这些是记录:
class Bewertung(models.Model):
//you don't have to put default="" because this is already required
von_location= models.ForeignKey(Location,related_name="locations_bewertung")
von_user = models.ForeignKey(User,related_name="users_bewertung")
//use DecimalField instead of IntergerField
//use max_digits not max_length because it is for string
price_leistung = models.DecimalField(max_digits=3, decimal_place=2, default=0)
romantic = models.DecimalField(max_digits=3, decimal_place=2, default=0)
bewertung = models.DecimalField(max_digits=3, decimal_place=2, default=0)
//you return your unicode with an int field which result to error
//so you must do it this way
def __unicode__(self):
return "{0}".format(self.bewertung)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.