Encouraging to hear all the feedback here, this was really just a
thought provoker (with perhaps a dash of vented frustration).

Newforms is great, and it's *nearly* there. Just needs a few key
enhancements before it's ready for prime time. No doubt the newforms-
admin guys have been noticing this (the work they've done on formsets
looks like a welcome addition!).

The form_for_ concept is great but needs streamlining; it's missing a
few really killer features. A bit of a cop out to say we should only
be using it for CRUD - I see it as a vital link in achieving DRY
(along with model inheritance, better newforms form_for_ inheritance/
mix-in, schema migration).

I'll see if I can put together some more specific suggestions with
example code and use cases over the next week or so.


On Aug 15, 8:45 am, Pigletto <[EMAIL PROTECTED]> wrote:
> > If you wanted to use the standard form_for_* functions, that sounds
> > like something you could solve by creating a BaseForm which overrides
> > __init__ (taking any extra arguments you require,.e.g. querysets which
> > specify data to be used to populate a field's choices), and modifies
> > the form's fields after the call to super(...).__init__, passing this
> > BaseForm into form_for_* functions using their "form" argument.
>
> This will work but you'll hit database twice.
> This is because when ForeignKey is converted to ModelChoiceField
> it prepopulates widget choices list. AFAIR this causes query to be
> executed
> during field creation.
>
> > class JobBaseForm(forms.BaseForm):
> >     def __init__(self, *args, **kwargs):
> >         super(JobBaseForm, self).__init__(*args, **kwargs)
> >         self.fields['number'].required = False
>
> Yes, it is good way I think.
>
> My callback (that in fact uses modified version of ModelChoiceField
> and
>  modified QuerySetIteratof look this way:
>
> # this callback is called for every field
> def pre_customer_callback(field, defaults, extra):
>     """ defaults - dictionary passed to newforms' field constructor
>          extra - additional parameters
>     """
>     # get default queryset for field
>     queryset = defaults.get('queryset', None)
>
>     # we want to show only subcompanies that belong to this company
>     company = extra['company']
>
>     # mark all not null fields as required
>     defaults['required']=not field.null
>
>     # additionally mark other fields as required
>     if field.name in ['phone', 'fax']:
>         defaults['required']=True
>
>     if field.name=='subcompany':
>         defaults['queryset'] =
> queryset.filter(company__exact=company)
>         # in the <select> combo box we want user to see something
> like: 'RedCompany (Paris)'
>         defaults['queryset_label']=lambda obj: obj.name
> +' ('+obj.city.name+')'


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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