How do I handle creating resources while also referencing foreign resources?

29 views
Skip to first unread message

Dona

unread,
Nov 11, 2020, 8:47:29 AM11/11/20
to Django REST framework
Hi Django REST Community,

I want to build a frontend and a backend. Within my frontend I would like to be able to create a new resource but with referencing already existing Movies or create new Movie instances. For instance via this post request:
{
     "name": "Resource1",
     "movie": [
          { "id": 0 },
          { "id": 1 },
          { "id": 2 },
          { "name": "New Movie 1", "description": "Simple description..." },
          { "name": "New Movie 2", "description": "Another description" },
     ]
}

Does this design makes sense or is there a better approach?
If so, do I then need to create 2 serializers one for post (create) and one for everything else? I could then use 
get_serializer_class to distinguish between the 2 serializers.

I would be happy to receive an opinion.

Kind regards,
Dona
Reply all
Reply to author
Forward
0 new messages