X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/758943d9c9bc7aafb8262ee265018502f2db469d..8f031335a8a0dabceec381b89eb0cbbcb2f4b637:/src/catalogue/api/views.py?ds=sidebyside diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index 5512501c6..0f95f0ace 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -320,7 +320,7 @@ class TagView(RetrieveAPIView): slug=self.kwargs['slug'] ) except Http404: - if self.request.method == 'PUT': + if self.request.method == 'POST': return Tag( category=self.kwargs['category'], slug=self.kwargs['slug'] @@ -330,10 +330,21 @@ class TagView(RetrieveAPIView): def post(self, request, **kwargs): data = json.loads(request.POST.get('data')) - desc = data['description_pl'] + fields = { + "description_pl": "description_pl", + "plural": "plural", + "is_epoch_specific": "genre_epoch_specific", + "collective_noun": "collective_noun", + "adjective_feminine_singular": "adjective_feminine_singular", + "adjective_nonmasculine_plural": "adjective_nonmasculine_plural", + } obj = self.get_object() - obj.description_pl = desc - obj.save(update_fields=['description_pl'], quick=True) + for data_field, model_field in fields.items(): + setattr(obj, model_field, data.get(data_field, getattr(obj, model_field))) + if obj.pk: + obj.save(update_fields=fields.values(), quick=True) + else: + obj.save() return Response({})