Files
muzak/playlist/models/utils/json.py
T
mark aad9343569 Refactor
Moves from_json to utils and splits the models to files in a module
2024-02-06 15:31:05 +01:00

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)