On 12 Sty, 20:52, a b <dolittle...@gmail.com> wrote:
> Hi,
>
> I have three models:
> Product
> SimpleProduct that extends Product
> GroupProduct that extends Product and have ManyToMany relation with
> SimpleProduct
>
> The reason to use the base Product model is so I can use paging.
> Is it possible to make a query that gives a list of GroupProducts and
> SimpleProducts that are not included in a GroupProduct.
> I don't want to show the same product twice, once standalone and once as
> part of a GroupProduct.
>
> I can add a field to SimpleProduct that indicates weather it's standalone or
> not and maybe update it using signals
> but it doesn't feel like the right way.
>

Quick, untried, ideas:

1. You could try using aggregation:

from django.db.models import Count
SimpleProduct.objects.annotate(belongs_to_groupproducts=Count
('groupproduct')).filter(belongs_to_groupproducts=0)

2. If this is "normal" inheritance (i.e. not an abstract one), then
SimpleProduct and GroupProduct have
implicit OneToOneField connecting them to Product. It means that you
probably could just filter Product-s and then downcast it.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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