aad9343569
Moves from_json to utils and splits the models to files in a module
9 lines
284 B
Python
9 lines
284 B
Python
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)
|
|
|