#30373: "Save as new" with read-only fields
-----------------------------------------+------------------------
               Reporter:  Nicola Zilio   |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  contrib.admin  |        Version:  1.11
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 I want to implement the "Save as new" feature in Django's admin for a
 model such as this one:


 {{{
 class Plasmid (models.Model):
     name = models.CharField("Name", max_length = 255, blank=False)
     other_name = models.CharField("Other Name", max_length = 255,
 blank=True)
     selection = models.CharField("Selection", max_length = 50,
 blank=False)
     created_by = models.ForeignKey(User)
 }}}


 In the admin, if the user who requests a Plasmid object is NOT the same as
 the one who created it, some of the above-shown fields are set as read-
 only. If the user is the same, they are all editable. For example:

 {{{
 class PlasmidPage(admin.ModelAdmin):

     def get_readonly_fields(self, request, obj=None):

         if obj:
             if not request.user == obj.created_by:
                 return ['name', 'created_by',]
             else:
                 return ['created_by',]
         else:
             return []

     def change_view(self,request,object_id,extra_context=None):

         self.fields = ('name', 'other_name', 'selection', 'created_by',)
         return super(PlasmidPage,self).change_view(request,object_id)
 }}}

 The issue I have is that when a field is read-only and a user hits the
 "Save as new" button, the value of that field is not 'transferred' to the
 new object. On the other hand, the values of fields that are editable (not
 read-only) are transferred.

 I don't understand if this is a bug or a (security?) feature. In either
 case does anybody why, or how I could solve this problem? I want to
 transfer the values of both read-only and non-read-only fields to the new
 object.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30373>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.34f99c194eb62f2a8ada9139c467a8cb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to