SQL Debugging and limit_choices_to in MR Branch

7 views
Skip to first unread message

ChaosKCW

unread,
Mar 21, 2006, 10:48:08 AM3/21/06
to Django users
How can I see SQLs generated from an application. I have read the
previosu topics on this, but they no longer seem to apply to MR branch.
Well I cant find the table with all the queries anyways.

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

tonemcd

unread,
Mar 21, 2006, 11:01:36 AM3/21/06
to Django users
I have a similar problem with limit_choices_to and MR.

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

ChaosKCW

unread,
Mar 22, 2006, 4:33:07 AM3/22/06
to Django users

tonemcd

unread,
Mar 23, 2006, 1:01:38 PM3/23/06
to Django users
Thanks for the patch ChaosKCW,

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

tonemcd

unread,
Mar 23, 2006, 1:33:40 PM3/23/06
to Django users
Way-Hay!, this works

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

ChaosKCW

unread,
Mar 24, 2006, 6:39:50 AM3/24/06
to Django users
Glad you solved it, PS the patch wasnt done by me BTW. Kudos to Luke.

Reply all
Reply to author
Forward
0 new messages