Exemplo n.º 1
0
    def post(self, request):
        tags = request.data['tags']

        response = super(ItemCreateView, self).post(request)
        id = response.data['id']
        item = Item.objects.get(id=id)

        for tag in tags:
            item_tag = ItemTag()
            item_tag.tag = tag
            item_tag.item = item
            item_tag.save()

        return response
Exemplo n.º 2
0
    def put(self, request, pk):
        tags = request.data['tags']

        response = super(ItemUpdateView, self).put(request)
        id = response.data['id']
        item = Item.objects.get(id=id)

        ItemTag.objects.filter(item=item).delete()

        for tag in tags:
            item_tag = ItemTag()
            item_tag.tag = tag
            item_tag.item = item
            item_tag.save()

        return response