django readonly form/modelform

Overview

A Form and ModelForm which provides the ability to specify certain fields as readonly, meaning that they will display their value as text wrapped with a tag. The user is unable to edit them, and they are protected from POST data insertion attacks.

The recommended usage is to place a NewMeta inner class on the form, with a readonly attribute which is a list or tuple of fields, similar to the fields and exclude attributes on the Meta inner class.

class MyForm(ReadonlyForm):
    foo = forms.TextField()
    bar = forms.TextField()
    class NewMeta:
        readonly = ('foo',)

Use these forms as you would a standard form in your templates.

Reference Links

overview of readonly on django-crispy-forms Show archive.org snapshot

Cuauhtemoc Almost 6 years ago