def post(request): user=request.user if user.is_authenticated(): data=json.loads(request.body) affiliate=Affiliate(user=user, name=data['name'], note=data['note']) affiliateId=data['id'] if affiliateId > 0: affiliate.id=affiliateId affiliate.save() AffiliateTag.objects.filter(affiliate=affiliate).delete() for postedTag in data['tags']: tag=Tag(name=postedTag) tag.save() affiliateTag=AffiliateTag(affiliate=affiliate, tag=tag) affiliateTag.save() return HttpResponse(affiliate.id, content_type='application/json') else: return HttpResponse(status=401)
def post(request): user = request.user if user.is_authenticated(): data = json.loads(request.body) item = Item( user=user, affiliate_id=data["affiliateId"], name=data["name"], cost=data["cost"], note=data["note"] ) itemId = data["id"] if itemId > 0: item.id = itemId item.save() ItemTag.objects.filter(item=item).delete() for postedTag in data["tags"]: tag = Tag(name=postedTag) tag.save() itemTag = ItemTag(item=item, tag=tag) itemTag.save() return HttpResponse(item.id, content_type="application/json") else: return HttpResponse(status=401)