bruth / django-preserialize

Convert your model instances and querysets into dicts and list with style.
http://bruth.github.io/django-preserialize
BSD 2-Clause "Simplified" License
41 stars 6 forks source link

Exclude doesn't work recursively #12

Open bee-keeper opened 8 years ago

bee-keeper commented 8 years ago

Hello,

It seems that exclude has no effect on nested serialised objects. Is this intentional?

bruth commented 8 years ago

Can you provide an example?

bee-keeper commented 8 years ago

I have a Django model with a fk and m2m. Serialise works perfectly but when I run the following, the field is only excluded in the outer level and appears in all subsequent nestings. I haven't had too much time to look into this, perhaps using templates is the solution?

serialize(my_obj, exclude=['my_field'])

bruth commented 8 years ago

@bee-keeper Sorry for the late response. For recursive objects or models that appear more than one in a graph, templates are very good for. Here is an example of how I define and reference them.

bee-keeper commented 8 years ago

Ok i had assumed that templates would be a solution, I suppose it was more a comment on the default behaviour without using a template. Please feel free to close in that case.

bruth commented 8 years ago

I suppose it was more a comment on the default behaviour without using a template.

Yes. That being said, #5 describes an approach to define defaults per model. Also I have #14 in the works that defines a Serializer class that would encapsulate options like these.