On Nov 21, 9:09 am, Donn <[EMAIL PROTECTED]> wrote:
> On Friday, 21 November 2008 08:06:32 urukay wrote:
>
> > easy way how to solve it is to put definition of your choices out of model
> > definition:
>
> Yeah, that's what I call a 'global', but is there no way to get the choices
> from the field in the model class?
>
> \d

No, there isn't - this is one of the frustrating parts of customising
a ModelForm. You can't get the default widget attributes either.

There is an alternative, though: instead of overriding the fields
declaratively, you can define a formfield_callback function. This gets
passed each model field and must return a form field, but you can do
anything you want to it in the meantime. So, for example:

def customise_formfields(field):
    field_obj = field.formfield()
    if field.name == 'disk_type':
        existing_choices = field_obj.choices
        field_obj.widget = choicewidget(choices=existing_choices)
    return field_obj

class CustomModelForm(forms.ModelForm):
    formfield_callback = customise_formfields

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