I am trying to use limit_choices_to on a foreignkey and it just doesnt
seem to do anything.
I have a class which like so:
class UserDefinedCode(models.Model):
type: model.CharField(maxlength=3)
.........
class OTher(models.Model):
department = model.ForeignKey(UserDefinedCode,
limit_choices_to={'type__exact': 'LOC'})
.....
In admin this still shows all records on UserDefinedCode instead of
just the entries of type='LOC'.
I read the MR branch Qiki, but unless I am blind, I cant see any
changes to this.
Anyone got any ideas ?
Thanks,
C
Within the admin interface I'd like to limit the choices for a persons
'personalAssistant' to come from a group called 'Administration'. At
the moment, it doesn't work, all 'Persons' are shown in the
'personalAssistant' popup, and I know I have some that have the
WorkGroup 'Administration'. Here's my model:
class WorkGroup(models.Model):
groupName = models.CharField(maxlength=50)
def __repr__(self):
return "%s" % self.groupName
class Person(models.Model):
firstName = models.CharField(maxlength=50)
lastName = models.CharField(maxlength=50)
title = models.CharField(maxlength=20, blank=True)
null=True)
groups = models.ManyToManyField(WorkGroup, related_name = 'groups',
blank=True)
coordinator = models.ManyToManyField(WorkGroup, related_name =
'coordinator', blank=True)
personalAssistant = models.ForeignKey("self", blank=True,
null=True, limit_choices_to = {'groups_groupName' : 'Administration'})
# PA for this person
But the limit_to_choices isn't limiting choices at all.
Does anyone have any pointers?
Cheers,
Tone
I still can't get this to work though,
pa = models.ForeignKey("self", blank=True, null=True,
limit_choices_to = {'groups__exact' : 'Administration'}) # PA for
this person
I'm now getting mesages about an m2m table not existing.
What I'd like to do is something like
limit_choices_to = {'WorkGroups.groupName__exact' : 'Administrator'}
but that returns "Cannot resolve keyword 'WorkGroup.groupName' into
field".
thanks for any help,
Cheers,
Tone
pa = models.ForeignKey("self", blank=True, null=True,
limit_choices_to = {'groups__groupName__exact' : 'Administration'})
# PA for this person
Now the only people who are in the popup are those who are in the group
'Administration'. Very neat ;)
Cheers,
Tone