hi,

while learning and experimenting with forms ... one should use
ModelChoiceField in order to let newforms bind the value on a
foreignkey field of a model. My concern is that in the real world, you
usually don't use <select></select>  to let the user chose the value
to be filled especially if the list of choices is very very large.
While I have success with ModelChoiceField(Item.object.all(),
widget=TextInput), providing a <input type="text"></input> for
entering a value which could come from a selected record thru
searching, my concerned/question is ...

1. Does the Item.objects.all() get executed while rendering the <input
type="text">? (I hope not since the widget is not the <select>)
2. Does the Item.objects.all() get executed when in the process of
assignment. example
   class InvoiceItem(models.Model):
      qty = models.PositiveInteger()
      item = models.ForeignKey(Item)

   class InvoiceItemForm(forms.Form):
      qty = forms.IntegerField()
      item = models.ModelChoiceField(Item.objects.all(),
widget=TextInput)

   f = InvoiceItemForm(requst.POST)
   if f.is_valid():
      ii = InvoiceItem(**f.cleaned_data)
      ii.save()

(I hope during the assignment ii.item = f.item, the Item.objects.all()
is not executed but instead it will do something like
item.objects.all().filter(id="value from the text input"). If this is
the case then I have no problem with this approach but if not could
some share their solution?)

Thanks
james


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to