I'm writing an API to which client may send JSON containing list of ids as 
{'posts': [1, 2, 3]} with serializer that does following things:

- validates that request.data is structured correctly
- ids key is indeed list of integers
- ids list is no longer than 20 items (this is important as the models and 
operation I'm planning to execute are quite heavy)
- translates those ids to object instances
- runs some validation logic on those instances (eg. they are associated 
with same user)
- on .update() run custom logic on those instances (I'm basically merging 
objects #2 and #3 contents in #1, then deleting them)

I've got some success with custom related field inheriting from 
PrimaryKeyRelatedField, but I've couldn't implement the limit validation 
BEFORE hitting queryset instead of after. Eventually I've came to the 
conclusion that its best to go with ListField containing IntegerField and 
set "self.posts" attribute near the end of my validate_posts() that I'm 
accessing in update() next, but this feels very hacky to me.

Are there any better ways to go about what I'm after?

Thanks!

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

Reply via email to