Search code examples
djangodjango-south

How to specify Decimal as one-off value for Django South migration


I added a DecimalField to my model

dec_field = models.DecimalField(max_digits=6, decimal_places=3)

After I tried to create an auto schemamigration file with South, I attempt to specify a one-off value to use for existing columns now, but...

? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
>>> Decimal('15.4')
! Invalid input: name 'Decimal' is not defined
>>> from decimal import *
! Invalid input: invalid syntax (<string>, line 1)

Is it possible for me to specify a Decimal default value (lossless, so float is not ideal), and if so how?


Solution

  • looking at the code:: https://bitbucket.org/andrewgodwin/south/src/81b93bfc927b46227103d094691b5ddcfc25f400/south/creator/actions.py?at=default#cl-190

    I tried doing this:

        __import__('decimal').Decimal('0.445')
    

    and worked

    but This is bizarre, the most correct would just put a string it automatically converts

    or import Decimal in that the south migration created