I am running Django 1.1 and cannot get the "limit_choices_to" option for my ManytoManyField to work.
I have two models:
class MemberPhoto(ImageModel):
title = models.CharField(_('title'), max_length=255, blank=True, null=True)
caption = models.CharField(_('caption'), max_length=255, blank=True, null=True)
date_added = models.DateTimeField(_('date added'), default=datetime.now, editable=False)
member = models.ForeignKey(User)
def __unicode__(self):
return u'%s (%s)' % (self.member.username, self.id)
and
class lock(models.Model):
user = models.ForeignKey(User, related_name="owner")
to_user = models.ForeignKey(User, related_name="to_user")
unlocked_photos = models.ManyToManyField(MemberPhoto, blank=True, null=True, limit_choices_to = {'member':'user'})
objects = locking_manager()
in the second model, i want to make sure in Django's admin that the only "unlocked_photos" ("MemberPhoto" objects) presented in the multiple select field are those who have a "member" value (a User object) the same as the "lock" object's "user" (also a User object).
I thought I had followed the Django docs on this, but it doesn't work. I get the following error:
TemplateSyntaxError
Caught an exception while rendering: invalid input syntax for integer: "user"
I've tried changing the "limit_choices_to" to things like:
limit_choices_to = {'member': user} --- Doesnt work
limit_choices_to = {'member__username':'kyle'} --- this DOES work but it's useless, i'm just manually specifying a username
How can I instead get the user from the current "lock" object and filter the MemberPhoto "member" property by that?
Thanks to anybody who can help.
Kyle