Answer the question
In order to leave comments, you need to log in
How do I organize a bunch of models in creating a photo album?
Welcome all.
I need to make a photo album, and the task arose to correctly organize a bunch of one object with another. I found an example
on StackOverFlow ( here ). It turns out you need to make the Album model with ForeignKey on the image model.
Here's what happened:
class Album(models.Model):
name = models.CharField(max_length=35)
owner = models.ForeignKey(User)
images = models.ForeignKey(Image)
create_date = models.DateTimeField(auto_now_add=True)
class Image(models.Model):
image = models.ImageField()
upload_date = models.DateTimeField(auto_now_add=True)
slug = models.SlugField()
views = models.IntegerField(default=0)
Answer the question
In order to leave comments, you need to log in
Relationship Photo is in Album, not Album is in Photo
https://docs.djangoproject.com/en/dev/ref/models/f...
class Album(models.Model):
name = models.CharField(max_length=35)
owner = models.ForeignKey(User)
create_date = models.DateTimeField(auto_now_add=True)
class Image(models.Model):
album = models.ForeignKey(Image, related_name='images')
image = models.ImageField()
upload_date = models.DateTimeField(auto_now_add=True)
slug = models.SlugField()
views = models.IntegerField(default=0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question