ducin
ducin

Reputation: 26437

django tastypie alter model fetching

I'm trying to find a way to make tastypie return results that are a little bit different than the default ones. For example, by default the api returns the following:

{
created_at: "2011-10-18T14:22:27",
email_address: "[email protected]",
first_name: "Paul",
id: 1,
is_active: true,
is_super_admin: true,
last_login: "2011-10-18T14:22:27",
last_name: "McCartney",
resource_uri: "/api/v1/user/1/",
updated_at: "2011-10-18T14:22:27",
username: "pmc"
}

And I would like to replace first_name and last_name with full_name being Paul McCartney. Is that possible to override model fields? If so - how to do that?

Upvotes: 0

Views: 83

Answers (1)

Paulo Bu
Paulo Bu

Reputation: 29794

It seems you have to use the dehydrate cicle. From the docs:

Tastypie uses a “dehydrate” cycle to prepare data for serialization, which is to say that it takes the raw, potentially complicated data model & turns it into a (generally simpler) processed data structure for client consumption. This usually means taking a complex data object & turning it into a dictionary of simple data types.

I hope this helps!

Upvotes: 2

Related Questions