Return existing from generics.CreateAPIView

20 views
Skip to first unread message

Stats Student

unread,
Sep 4, 2020, 5:48:19 PM9/4/20
to Django REST framework
Hi, I have a view for creating new objects which inherits from generics.CreateAPIView.

Inside I override perform_create() like so:

u1 = get_object_or_404 (Usr.objects, login = self.request.user)
serialize.save(usr = u1)

I'd like to add logic to check whether the object to be created is already in the database and if so, just return the existing object. How can I accomplish this? And one more thing - can I only return some of the fields, but not others?

Thanks!
Reply all
Reply to author
Forward
0 new messages