I\'m wrestling with how to best create HTML pages in Django that can either be used for displaying or editing data. That is, I\'d like the field\'s values to appear as text in d
Answering my own question, apparently. I ended up with a three-part solution:
Step one:
form.model = Model(...)
Step two:
{{form.field1.label}} {% render form.field1 user action %} {{form.field2.label}} {% render form.field2 user action %}
Step three:
Something like:
def render(formfield, user, action, default_text="Private"): if not user.is_authenticated(): action = "view" if action == "view": if user.is_authenticated(): fieldname = formfield.name retval = str(getattr(formfield.form.model, fieldname)) else: retval = default_text else: retval = formfield.as_widget() return retval