Re: Restrict choices in ModelForm for ForeginKey field

2010-03-02 Thread Bill Freeman
Good stuff. I take it that not specifying queryset on the ModelChoiceField constructor doesn't work? If you really need an empty one by default, then the none() method seems ideal. The documentation says that this provides an EmptyQuerySet, so you don't have to worry about it changing. There's

Re: Restrict choices in ModelForm for ForeginKey field

2010-03-02 Thread AlienBaby
Hi, thanks for the pointers, I followed through Bill's suggestion, and while I could understand the approach I did indeed have problems with ''access to data from the request'' as this was all happening in the models.py in a class definition. But, reading around it and a little more google I ended

Re: Restrict choices in ModelForm for ForeginKey field

2010-03-02 Thread Alex Robbins
If you set limit_choices_to on the underlying foreign key, I think that shows up in any modelform derived from it too. http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to Hope that helps, Alex On Mar 1, 8:24 am, AlienBaby wrote: > Hi. > > I have

Re: Restrict choices in ModelForm for ForeginKey field

2010-03-01 Thread Bill Freeman
When I've needed something like this I've used a model field subclass to customize the formfield() method. I've subclassed models.ManyToManyField, but I would expect the approach to work on models.ForeignKey as well. formfield is called to instantiate a forms field when you instantiate the model