Reputation: 125
I need a few photos of each Food
. How well design model?
This is my try, but it is not a good:
class Photo(models.Model):
img = models.ImageField(upload_to="media/images")
class Food(models.Model):
name = models.CharField(max_length=100)
desc = models.TextField()
photo = models.ManyToManyField(Photo)
Upvotes: 1
Views: 87
Reputation: 4320
In my opinion ForeignKey will be better:
class Photo(models.Model):
img = models.ImageField(upload_to="media/images")
food = models.ForeignKey(Food)
class Food(models.Model):
name = models.CharField(max_length=100)
desc = models.TextField()
bacause one photo is always for specific food
Upvotes: 3