django-preserialize icon indicating copy to clipboard operation
django-preserialize copied to clipboard

Exclude doesn't work recursively

Open bee-keeper opened this issue 9 years ago • 5 comments
trafficstars

Hello,

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

bee-keeper avatar Dec 22 '15 21:12 bee-keeper

Can you provide an example?

bruth avatar Dec 23 '15 02:12 bruth

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 avatar Dec 23 '15 10:12 bee-keeper

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

bruth avatar Feb 23 '16 15:02 bruth

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.

bee-keeper avatar Feb 24 '16 11:02 bee-keeper

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.

bruth avatar Feb 24 '16 12:02 bruth