0

I am designing a website using django. The idea of a website is to have photographers and each photographer would have an album or more albums and each album would have one or more photo/photos. Currently I have:

class Photo(models.Model):
 name=models.ForeignKey('Album')
 p=models.ImageField()
 def __unicode__(self):
 return self.name
class Album(models.Model):
 name=models.ForeignKey('Photographer')
 def __unicode__(self):
 return self.name
class Photographer(models.Model):
 name=models.ForeignKey('User')
 def __unicode__(self):
 return self.name

The question is if you have the same design would you create a directory for each photographer and for each album you would create another directory in the parent directory and then store the photos in that album's directory or store them in the database. I know that is a newbie question but I really need help. If you have other design to make it easier on me please let me know.

Thanks in advance, Abdul

asked Dec 1, 2012 at 2:27
1
  • Uh... I'd let the storage handler deal with it for me... Commented Dec 1, 2012 at 2:31

3 Answers 3

2

Use the imagefield to store all the photos at one place and even better store them in cloud storage services. And as to regarding the relation have ForeignKeys in Photo model relating to Album and Photographer. Than use reverse relationship to find out the photos of each album or Photographer.

Your code might look like this`

class Photo(models.Model):
image = ImageField(upload_to="whereever you want to")
album = ForeignKey(Album)
photographer=ForeignKey(Photographer)

and after you get a particular album you can use Album.set_all and photographer.set_all to get all the photos of a particular album or photographer

`

answered Dec 1, 2012 at 6:20
Sign up to request clarification or add additional context in comments.

Comments

1

Yes, store the photos directly in the file system, rather than database. This is a common practise which makes sense for many reasons, mostly related to performance.

If you expect to have thousends of photos then dont keep them one directory, cause that can cause performance issues on popular systems. Instead, design a simple hierarchy appropriate for your application.

answered Dec 1, 2012 at 2:33

3 Comments

Does it handle non Latin later and conflate?
What do you mean non Latin later and conflate? Since it stores the files on disk, then it can store all files with valid filenames, which includes some non-latin characters.
The users of the website uses Arabic
0

There is no need to create directories for photographer or an album. That is what databases are for. You can have one giant folder (specified in upload_to) which will contain all uploaded images for all photographers and albums and then its up for a db to keep track which photos belong to what photographer/album.

By the way you should specify upload_to parameter for ImageField:

models.ImageField(upload_to='images/')

If you really want to create folders for each album, you can pass a function to upload_to parameter and add whatever logic you want there... more about that in the docs here.

answered Dec 1, 2012 at 2:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.