Hi, I'm currently experiencing some behaviour to which I'm sure is the intended way (as far as I can make out from the DRF source), but I'm wondering if anyone has a decent approach to make it work.
A small outline of the code can be seen in https://gist.github.com/HenrikOssipoff/3d2ff6ec554fcc8b637f38827fc810a6 (obviously, a lot of the fields and all the business logic have been stripped away) The basic idea, si that we have a validator (AttributesValidator) that validates the "attributes" field on ProductSerializer. However, in order to do this, it needs to know which category the product has. In order to do this, we go through the parent's initial data, to find the category that was supplied. Not the cleanest approach, but it works when using ViewSets, since the data parameter is being passed to the serializer automatically, creating the initial_data attribute on the serializer. However, when we attempt to nest this in VariantSerializer (a serializer which essentially just takes a list of products), the data parameter is NOT passed to each ProductSerializer, meaning no initial data exists, and the validator then errors. What seems to happen instead, is that the validation in VariantSerializer simply loops over each field, and runs its validation, only supplying the needed data to the validation method - which obviously makes sense. Is there anyone who has a way of approaching this problem, that could lead to a solution? Thanks in advance. // Ossipoff -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
