1

I have recently added new ImageField to my Bird model in Django application.

# models.py
class Bird(models.Model):
    name = models.CharField(max_length=50)
    project = models.ForeignKey(
        Project,
        related_name='birds',
        on_delete=models.CASCADE
    )

    def bird_images_path(instance, filename):
        return 'bird_images/' + instance.project.directory + '/' + filename

    image = models.ImageField(upload_to=bird_images_path, null=True, blank=True)

In django admin I have added new records to Bird table in db, uploaded images and they appered in my media path (\media\bird_images\birds) as expected. Everything worked well.

Nevertheless, after some time some weirdly named copies of my previous files appeared in the same location. For example, dove_ee9rsOT.jpg and dove_zRCwQrj.jpg are now saved next to originally uploaded dove.jpg. All three images are identical and the database record contains one of the new ones.

However, I don't recall adding any such images and nobody else has access to my app. Is there any explanation for this behavior or a way how to prevent it?

Petr Hofman
  • 162
  • 1
  • 15
  • I may have found an explanation. When I tried to investigate and add new records to db at one time I got "Database is locked" error and this kind of duplicate file appeared again. I still use sqlite db so hopefully it will disappear when I switch to proper db in production. – Petr Hofman Apr 02 '19 at 14:49

0 Answers0