Jorge, I can't thank you enough for explaining this, but I'm still a little stuck.
On Jul 3, 2006, at 6:46 PM, Jorge Gajon wrote: > # No post, fill up default values > new_data['some_field'] = 'default value' > > form = form.FormWrapper(manipulator, new_data, errors) > return render_to_response('some_template.html', {'form': form}) > This works great. In the shell, I try str(form['some_field']) and the value is pre-populated as expected. > and for a ForeignKey: > related_object = OtherObject.objects.get(pk=23) > new_data['related_object'] = str(related_object.id) This, not so much. The related object entry is in the data field of the FormWrapper when I look at it, but if I render the SelectField it corresponds to, the empty entry is pre-selected, not the entry that corresponds to the related_object. Is it not possible to pre-select something in a SelectField, or do you have to do it some other way? Also, since I don't really want the user to be able to change this, it would be just as nice for me to replace the SelectField that the AddManipulator creates with a HiddenField of my own, but I can't see how to do that except manually in the template. > If you want to use an automatic manipulator but want to only restrict > the selections in a select list you could subclass the manipulator > like this: > > class MyCustomManipulator(MyModel.AddManipulator): > def __init__(self): > MyModel.AddManipulator.__init__(self) > > for field in self.fields: > if field.field_name == 'related_object': > choices = [(obj.id, obj) for obj in > RelatedObject.objects.filter(somecriteria)] > field.choices = choices I'm reminded of the scene in Amadeus when Salieri was reading Mozart's music and just let it fall to the ground. That's very elegant. Thanks, Todd --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---