On Mar 26, 9:59 am, Adam Fraser <adam.n.fra...@gmail.com> wrote:
> hrm, I think I'm _finally_ starting to understand how django is meant
> to be used.
>
> Question: Why can't I just specify the widget used by a particular
> field from my model in the admin interface.
>
> stains = models.CommaSeparatedIntegerField(widget=SelectMultiple
> (choices=STAIN_CHOICES))
>
> ...or can I?  You suggested something like this earlier only referred
> to forms.CommaSeparatedIntegerField rather than
> models.CommaSeparatedIntegerField.
>
> hrm

Models are simply models. They don't really say much about forms. What
the admin application does is to make some default choices about how
to display your model in the admin interface. It automatically builds
the form to edit your model using some very reasonable defaults. If
you aren't happy with those choices, you can provide the form that the
admin should use instead of the default one. In your form, you are
free to use different widgets for your fields and/or provide custom
behavior.

The docs describe how to provide your own form to the admin here:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form

You simply provide an attribute on your ModelAdmin called 'form', set
equal to the form class you want the admin to use. This form class
should inherit from ModelForm. You can then customize the widgets and
behavior anyway you would like.

ModelForms are discussed here:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#topics-forms-modelforms

Overriding the default field type for a field on a ModelForm is a bit
further down:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types

But before you read all that, make sure you understand forms in
Django, in general:
http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index

Armed with that info, you should be able to make a custom form for the
admin to use. Good luck.

BN
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to