#24259: Django 1.7.4 makes the same migration change when `upload_to` and
`validators` are set.
-------------------------------+------------------------
     Reporter:  user0007       |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Migrations     |    Version:  1.7
     Severity:  Normal         |   Keywords:  migrations
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+------------------------
 My model:
 {{{#!python
     from myapps.core.fstorages.util import get_upload_path
     from myapps.core.validators.base import FileValidator


     class Entry(models.Model):
         ....
         photo = models.ImageField(
             max_length=200,
             upload_to=get_upload_path,
             validators=[
                 FileValidator(
                     allowed_extensions=['png', 'jpg'],
                     max_size=10 * 1024 * 1024,
                 )
             ]
         )
 }}}

 Running makemigrations:

     $ python manage.py makemigrations entries

 Migration:
 {{{#!python
     class Migration(migrations.Migration):
         ...
         operations = [
             migrations.AlterField(
                 model_name='entry',
                 name='photo',
 field=models.ImageField(upload_to=myapps.core.fstorages.util.get_upload_path,
 max_length=200, verbose_name='photo',
 
validators=[myapps.core.validators.base.FileValidator(allowed_extensions=[b'png',
 b'jpg'], max_size=10485760)]),
             preserve_default=True,
         ),
     ]
 }}}
 Running migrations

     $ python manage.py migrate entries
     OK


 Running migrations (once again):

     $ python manage.py migrate entries
     Your models have changes that are not yet reflected in a migration,
 and so won't be applied. Run 'manage.py makemigrations' to make new
 migrations, and then re-run 'manage.py migrate' to apply them.

 So I do:

     $ python manage.py makemigrations entries

 and get the same migration. Every time I run makemigrations Django creates
 the same migration for field "photo" .. is there some bug?

 Thanks.

 PS. FileValidator and get_upload_path source:

 {{{#!python
 def get_upload_path(instance, filename):
     return "/1/2/3"

 @deconstructible
 class FileValidator(object):
     def __init__(self, *args, **kwargs):
         self.allowed_extensions = kwargs.pop('allowed_extensions', ())
         self.allowed_mimetypes = kwargs.pop('allowed_mimetypes', ())
         self.min_size = kwargs.pop('min_size', 0)
         self.max_size = kwargs.pop('max_size', None)

     def __call__(self, value):
         # ...code here
         pass
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24259>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.f0f065985b76dc26243f280b939857df%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to