#12238: ModelAdmin ignores dynamic fields of ModelForm
-------------------------------------------+--------------------------------
          Reporter:  anonymous             |         Owner:  nobody             
               
            Status:  new                   |     Milestone:                     
               
         Component:  django.contrib.admin  |       Version:  1.1                
               
        Resolution:                        |      Keywords:  modelform 
modeladmin dynamic field
             Stage:  Unreviewed            |     Has_patch:  1                  
               
        Needs_docs:  0                     |   Needs_tests:  0                  
               
Needs_better_patch:  0                     |  
-------------------------------------------+--------------------------------
Changes (by batiste):

  * has_patch:  0 => 1

Comment:

 The patch I sent seems to work quite oki, but if I add a field dynamicaly,
 even if it's in the form object, the new value is not saved:

 {{{
     def dynamic_fieldsets(self, request, obj=None, **kwargs):

         general_fields = list(self.general_fields)
         perms = PagePermission(request.user)

         if perms.check('freeze'):
             general_fields.append('freeze_date')

         return [
             [_('General'), {
                 'fields': general_fields,
                 'classes': ('module-general',),
             }],
             (_('Options'), {
                 'fields': self.normal_fields,
                 'classes': ('module-options',),
             }),
         ]
 }}}


 My freeze field is added properly in the admin interface, but the value is
 not saved. But in the other hand if I do things like that:

 {{{
     def get_fieldsets(self, request, obj=None):
         """
         Add fieldsets of placeholders to the list of already
         existing fieldsets.
         """
         general_fields = list(self.general_fields)
         perms = PagePermission(request.user)

         # some ugly business to remove freeze_date
         # from the field list
         general_module = {
             'fields': list(self.general_fields),
             'classes': ('module-general',),
         }

         default_fieldsets = list(self.fieldsets)
         if not perms.check('freeze'):
             general_module['fields'].remove('freeze_date')

         default_fieldsets[0][1] = general_module
 }}}

 The latest version works, but it feels like a very hackish way to do
 things.

 Can somebody explain me what's wrong here? Does Django have a more elegant
 way to do this?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12238#comment:5>
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