开发者

Equivalent to django Form to show object contents

Is there any Django class used to show the contents of an object model in a non-modifiable way? Something like this for forms to edit the objects from a model:

class TestForm(forms.ModelForm):
    class Meta:
        model = models.Test

using it as:

def generic_view(request):
    form = TestForm()
    return render_to_response('generic/generic_view.html', {
        'form': form,
    })

and then in the开发者_C百科 template:

{{ form.as_p }}

but showing just the contents of an object instead of a form?


Calling repr() against the model instance will get you a (admittedly ugly) representation of the instance fields.


I would take a look at the source of Databrowse to see how it does it. It introspects models and displays the data of objects with minimal configuration, so it probably has a component that does what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜