简体   繁体   中英

django model - queryset issue

I am trying to search for an item in 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.

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? i am getting the first record where bewertung is 4, but the second isnot coming up in the result.

EDIT :

this is the Bewertung Model.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM