1

Possible Duplicate:
How to access the request.user in a Piston classmethod

How to access the request.user in a Django Piston @classmethod?

In the documentation about the classmethod it's reported:

...In addition to these, you may define any other methods you want. You can use these by including their names in the fields directive, and by doing so, the function will be called with a single argument: The instance of the model.

Community
  • 1
  • 1
user760065
  • 11
  • 1

1 Answers1

1

The request object in piston is passed to the corresponding resource methods

read is called on GET requests, and should never modify data (idempotent.)

create is called on POST, and creates new objects, and should return them (or rc.CREATED.)

update is called on PUT, and should update an existing product and return them (or rc.ALL_OK.)

delete is called on DELETE, and should delete an existing object. Should not return anything, just rc.DELETED.

Just create a instance variable and set it to the request.user object or pass the django user object to your classmethod.

Henrik P. Hessel
  • 36,243
  • 17
  • 80
  • 100
  • Thanks for your answer, but the instance variable neither the classmethod worked for me. But I found a solution on this post:http://stackoverflow.com/questions/3580653/how-to-access-the-request-user-in-a-piston-classmethod – user760065 Jun 09 '11 at 23:19