#14802: feature request: ability to override default hidden_widget used to 
render a
custom model field when marked as readonly in the admin
----------------------------------+-----------------------------------------
 Reporter:  nickname123           |       Owner:  nobody    
   Status:  new                   |   Milestone:  1.3       
Component:  django.contrib.admin  |     Version:  1.2       
 Keywords:  hidden_widget         |       Stage:  Unreviewed
Has_patch:  0                     |  
----------------------------------+-----------------------------------------
 It is possible to override the default widget that is used to render a
 custom model field... however the hidden_widget is more difficult.  The
 only way appears to be on a per model basis by changing the widget in the
 model admin.  This can be very difficult/impractical when inheriting
 models that make use of the custom field with the field set to readonly in
 the model admin.

 For example, a simple field that uses a custom widget:

 {{{

 class CustomFileWidget(forms.FileInput):
         return mark_safe(u"CustomFileWidget was used: %s" %
 super(CustomFileWidget, self).render(name, value, attrs))

 class CustomFileFormField(forms.FileField):
     def __init__(self, *args, **kwargs):
         kwargs['widget'] = CustomFileWidget
         super(CustomFileFormField, self).__init__(*args, **kwargs)

 class CustomFileField(models.FileField):
     def formfield(self, **kwargs):
         return super(CustomFileField,
 self).formfield(form_class=CustomFileFormField,**kwargs)
 }}}



 However, there does not appear to be a kwarg for hidden_widget and using
 something like the following will not work:

 {{{

 class CustomFileFormField(forms.FileField):
     hidden_widget = CustomFileWidget
     widget = CustomFileWidget
 class CustomFileField(models.FileField):
     def formfield(self, **kwargs):
         return super(CustomFileField,
 self).formfield(form_class=CustomFileFormField,**kwargs)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14802>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en.

Reply via email to