I have this model:
# models.py from django.contrib.auth.models import User class Test(models.Model): author = models.ForeignKey(User, related_name="tests") title = models.CharField(_("title"), max_length=100)
Then in the api folder for the django piston web service:
class TestHandler(BaseHandler): allowed_methods = ("GET") model = Test fields = ("title", ("author", ("username",))) def read(self, request, id): base = self.model.objects try: r = base.get(pk=id) return r except: return rc.NOT_FOUND
If I call this web service, I get:
{ "title": "A test" "author": { "username": "menda", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2011-02-09 10:39:02", "password": "sha1$83f15$feb85449bdae1a55f3ad5b41a601dbdb35c844b7", "email": " b@a.as ", "date_joined": "2011-02-02 10:49:48" }, }
I also tried using exclude , but it doesn't work either.
How can I get only the username for author ? Thanks!
Menda source share