Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with Django 1.7 migrations #17

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
.idea
*.egg-info
21 changes: 19 additions & 2 deletions timezone_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import six
from django.utils.encoding import smart_text
from django.utils.encoding import smart_text, force_text


class TimeZoneFieldBase(models.Field):
Expand Down Expand Up @@ -72,7 +72,24 @@ def _get_python_and_db_repr(self, value):
# http://packages.python.org/six/#six.with_metaclass
class TimeZoneField(six.with_metaclass(models.SubfieldBase,
TimeZoneFieldBase)):
pass
def deconstruct(self):
# as field attributes, we want to preserve the max_length and if it
# exists, also the default the user has specified
keywords = {'max_length': TimeZoneField.MAX_LENGTH}
if self.default != models.fields.NOT_PROVIDED:
keywords['default'] = self.default

# information to recreate the field
return (
force_text(self.name, strings_only=True), # name of the field on
# the model
'timezone_field.fields.TimeZoneField', # import path of the
# field
(), # list of positional
# arguments
keywords # dict of keyword
# arguments
)


# South support
Expand Down
5 changes: 5 additions & 0 deletions timezone_field/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
},
}

# The name of the class to use for starting the test suite. Set
# explicitly to the default value to silence an upgrade path warning
# on Django 1.7.
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
Expand Down
1 change: 1 addition & 0 deletions timezone_field/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestForm(forms.Form):
class TestModelForm(forms.ModelForm):
class Meta:
model = TestModel
# fields = ['tz', 'tz_opt', 'tz_opt_default',]


class TimeZoneFormFieldTestCase(TestCase):
Expand Down