我有一个名为的基本模型Restaurant
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True)
serves_pizza = models.BooleanField()
serves_hotdog = models.BooleanField()
def __unicode__(self):
return u'%s the restaurant' % self.place.name
查询Restaurant.objects.all()
并Restaurant.objects.get()
产生两个不同的结果,其中只有前者是正确的。
# this is correct
>>> r=Restaurant.objects.all()
>>> r
[<Restaurant: Hogwarts the restaurant>, <Restaurant: Domino the restaurant>]
>>> r[0].serves_hotdog
True
# this is not correct
>>> r0=Restaurant.objects.get(pk=4556376185503744)
>>> r0.serves_hotdog
False
# although they have the same pk
>>> r0.pk == r[0].pk
True
# their property values are different
>>> r[0].serves_hotdog == r0.serves_hotdog
False
>>> r[0].serves_pizza == r0.serves_pizza
False
有没有人见过类似的东西?