mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-03 07:24:00 +00:00
Added event create view
This commit is contained in:
17
core/serialisers/json.py
Normal file
17
core/serialisers/json.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.core.serializers import serialize
|
||||
from django.utils.simplejson import dumps, loads, JSONEncoder
|
||||
from django.db.models.query import QuerySet
|
||||
from django.utils.functional import curry
|
||||
|
||||
class DjangoJSONEncoder(JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, QuerySet):
|
||||
# `default` must return a python serializable
|
||||
# structure, the easiest way is to load the JSON
|
||||
# string produced by `serialize` and return it
|
||||
return loads(serialize('json', obj, fields=('id', 'name')))
|
||||
return JSONEncoder.default(self,obj)
|
||||
|
||||
# partial function, we can now use dumps(my_dict) instead
|
||||
# of dumps(my_dict, cls=DjangoJSONEncoder)
|
||||
dumps = curry(dumps, cls=DjangoJSONEncoder)
|
||||
Reference in New Issue
Block a user