Search code examples
djangotastypie

How to get back an attribute of Resource in tastypie


Details :

@localhost:8000/api/v1/user/1/

Gives :

{
    "date_joined": "2013-08-28T04:20:36.704342",
    "email": "[email protected]",
    "first_name": "",
    "id": 1,
    "is_active": true,
    "is_staff": true,
    "is_superuser": true,
    "last_login": "2013-08-29T01:18:07.163345",
    "last_name": "",
    "password": "pbkdf2_sha256$10000$EVKt9xEHWSaD$S/ipn3mqoSMBjo98D9wconcloape1eFvsu9mVoIm+KA=",
    "resource_uri": "/api/v1/user/1/",
    "username": "admin"
}

Now if i wanna get only firstname How can i do that in tasty pie??


Solution

  • class MyResource(ModelResource):
        class Meta:
           queryset = User.objects.all()
           excludes = ['email', 'password', 'is_staff', 'is_superuser']
    

    Use 'excludes' attribute.