I've created a blog post
model where I'm going to add a varied number of pictures. How do I setup relations with the picture
model?
In the admin panel the blog
form should be displaying only pictures attached to this post. Each picture might be used in many posts.
class Post(models.Model):
name = models.CharField(max_length=200, null=False)
article = models.TextField(null=False)
img = models.ManyToManyField('Picture')
class Picture(models.Model):
def get_image_path(instance, filename):
return os.path.join('images', str(instance.id), filename)
picture = models.ImageField(upload_to=get_image_path, default = 'images/no-img.jpg')