22
votes

I have a Django model class with a non-model-field property, ex:

def _get(self):
    return "something"
description = property(_get)

I'm using the model class with in a ModelForm / ModelFormset. Is there any way to access the property from the form / formset? If not, what's best practice for including extra "display" data in a django formset?

1

1 Answers

31
votes

If your ModelForm was initialized with an instance of a Model, then you can access it through the instance attribute. From the ModelForm docs:

Also, a model form instance bound to a model object will contain a self.instance attribute that gives model form methods access to that specific model instance.