Skip to content
Snippets Groups Projects
Verified Commit 24f3a90e authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Move get_db_field to FieldType base class

parent 10704346
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ class FieldType:
verbose_name: str = ""
models: Sequence = []
data_type: type = str
db_field: str = ""
converter: Optional[Union[str, Sequence[str]]] = None
alternative: Optional[str] = None
args: Optional[dict] = None
......@@ -69,6 +70,12 @@ class FieldType:
def get_column_name(cls) -> str:
return cls.name
@classmethod
def get_db_field(cls):
if cls.get_args().get("db_field"):
return cls.get_args()["db_field"]
return cls.db_field
@classmethod
def is_model_valid(cls, model: Model) -> bool:
if not cls.models:
......@@ -84,15 +91,8 @@ class FieldType:
class MatchFieldType(FieldType):
"""Field type for getting an instance."""
db_field: str = ""
priority: int = 1
@classmethod
def get_db_field(cls):
if cls.get_args().get("db_field"):
return cls.get_args()["db_field"]
return cls.db_field
@classmethod
def get_priority(cls):
return cls.get_args().get("priority", "") or cls.priority
......@@ -101,14 +101,6 @@ class MatchFieldType(FieldType):
class DirectMappingFieldType(FieldType):
"""Set value directly in DB."""
db_field: str = ""
@classmethod
def get_db_field(cls):
if cls.get_args().get("db_field"):
return cls.get_args()["db_field"]
return cls.db_field
@classmethod
def get_column_name(cls):
return cls.get_db_field()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment