Opened 10 years ago

Closed 10 years ago

#22987 closed New feature (duplicate)

view only implementation (without using read only fields)

Reported by: liwee_ong@… Owned by: nobody
Component: contrib.admin Version: 1.6
Severity: Normal Keywords: view, read_only, admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Change History (1)

comment:1 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #8936

Note: See TracTickets for help on using tickets.
Back to Top