On Jan 27, 9:23 am, "canen" <[EMAIL PROTECTED]> wrote:
> my_field = ChoiceField(choices=[(1, 1), (2, 2)], initial=1)
> doesn't work?

Yes, thank you.

For information, here is more details.

I have a view function called bill_clone to build a new bill form 
prepopulated with the values from a previous bill (apart from the bill 
number that has to be unique) .
It contained these lines :

billForm = forms.models.form_for_model(Bill)
bill = Bill.objects.get(number__iexact=bill_number)
data = bill.__dict__
del data['number']
form = billForm(initial=data)

Everything was fine except that foreignKey fields were not well 
selected.

Adding the lines :

form['currency'].field.initial = bill.currency_id
form['vendor'].field.initial = bill.vendor_id
form['customer'].field.initial = bill.customer_id

does the thing.

Thank you for your help.

Denis




--~--~---------~--~----~------------~-------~--~----~
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