Skip to content

Commit

Permalink
Fix #34 -- Support migrations for blank fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jnns authored Jul 28, 2022
1 parent 95ca8d8 commit 3f103b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pictures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def delete(self):
class PictureFieldFile(ImageFieldFile):
def save(self, name, content, save=True):
super().save(name, content, save)
if self:
self.save_all()
self.save_all()

def save_all(self):
from . import tasks
if self:
from . import tasks

tasks.process_picture(self)
tasks.process_picture(self)

def delete(self, save=True):
self.delete_all()
Expand Down
22 changes: 22 additions & 0 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ class Meta:
)
assert path.exists()

@pytest.mark.django_db
def test_to_picture_field_blank(self, request, stub_worker):
class FromModel(models.Model):
picture = models.ImageField(blank=True)

class Meta:
app_label = request.node.name
db_table = "testapp_profile"

class ToModel(models.Model):
name = models.CharField(max_length=100)
picture = models.ImageField(upload_to="testapp/profile/", blank=True)

class Meta:
app_label = request.node.name
db_table = "testapp_profile"

ToModel.objects.create(name="Luke")
stub_worker.join()
migration = migrations.AlterPictureField("profile", "picture", PictureField())
migration.to_picture_field(FromModel, Profile)

@pytest.mark.django_db
def test_to_picture_field__from_stdimage(
self, request, stub_worker, image_upload_file
Expand Down

0 comments on commit 3f103b5

Please sign in to comment.