0

I'd like my two image fields point to the same image.

At one time, I'll have one image field populated. At later time, I'd like another imageField to point to the same file.

(If the first one changes, the second one gets updated as well)

The file is at amazon s3 if it matters.

I've asked the same question before, and I got a suggestion to use ForeignKey to Image table.
That's a possibility. But it incurs another DB hit to get an image.

I suspect image field is just a pointer to a file (and a meta data about the file I guess), and there might be a way to just store the same pointer in multiple imagefields...

eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

0

You can set the image path manually like this:

from django.db import models

class Example(models.Model):
    image = models.ImageField(upload_to="somewhere/special")   

example = Example.objects.get(id=1)

example.image = 'somewhere/special/filename.jpeg'
example.save()

But it wont change two fields at the same time . For this you will need to use a signals and do this same time update logic manually

Aldarund
  • 17,312
  • 5
  • 73
  • 104