diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 281963f..0ea9667 100644
a
|
b
|
class Field(object):
|
132 | 132 | memodict[id(self)] = obj |
133 | 133 | return obj |
134 | 134 | |
| 135 | def __getstate__(self): |
| 136 | obj_dict = self.__dict__.copy() |
| 137 | del obj_dict['default'] |
| 138 | return obj_dict |
| 139 | |
| 140 | def __setstate__(self, data): |
| 141 | self.__dict__.update(data) |
| 142 | |
| 143 | # Restore the default |
| 144 | self.default = self._model._meta.get_field_by_name(self.name)[0].default |
| 145 | |
| 146 | |
135 | 147 | def to_python(self, value): |
136 | 148 | """ |
137 | 149 | Converts the input value into the expected Python data type, raising |
… |
… |
class Field(object):
|
233 | 245 | |
234 | 246 | def contribute_to_class(self, cls, name): |
235 | 247 | self.set_attributes_from_name(name) |
| 248 | self._model = cls |
236 | 249 | cls._meta.add_field(self) |
237 | 250 | if self.choices: |
238 | 251 | setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self)) |
diff --git a/tests/regressiontests/queryset_pickle/models.py b/tests/regressiontests/queryset_pickle/models.py
index ec4bbed..b0cae0a 100644
a
|
b
|
|
| 1 | import datetime |
1 | 2 | from django.db import models |
2 | 3 | from django.utils.translation import ugettext_lazy as _ |
3 | 4 | |
| 5 | class Numbers(object): |
| 6 | |
| 7 | @classmethod |
| 8 | def get_number(self): |
| 9 | return 2 |
| 10 | |
4 | 11 | class Group(models.Model): |
5 | 12 | name = models.CharField(_('name'), max_length=100) |
6 | 13 | |
7 | 14 | class Event(models.Model): |
8 | 15 | group = models.ForeignKey(Group) |
| 16 | |
| 17 | class Happening(models.Model): |
| 18 | when = models.DateTimeField(blank=True, default=datetime.datetime.now) |
| 19 | name = models.CharField(blank=True, max_length=100, default=lambda:"test") |
| 20 | number = models.IntegerField(blank=True, default=Numbers.get_number) |
diff --git a/tests/regressiontests/queryset_pickle/tests.py b/tests/regressiontests/queryset_pickle/tests.py
index 8191403..99ec54f 100644
a
|
b
|
|
1 | 1 | import pickle |
| 2 | import datetime |
2 | 3 | |
3 | 4 | from django.test import TestCase |
4 | 5 | |
5 | | from models import Group, Event |
6 | | |
| 6 | from models import Group, Event, Happening |
7 | 7 | |
8 | 8 | class PickleabilityTestCase(TestCase): |
9 | 9 | def assert_pickles(self, qs): |
… |
… |
class PickleabilityTestCase(TestCase):
|
12 | 12 | def test_related_field(self): |
13 | 13 | g = Group.objects.create(name="Ponies Who Own Maybachs") |
14 | 14 | self.assert_pickles(Event.objects.filter(group=g.id)) |
| 15 | |
| 16 | def test_datetime_callable_default_all(self): |
| 17 | self.assert_pickles(Happening.objects.all()) |
| 18 | |
| 19 | def test_datetime_callable_default_filter(self): |
| 20 | self.assert_pickles(Happening.objects.filter(when=datetime.datetime.now())) |
| 21 | |
| 22 | def test_lambda_as_default(self): |
| 23 | self.assert_pickles(Happening.objects.filter(name="test")) |
| 24 | |
| 25 | def test_callable_as_default(self): |
| 26 | self.assert_pickles(Happening.objects.filter(number=1)) |