On Thu, Feb 5, 2009 at 5:21 PM, Stephen Sundell
<[email protected]>wrote:

>
> Say I have a model like this:
>
> class Photo(models.Model):
>    name = models.CharField(max_length=25)
>    user = models.ForeignKey(User,related_name='photos')
>    image = models.ImageField()
>    site = models.ForeignKey(Site,related_name='site_photos')
>    objects = CurrentSiteManager()
>
> I've noticed that if I try to filter users on whether or not they have
> a photo with a certain name it doesn't restrict photos to those on the
> current site.  The query 'User.objects.filter
> (photos__name="photo_name")' looks like this:
>
> ('SELECT "auth_user"."id", "auth_user"."username",
> "auth_user"."first_name", "auth_user"."last_name",
> "auth_user"."email", "auth_user"."password",
>        "auth_user"."is_staff", "auth_user"."is_active",
> "auth_user"."is_superuser", "auth_user"."last_login",
> "auth_user"."date_joined"
> FROM "auth_user"
>        INNER JOIN "photos_photo" ON ("auth_user"."id" =
> "photos_photo"."user_id")
> WHERE "photos_photo"."name" = %s ', ('photo_name',))
>
> I think it should look like this:
>
> 'SELECT "auth_user"."id", "auth_user"."username",
> "auth_user"."first_name", "auth_user"."last_name",
> "auth_user"."email", "auth_user"."password",
>        "auth_user"."is_staff", "auth_user"."is_active",
> "auth_user"."is_superuser", "auth_user"."last_login",
> "auth_user"."date_joined"
> FROM "auth_user"
>        INNER JOIN "photos_photo" ON ("auth_user"."id" =
> "photos_photo"."user_id")
> WHERE ("photos_photo"."name" = %s
>        AND "photos_photo"."site_id" = %s )', ('photo_name',1))
>
> Is this done on purpose?  There may be a reason for it that I don't
> understand.  Is there a way that default managers can be taken into
> consideration when filtering through related fields?  I don't know
> exactly how this is supposed to work, is this the desired behavior?
>
> Thanks
> >
>
The manager on photos never gets invoked so it won't automatically get
injected into there, you'll to add (photos__site=1) to your query.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to