Russell, Michael, tonecmd,

  Thanks a lot for the replies.

  What I've ended up doing is adding a limit_choices_to like this:

candidate = meta.ForeignKey(Candidate, limit_choices_to = {'id__in': 
['1', '2']} )

  Then I intercept the admin url, get the current user, and in a method 
on the class that has the 'candidate' field, I get the list of ids of 
candidates he has access to, and then set:

self._meta.fields[1].rel.limit_choices_to = {'id__in': result}

  This dynamically updates the limit_choices_to depending on the current 
user.
  It isn't exactly pretty, and I'm not sure if it causes an issue with 
threading (I don't know how mod_python works well enough), but it works !

  I'm using the CVS trunk build.

  Thanks again,
  Graham.


Russell Cloran wrote:
> Hi,
> 
> On Mon, 2006-04-10 at 15:36 +0100, Graham King wrote:
>>   Is there a way to control the values that appear in a pulldown (a 
>> ForeignKey field) on the admin interface ?
>>
>>   I would like the ForeignKey to only be assignable to a subset of all 
>> values.
> 
> Is the limit_choices_to option suitable? It lets you limit your choices
> based on some query.
> 
> http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships
> 
> Russell
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to