bruth / django-preserialize

Convert your model instances and querysets into dicts and list with style.

Home Page:http://bruth.github.io/django-preserialize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclude doesn't work recursively

bee-keeper opened this issue · comments

Hello,

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

Can you provide an example?

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'])

@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.

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.

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.