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 base_on_stock : int Init count on stock. """ @staticmethod def base_on_stock() -> int: """ Return base count of items on stock. Returns ------- int Init count on stock. """ return 1 @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)