How to encapsulate Resource

72 views
Skip to first unread message

pawel

unread,
May 24, 2012, 7:11:14 AM5/24/12
to django-res...@googlegroups.com
Hi all!

For example, I have a view that returns DjangoUser class instances. I have defined a UserResource with model=DjangoUser, specified relevant fields, etc....

So I have a working UserView and Resource. It returns data in JSON. That is correct. Like: [......]

Now I would like to return the same data with additional info. Like: {'users':[......],'status':'My additional info'}

How to achieve that without too much hassle ?

Adam Ness

unread,
Jun 2, 2012, 9:16:32 PM6/2/12
to django-res...@googlegroups.com
You can have nested resources, like so:

class UserResource(ModelResource): 
    model=User

class ResponseResource(Resource):
    fields = (
        'status,
        ('users': UserResource'), 
    )

class UserView(View):
    resource = ResponseResource
    def post(request):
        users = User.objects.filter(....)
        return { 'status': 'done', 'users': users }
Reply all
Reply to author
Forward
0 new messages