hello,
consider the code below. it has two print statements at the end. their
output should be identical, but it is not. i think there is a bug.
thanks
konstantin
class X(models.Model) :
name = models.SlugField()
def __str__(self) : return
self.name
class Y(models.Model) :
name = models.SlugField()
xs = models.ManyToManyField(X, through = 'Pair')
def __str__(self) : return
self.name
class Pair(models.Model) :
name = models.SlugField()
x = models.ForeignKey(X)
y = models.ForeignKey(Y)
def __str__(self) : return "(%s,'%s',%s)" % (self.x,
self.name,
self.y)
...
x0, _ = X.objects.get_or_create(name = 'x0')
x1, _ = X.objects.get_or_create(name = 'x1')
y0, _ = Y.objects.get_or_create(name = 'y0')
y1, _ = Y.objects.get_or_create(name = 'y1')
p0, _ = Pair.objects.get_or_create(name = 'a', y = y0, defaults =
{ 'x' : x0 })
p1, _ = Pair.objects.get_or_create(name = 'b', y = y0, defaults =
{ 'x' : x1 })
p2, _ = Pair.objects.get_or_create(name = 'c', y = y1, defaults =
{ 'x' : x0 })
p3, _ = Pair.objects.get_or_create(name = 'd', y = y1, defaults =
{ 'x' : x1 })
print [p.x for p in Pair.objects.filter(y = y0, name = 'd')]
print y0.xs.filter(pair__name = 'd')
...
output:
[]
[<X: x1>]