No model, but having model fields in serializer, presented as ids

6 views
Skip to first unread message

Antony Chaporgin

unread,
Jul 2, 2015, 4:54:23 AM7/2/15
to django-res...@googlegroups.com
Hi. 
I got no real model behind my serializer (well, I do, but it's too complex and it's not a single model). I use serializer to validate incoming data and then I pass to to my logic layer.

So in my serializer I got user_ids field and robot_ids field and group_ids field etc. All of them are essentially list of ids, that the logic layer now gets from database. If it does not find entities of all the ids it raises validation error (yeah), if it does find all the entities, it returns them to my code not as original ids, but as the entities. What I would like to have is 
1) mention the corresponding models in corresponding serializer fields (probably with a notice of corresponding model field, with "PK")
2) having them taken from database after the serializer.is_valid() and put into serializer.data['user_ids']. 

I do think this may be a common usage of rest_framework.

I remember django forms having this functionality. Did not find this in rest_framework. Consider it being helpful, I would contribute the code to the project. Otherwise, if I am using rest_framework in a bad way, please show me how to do it right.
Reply all
Reply to author
Forward
0 new messages