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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---