Class Level Property for Django Model in Python

I have a Django model that stores some rarely modified but frequently used data. I am looking for a template so that I can refer to them as variables of a static class, for example, like SomeModel.Baror SomeModel.Baz.

I am currently using staticmethod, for example:

class SomeModel(models.Model):
    name = models.CharField(max_length=100)

    @staticmethod
    def Baz():
        #retrieve from cache or lookup Baz item
        return baz

Meaning I treat elements like SomeModel.Baz (), but this is just not entirely correct. I just get the impression that I'm doing something wrong. I do not want this property, because I do not want the instance to refer to the element.

Can someone point me to a sample or example to show me if I can implement the class level property this way? Or tell me why should I do something completely different? Thank:).

+5
source share
1 answer

If you need some logic for a model that does not belong to a particular line, write a user model manager .

+2
source

All Articles