On Fri, Nov 04, 2011 at 11:03:35AM -0700, guardbadger wrote:
> Hi all,
> 
> Appreciate some help trying to build a queryset. Im hoping I can make
> this in django, without having to crack open raw sql... Here is my
> setup:
> 
> class Container(models.Model):
>   permissions = generic.GenericRelation(Permission)
> 
> class Item(models.Model):
>   container = models.ForeignKey(Container)
>   extraSetting = models.ForeignKey(ExtraSetting)
> 
> class Permission(models.Model):
>   content_type = models.ForeignKey(ContentType)
>   content_object = generic.GenericForeignKey()
>   extraSetting =   models.ForeignKey(ExtraSetting)
> 
> class ExtraSetting(models.Model):
>   ....
> 
> Convoluted made up example, but hopefully you can see what the data
> might be.
> 
> So the problem im trying to solve. I need to get a list of items and
> their permissions, but restrict the permission set so that I only get
> permissions where extraSetting is the same on the Item and on the
> permission.
> 
> So I want to run something like
> 
> Item.objects.filter(container__permissions__extraSetting=Item.extraSetting)

What I think you want to use is this: http://django.me/f
In your case something like

Item.objects.filter(container__permissions__extraSetting=F('extraSetting'))

Michal

Attachment: signature.asc
Description: Digital signature

Reply via email to