I have a subscription service online app. If the user has payed he may create as many resources as he want, if not he would be limited.
def obj_create(self, bundle, **kwargs):
current_user = auth.get_user(bundle.request)
if current_user.get_profile().has_payed:
return super(ClientResource, self).obj_create(bundle, user=current_user)
else:
if Client.objects.filter(user=current_user).count() < 2:
print "you may create"
return super(ClientResource, self).obj_create(bundle, user=current_user)
else:
return ???
Is this the correct way? And what do I need to return to tell the user the custom message of "Sorry you have reached the limit, please pay up"
I suggest you simply return a 401 (unauthorized) http response. Its the RESTFul thing to do