mirror of
https://github.com/jazzband/django-ddp.git
synced 2026-05-03 21:24:47 +00:00
changed decorator to custom ddp_property
This commit is contained in:
parent
54ec9b8cbc
commit
291b3b882f
1 changed files with 19 additions and 3 deletions
22
dddp/api.py
22
dddp/api.py
|
|
@ -94,6 +94,22 @@ class Array(aggregates.Aggregate):
|
|||
return value
|
||||
|
||||
|
||||
def ddp_property(method):
|
||||
"""
|
||||
Simple decorator that adds a "serialize_ddp" attribute to tell the
|
||||
serializer to include it in the payload returning to the client
|
||||
|
||||
Args:
|
||||
method: the decorated method
|
||||
|
||||
Returns:
|
||||
Callable: Decorated method with new attribute
|
||||
"""
|
||||
method.serialize_ddp = True
|
||||
|
||||
return method
|
||||
|
||||
|
||||
def api_endpoint(path_or_func=None, decorate=True):
|
||||
"""
|
||||
Decorator to mark a method as an API endpoint for later registration.
|
||||
|
|
@ -495,11 +511,11 @@ class Collection(APIMixin):
|
|||
field.rel.to, fields.pop(field.name),
|
||||
).values()
|
||||
|
||||
# run serialization for all properties
|
||||
# run serialization for all methods decoratored with ddp_property
|
||||
for o in obj.__class__.mro():
|
||||
for attr in o.__dict__:
|
||||
if isinstance(o.__dict__[attr], property):
|
||||
val = o.__dict__[attr].__get__(obj)
|
||||
if hasattr(o.__dict__[attr], 'serialize_ddp'):
|
||||
val = o.__dict__[attr].__call__(obj)
|
||||
fields[attr] = val
|
||||
return data
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue