我正在 django 中构建一个专辑应用程序,我有两个 django 模型
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())
并为 RESFull api 使用tastepir,
在主干我有两个系列
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 是静态的。
如何获取带有骨干和美味派的相册中的图像?