Hi guys,

I used model inheritance quite a while and came across a problem which
I can resolve and actually think is might be a bug in django itself.
Because of the size of the project I'm working on it would be a waste
of space using the original models here ... so I simplified the
classes to reproduce the problem.

--- models.py code --- snip ---
from django.db import models

class Base(models.Model):
    name = models.CharField(max_length=20)

    def __unicode__(self):
        return self.name

class Seller(Base):
    childa = models.CharField(max_length=20)

    def __unicode__(self):
        return u'%s: %s' %(self.name, self.childa)

class Buyer(Base):
    childb = models.CharField(max_length=20)
    partner = models.ForeignKey(Base, related_name = 'buyer_partner',
blank = True, null = True)

    def __unicode__(self):
        return u'%s: %s, %s' %(self.name, self.childb, self.partner)

class Item(models.Model):
    name = models.CharField(max_length=20)
    owner = models.ForeignKey(Base, related_name='item_owner',
blank=True, null=True)

    def __unicode__(self):
        return u'%s: %s' %(self.name, self.owner)
--- snap ---

I'm using postgresql in the real application and the sqlite3 backend
on this example here, both behave the same.
To add some data I do the following on the python shell (python manage
shell):
--- snip ---
>>> from multi.models import Seller, Buyer, Item, Base
>>> seller = Seller(name='Seller1', childa='ChildA')
>>> seller.save()
>>> buyer = Buyer(name='Buyer1', childb='ChildB', partner=seller)
>>> buyer.save()
>>> item = Item(name='Nice Thing', owner = buyer)
>>> item.save()
--- snap ---

After this I do some query to verify that everything is in the
database (also on the shell):
--- snip ---
>>> from multi.models import Seller, Buyer, Item, Base
>>> Buyer.objects.all()
[<Buyer: Buyer1: ChildB, Seller1>]
>>> Seller.objects.all()
[<Seller: Seller1: ChildA>]
>>> Item.objects.all()
[<Item: Nice Thing: Buyer1>]
--- snap ---

So all necessary data is in the database ... now a few queries to get
data back out and assigned to some vars ... and finally to filter
queries ... the first one is working, the second one seems to bee
'broken' (gives no result = []) and I don't know why ...
--- snip ---
>>> from multi.models import Seller, Buyer, Item, Base
>>> s = Seller.objects.get(name='Seller1')
>>> b = Buyer.objects.get(name='Buyer1')
>>> s
<Seller: Seller1: ChildA>
>>> b
<Buyer: Buyer1: ChildB, Seller1>
>>> Item.objects.filter(owner=b)
[<Item: Nice Thing: Buyer1>]
>>> Item.objects.filter(owner__buyer_partner = s)
[]
--- snap ---

Could anyone point me to the right direction or give me an example how
it is supposed to work?

Regards

     Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to