我建立在Django專輯的應用程序,我有兩個的Django模型Django tastypie和骨幹相冊應用程序?
class Album(models.Model):
name = models.CharField(max_length=100)
family = models.ForeignKey(FamilyProfile)
created_by = models.ForeignKey(User)
created_date = models.DateField(default=datetime.datetime.now())
class Image(models.Model):
album = models.ForeignKey(Album)
name = models.CharField(max_length=100,null=True,blank=True)
src = models.ImageField(upload_to=MEDIA_ROOT)
upload_by = models.ForeignKey(User)
upload_time = models.DateTimeField(default=datetime.datetime.now())
,並使用tastypir爲RESFull API,骨幹
我有兩個集合
album.albumCollection = Backbone.Tastypie.Collection.extend({
url:'/album/v1/album/',
model:album.albumModel,
})
image.imageCollection = Backbone.Tastypie.Collection.extend({
url:'/album/v1/image/',
model:image.imageModel,
})
和骨幹路由器
album.router = Backbone.Router.extend({
routes:{
'':'album',
'test/:id':'openAlbum',
},
album:function(){
this.albums = new album.albumCollection()
this.albumsView = new album.albumCollectionView({model:this.albums})
this.albums.fetch({reset: true})
},
openAlbum:function(id){
this.images = new image.imageCollection()
this.imagesView = new image.imageCollectionView({model:this.albums})
this.images.fetch({reset: true})
}
})
new album.router();
Backbone.history.start();
我可以得到專輯呈現,但是當我嘗試打開相冊時,您可以看到我需要按照相冊的ID獲取圖像集,但imageCollection.url是靜態的。
我怎樣才能獲得與骨幹和tastypie專輯內的圖像?
Tastypie可以響應與數據庫甚至關係,你可以發送JSON魔神這個{album_id任何數據: {image:[{url:'',title:'',etc},...]}} – Denis
當然,但如何獲取相冊的圖像[id] – paynestrike
我的意思是如何編寫imageCollection url來獲取所有相冊中的圖像[id] – paynestrike