Wednesday, July 4, 2012

Re: Forms for updating a compound model

I'm sorry to tell you that ModelForms don't seem to have this functionality, but I'm happy to tell you that ModelAdmins do.

What it does, basically, is to return this:

{
     'label': label_for_field(field, self.opts.model, self.opts),
     'widget': {
       'is_hidden': False
     },
     'required': False
}

when there's a field marked as readonly, so it can transparently be used from the templates.

I recommend you go look at the code in django.contrib.admin.helpers.InlineAdminFormSet to get a feel of what you can do.

Annd... looking around, I found a ReadonlyWidget, look at the first answer here: http://stackoverflow.com/questions/2931884/odd-behavior-in-django-form-readonly-field-widget

--
"The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment