Skip to content

Commit

Permalink
Update modelfields.py
Browse files Browse the repository at this point in the history
The patch to get_prep_value() allows manage.py migrate to successfully complete. This is to address issue "Running migration on phonenumberfield results in AttributeError stefanfoulis#123"

As per https://docs.djangoproject.com/en/1.8/howto/custom-model-fields/#custom-field-deconstruct-method, I also added the deconstruct method. I don't know if my migration will run without this, but figure since it's required, it should stay.
  • Loading branch information
dedayoa committed Apr 22, 2016
1 parent 63a3587 commit c8625ac
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions phonenumber_field/modelfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def get_prep_value(self, value):
return value
format_string = getattr(settings, 'PHONENUMBER_DB_FORMAT', 'E164')
fmt = PhoneNumber.format_map[format_string]

if value is None:
return ''

return value.format_as(fmt)

def contribute_to_class(self, cls, name):
Expand All @@ -85,6 +89,11 @@ def formfield(self, **kwargs):
}
defaults.update(kwargs)
return super(PhoneNumberField, self).formfield(**defaults)

def deconstruct(self):
name, path, args, kwargs = super(PhoneNumberField, self).deconstruct()
del kwargs["max_length"]
return name, path, args, kwargs


try:
Expand Down

0 comments on commit c8625ac

Please sign in to comment.