sebasuy
sebasuy

Reputation: 494

Django models: when should I use the @property decorator for attributes?

I would like to know what would be the best practice. I have been using the @property decorator a lot because it allows me to avoid creating custom context variables when I want to display something related to a model instance on a template.

I feel like my models are too big. Is this ok?

Upvotes: 6

Views: 1617

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798804

It's not a problem unless you find yourself writing exactly the same code on model after model. At that point you should consider writing a template tag that takes the model as a parameter instead.

Upvotes: 4

Related Questions