I want to upload images to the django server using my application and the folder/directory_name to which the image has to be uploaded, should be auto populated using the foreignkey relationship that my models are sharing
My models classes are as follows,
class Event(models.Model):
event_name = models.CharField(max_length=200)
event_desc = models.CharField(max_length=5000)
def __str__(self):
return self.event_name
class Image(models.Model):
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
image_name = models.CharField(max_length=200)
image = models.ImageField(upload_to='events/{}'.format("something"))
def __str__(self):
return self.image_name
the something in the models.ImageField function has to be replaced by the event_name dynamically and the value for event_name should be populated dynamically.