Django Rest Framework - How to use update_or_create
<p>I am using Django Rest Framework. I want to create a record if it doesn't exist, or update it if it does exist.</p>
<p>What I did:</p>
<pre><code>class MyModelList(generics.ListCreateAPIView):
    queryset = MyModel.objects.all()
    serializer_class = MyModeSerializer
    permission_classes = (permissions.IsAuthenticated,)

    def perform_create(self, serializer):
        my_model, created = MyModel.objects.update_or_create(user_id=self.request.data['user_id'],
            defaults={
                'reg_id': self.request.data['reg_id']
            })
</code></pre>
<p>The record is created or updated, but I am getting an error <code>'OrderedDict' object has no attribute 'pk'</code>. How do you use <code>update_or_create</code>?</p>