On Mon, Feb 9, 2009 at 5:18 PM, Serge S. Koval <serge.ko...@gmail.com>wrote:
> > Hello, > > I'm fairly new Django user, but have some background experience with > other frameworks. Sorry if this topic was discussed before, but I was > not able to find any mention of it. > > My question is related to architectural decisions of the forms, > fields and widgets. > > At the moment in Django, all "incoming" data is processed by the > widget and clean by the field. Data flow: raw data -> widget -> field -> > form. > However, reverse process is different: data -> form -> widget > data. As you can see, field does not play and role in reverse data > conversion. > > Let's examine simple task. ModelForm calls model_to_dict() to > initialize form fields with initial data. In case of models data is > their id's. > But what if one will want to develop widget that requires more > than just a model id? For example: str(model) and model.id at the same > time? There are not so many options how it can be done right now: or > derive from ModelForm and override it's data gathering behavior > (rewrite model_to_dict()) or run extra query in the widget itself (which > is not optimal). > > Possible naive solution: if it would be possible to make field work in > _both_ directions, it would be awesome. > If field will know that it works with models (like ModelForm related > fields), it will be responsible for cleaning data to the > widget-appropriate format. > > It is my two cents. I don't know if somebody already tried to make it > work this way of there were some reasons not to do this way... I don't > know. > > Thanks, > Serge. > > -- > Best regards, > Serge mailto:serge.ko...@gmail.com > > > > > I would recommend searching the dev list for a thread titled: "Controlling form/widgets output". Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---