Document usage of arbitrary resource (such as non-view function).

Issue #116 new
created an issue

Let's say a user wants to create a normal Python class with no affiliate with Django (The class in question acts as a facade into a lot of different models, other arbitrary classes that call 3rd party APIs, etc - to make one easy interface for my web-facing API. It doesn't offer read, update, etc methods like a normal Django model might implement.), and make it's methods available through Django Piston.

The documentation doesn't make mention of how to do this. I'm going to give it a try, but it might be good to have a quick snippet of code documenting this process in the section that talks about arbitrary resources. The following code is taken from the Wiki's home page:



class ArbitraryDataHandler(BaseHandler): methods_allowed = ('GET',)

def read(self, request, username, data):
    user = User.objects.get(username=username)

    return { 'user': user, 'data_length': len(data) }


On the Resource section of the docs it makes mention of each method being called with a model instance. If it is any arbitrary resource, then it won't have a model instance (at least I don't want it to have a model instance). My understanding of the above code snippet is that you're creating the instance of whatever you want in the read method and the other custom methods you create will be using what the read() method returns. If this is correct, does it mean that you cannot have arbitrary resources and you can only have model based resources? If it is already possible to do what I mentioned above, and I'm just an idiot for not seeing how, then I apologize for the waste of a ticket.

Comments (2)

  1. Log in to comment