I have the following tastypie resources:
class ArtistResource(SearchableResource):
audio_tracks = fields.ToManyField('music.api.AudioTrackResource', 'audio_tracks', related_name='artists', null=True, blank=True)
class Meta:
filtering = {
"title": ('startswith',),
"id": ALL_WITH_RELATIONS,
}
queryset = Artist.objects.all()
resource_name = 'artist'
allowed_methods = ['get']
class AudioTrackResource(SearchableResource):
artists = fields.ToManyField('music.api.ArtistResource', 'artists', null=True, blank=True)
class Meta:
filtering = {
"artists": ALL_WITH_RELATIONS,
}
queryset = AudioTrack.objects.all()
resource_name = 'audio_track'
allowed_methods = ['get']
And the following backbone models:
class Track extends Backbone.RelationalModel
urlRoot: TRACK_API
relations: [
{
type: Backbone.HasMany
key: 'artists'
relatedModel: Artist
collectionType: ArtistCollection
reverseRelation:
key: 'track'
includeInJSON: 'title'
}
]
Track.setup()
Track
class Artist extends Backbone.RelationalModel
urlRoot: ARTIST_API
relations: [
{
type: Backbone.HasMany
key: 'audio_tracks'
relatedModel: Track
collectionType: TrackCollection
reverseRelation:
key: 'artist'
includeInJSON: 'title'
}
]
Artist.setup()
Artist
And i can't set full=True in my Tastypie resources because it creates recursion... I don't want to set full=True at all. But i have no idea when and where to fetchRelated(). And it does not fetch anything because array of objects URIs is already there.. Is there any alternative way to populate many to many relationship to JSON on both sides?
P.S. i created this question after 3 days googling this problem, and i didn't find working solution.