clean method on ModelChoiceField

9 views
Skip to first unread message

james_027

unread,
Aug 17, 2007, 5:32:57 AM8/17/07
to Django developers
hi,

while doing some experiment with ModelChoiceField, and having success
with this settings ModelChoiceField(Item.objects.all(),
widget=TextInput). There's one thing that didn't work right for me ...
If I have Item.objects.filter(name__icontains=='sony') instead of
Item.objects.all() and the inputed value doesn't found in the
queryset, django still allow this, I think its because of this code on
the clean method of ModelChoiceField...

value = self.queryset.model._default_manager.get(pk=value)

I think this should reflect the queryset set on the argument of the
ModelChoiceField. Hope I know what I am saying here and right in what
I understand.

Thanks
james

Malcolm Tredinnick

unread,
Aug 17, 2007, 6:11:48 AM8/17/07
to django-d...@googlegroups.com

Whilst we encourage people to ask questions, plesae spend a few minutes
searching the archives to see if the exact topic has come up before. In
this case, searching for ModelChoiceField will show a thread that is not
two weeks old discussing the same issue. I even pointed out the
existence of this thread when responding to your django-users post 90
minutes ago where I pointed to the above line as the answer to your
question there.

The issue is not clear cut at all; there are definitely two sides to the
argument and it's not yet clear which way we should go.

The good news is that you can easily override the clean() method in a
sub-class if you want the behaviour you are after, so it's not really a
problem in either case.

Regards,
Malcolm

--
Two wrongs are only the beginning.
http://www.pointy-stick.com/blog/

Reply all
Reply to author
Forward
0 new messages