On Thu, 2008-12-11 at 20:55 -0800, maeck wrote: [...] > Now I can pass the fieldnames as values('parent') for now, It would be > easier if initial did not care if the _id is provided or not. > Or am I missing something else?
What you're missing, or rather, assuming, is that querysets are ideal or intended to be used directly as initial data, and that isn't the case. Forms are separate pieces of code from models and shouldn't have to understand all the foibles of models (i.e. enforce loose coupling). If you want to pass in the results of a queryset directly, it's easy, but you do have to take care and pass in the right values by specifying the names of the fields. You know the models you are using, so writing down their field names isn't particularly onerous. It happens that values(), by default, returns "parent_id" for historical reasons. However, we set things up so that you an also ask it to return "parent" by specifying that in the fields list. So use that functionality. If you still think that's all just nit-picking and we should compromise to avoid the inconvenience, realise how bad it is: first you have to teach Form's initial data that when they expect "foo", it might really be spelt "foo_id". The form doesn't know this is a foreign key, it just knows it's a choice field. But since "_id" isn't the only possible suffix, now the form has to be able to handle any possible suffix -- "foo_blah", for example -- since the database column name can be specified in the model. So we're looking at all sorts of possible alternate names for the key. Thus, the form really needs to have reference to the full model to inspect all that. Now we're passing in models and tying the form to the model and it's starting to look like you really should be using ModelFormSet. Short version: it's just not worth all the complexity. We have ModelFormSets for standard model-> form conversions and an easy way to produce sequences of dictionaries if you have other situations where a FormSet is more useful. These things have a way of being much more complicated than they look on the surface. :-) Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---