#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: reopened | Milestone: 1.3 Component: django.contrib.admin | Version: 1.2 Resolution: | Keywords: sprintdec2010 hidden_widget Stage: Design decision needed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | ---------------------------------------------+------------------------------ Changes (by nickname123):
* status: closed => reopened * resolution: wontfix => Comment: Replying to [comment:1 cogat]: > The admin app doesn't render hidden_widget at all, it just displays readonly fields (using `getattr(modelinstance, fieldname)`). AFAICS hidden_widget is only used by form previews and form wizards for holding on to copies of fields that were entered in an earlier view. > > If you are asking for a customised way to render a read-only field, then it might be helpful to know that you can pass a callable to readonly_fields that renders the result you want. > > {{{ > class Song(models.Model): > band = models.ForeignKey(Band) > title = CustomModelField(max_length=100) > > def rendertitle(self): > return "A custom rendering of %s" % self.title > > class SongAdmin(admin.ModelAdmin): > exclude = ('title',) > readonly_fields = ('rendertitle', ) > > }}} Wouldn't it be a better idea (in the future) to use a widget to render the readonly value so that the default appearance can be overridden? Using a field like that may be nice in some situations, but it doesn't work well for my use case. I don't think it would work well with any abstract model that is used repeatedly because you have to remember to add the callable to readonly_fields in every model's admin entry that inherits it. And also for admin inlines. -- Ticket URL: <http://code.djangoproject.com/ticket/14802#comment:2> 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 django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.