[Solved]-How can i access the model instance used by a form from a template?

35👍

I don’t think that’s what you want to do. A model is a class: it won’t have a status, as that’s a field which only gets a value for a particular instance.

I suspect what you mean to do is access the model instance associated with the form, which is just form.instance.

2👍

If you create a property on the form that reads the value then you can access it very easily in the template.

class SomeForm(...):
  @property
  def status(self):
    return self._meta.model.status

...

       {{ form.status }}

Leave a comment