0

I thought this question would have already existed on SO, but then I couldn't find any.

I am trying to find a reasonable place to define a constant associated with Item, a self-defined django model. This constant needs to be accessible to instances of Item, as well as beyond the model class. My basic idea is to defined it as a class attribute for Item, but I am not sure how to do that for django model class. My intuition tells me to define it in the model's metadata, if doable. Is that the right way to do it?

1 Answer 1

2

No.

class SomeModel(...):
  someconst = somevalue
Sign up to request clarification or add additional context in comments.

2 Comments

but wouldn't that be an instance attribute instead? I thought attributes defined in django model are automatically instance attributes.
No. Instance attributes are created via a reference to an instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.