| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- class constants:
- """
- That class stores constant values, which is used in a lot of places
- in the app code. Storing constants in one place makes it easier to
- change in the future.
- Methods
- -------
- @staticmethid empty_text : str
- Return simple empty string (""), but it is more descriptive than
- str().
- @staticmethod app_name : dtr
- Return name of the app, which is required for example in
- relationship builder
- @classmethod get_model_name : str
- Return name of the model for given class, or name in string..
-
- @staticmethod get_related_name : str
- It create name of the reverse relation field for other models.
- """
- @staticmethod
- def empty_text() -> str:
- """
- That return simple empty text, to make app more readable.
- Returns
- -------
- str
- Empty string.
- """
- return str()
- @staticmethod
- def app_name() -> str:
- """
- That retutn name of the app, useable for example when building
- relations in database.
- Returns
- -------
- str
- Name of the app.
- """
- return str("app")
- @classmethod
- def get_model_name(cls, target: str | type) -> str:
- """
- That generate model name from given model class, or model name in
- string. It does not return constant, but generate name from given
- parameters constant data in class.
- Parameters
- ----------
- target : str | type
- Target class or class name.
- Returns
- -------
- str
- Model name of given model class or given model class name.
- """
- if type(target) is not str:
- target = target.__name__
- return str(cls.app_name() + "." + target)
- @staticmethod
- def get_related_name(
- target: str | type,
- field: str | None = None
- ) -> str:
- """
- It return name of the field, which is related to other object by
- reverse relation. Target is name of model which own relation with,
- in other words, model which has foreign key. Field is neccssary only
- when object who has relation uses same model in more than one
- foreign key. Then field must be name of the foreign key field.
- For example, when item A has field to_b, which is foreign key of
- model B, when call to that would be "get_related_name(A)", or if
- b is used in other fields, then it would looks like
- "get_related_name(A, "to_b")".
- Parameters
- ----------
- target : str | type
- Name or class of the model, which use relation.
- field : str | None (Default: None)
- Name of the field, which use relation.
- """
- if type(target) is not str:
- target = target.__name__
- if field is not None:
- return str("related_" + target + "_to_field_" + field)
-
- return str("related_" + target)
|