I'm currently working on developing a new album application using django, with two essential django models:
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())
In addition, I am utilizing tastypie for the RESFull api. Moreover, in my Backbone.js setup, there are two collections defined:
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,
})
Furthermore, there is a backbone router configured as follows:
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();
While I have successfully rendered the albums, I am facing an issue when trying to view the images within a specific album since the image collection URL is static.
Could you provide any guidance on how I can retrieve and display images inside an album using both Backbone.js and tastypie?