#22987: view only implementation (without using read only fields)
-------------------------------+------------------------------------
     Reporter:  liwee_ong@…    |      Owner:  nobody
         Type:  New feature    |     Status:  new
    Component:  contrib.admin  |    Version:  1.6
     Severity:  Normal         |   Keywords:  view, read_only, admin
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+------------------------------------
 Initially, I started using read only fields for my project but it didn't
 work well with reversion. So I thought of another way to implement view
 only.

 Required setup:
 1. Disable enter key (via JS hack in base.html)
 2. Hack change_form.html, add new variable
 {{{
         {% if enable_submit|default_if_none:True %}
             {% block submit_buttons_bottom %}{% submit_row %}{% endblock
 %}
         {% endif %}
 }}}


 Implementation: in admin.py, override add_view/change_view as needed, e.g.

 {{{
     def change_view(self, request, object_id, form_url='',
 extra_context=None):
         extra_context = extra_context or {}
         extra_context["enable_submit"] = True
         if YOUR_CONDITION_FOR_READ_ONLY: extra_context["enable_submit"] =
 False

         return super(YOUR_CLASS_NAME, self).change_view(request,
 object_id, form_url, extra_context=extra_context)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22987>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.0907332f0d2a888d43c58ec774342b00%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to