Hi all,
I'm new to tastypie, I'm facing issue with the ApiKeyAuthentication with GET method.
I created an Account model that have foreign-key of User.
class Account(models.Model):
user = models.ForeignKey(User)
uuid = models.CharField(max_length = 36)
score = models.CharField(max_length = 36)
class Practice(models.Model):
account = models.ForeignKey(Account)
practice_type=models.CharField(max_length = 36)
app_id=models.CharField(max_length = 36)
I want to update the Account's score when user passing "app_id" and "practice_type" , Below is PracticeResource.
I'm using prepend_url method to pass the "app_id" and "practice_type".
class PracticeResource(ModelResource):
class Meta:
queryset = Practice.objects.all()
resource_name = 'practice'
authorization = Authorization()
authentication = MultiAuthentication(ApiKeyAuthentication(), SessionAuthentication())
always_return_data=True
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/levels%s$"%(self._meta.resource_name,trailing_slash()),self.wrap_view('get_practice_levels'), name="api_get_levels"),
]
def get_practice_levels(self,request,**kwargs):
# some rules goes here, if practice_type= 1 then score 100, if 2 then 200 .....etc
account = Account.objects.get(user=request.user)
account.score="100"
account.save()
I'm passing Authorization information in header,
Tastypie throws an error at
500 : Internal Server Error
>>> account = Account.objects.get(user=request.user)
TypeError: "int() argument must be a string or a number, not 'SimpleLazyObject'
Thanks.