Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding field from foreign key in django-tasypie ToOneField
    primarykey
    data
    text
    <p>When using django-tasypie is there a way one can add an extra field form the related object apart from the resource url?</p> <p>I have an Album model and a Photo model.</p> <pre><code>class Album(models.Model): title = models.CharField(_('Album Name'), max_length=250, default=_('Untitled Album')) class Photo(models.Model): album = models.ForeignKey(Album) </code></pre> <p>I have these as ModelResources in the api:</p> <pre><code>class PhotoResource(ModelResource): album = fields.ToOneField('ampwefly.apps.photos.api.AlbumResource', 'album') class AlbumResource(ModelResource): photo = fields.ToManyField(PhotoResource, 'photo_set', related_name='photo', full=True) </code></pre> <p>As it stands I am able to return the following when I access the url of a single photo:</p> <pre><code>{ album: "/api/v1/album/2/", description: "", id: "1", image: "/uploads/uploads/users/images/e-jey.jpg", resource_uri: "/api/v1/photo/1/", uploaded: "2012-11-22T22:42:26.051779" } </code></pre> <p>If I use:</p> <pre><code>album = fields.ToOneField('ampwefly.apps.photos.api.AlbumResource', 'album', full=True) </code></pre> <p>This will return all the fields of the album but what I would like to try to do is return on the title in addition to the the Resource url such as:</p> <pre><code>{ album: { id: "2", resource_uri: "/api/v1/album/2/", title: "Untitled Album" }, description: "", id: "1", image: "/uploads/uploads/users/images/e-jey.jpg", resource_uri: "/api/v1/photo/1/", uploaded: "2012-11-22T22:42:26.051779" } </code></pre> <p>What would be a suggested solution to get the result above?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload