Moves from_json to utils and splits the models to files in a module
This commit is contained in:
2024-02-06 15:31:05 +01:00
parent e7ee92868f
commit aad9343569
10 changed files with 132 additions and 111 deletions
+1
View File
@@ -0,0 +1 @@
from .json import from_json
+8
View File
@@ -0,0 +1,8 @@
def from_json(cls, json):
try:
return cls.objects.get(pk=json["id"])
except cls.DoesNotExist:
keys = [f.name for f in cls._meta.get_fields()]
subset = {key:json[key] for key in set(keys) & set(json.keys())}
return cls.objects.create(**subset)