diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:57:25 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:57:25 +0000 |
| commit | ca33d307dee3cf68cc9cd2ccfae00c7ff23ea890 (patch) | |
| tree | e0f0afa392f4ab50de4a89e2a0b1b4cc53f40794 /django/db/models | |
| parent | 7325fbf4ff20f9b0f21d3a1aba1abaca78a765d7 (diff) | |
queryset-refactor: Merged to [6300]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6340 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/base.py | 4 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 10 | ||||
| -rw-r--r-- | django/db/models/manager.py | 4 | ||||
| -rw-r--r-- | django/db/models/manipulators.py | 3 |
4 files changed, 18 insertions, 3 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index b728150a40..208dfadddd 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -247,6 +247,7 @@ class Model(object): qn(self._meta.order_with_respect_to.column)) cursor.execute(subsel, (getattr(self, self._meta.order_with_respect_to.attname),)) db_values.append(cursor.fetchone()[0]) + record_exists = False if db_values: cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ (qn(self._meta.db_table), ','.join(field_names), @@ -261,7 +262,8 @@ class Model(object): transaction.commit_unless_managed() # Run any post-save hooks. - dispatcher.send(signal=signals.post_save, sender=self.__class__, instance=self) + dispatcher.send(signal=signals.post_save, sender=self.__class__, + instance=self, created=(not record_exists)) save.alters_data = True diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 8fa091dd76..5b7adb2fb9 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -919,11 +919,21 @@ class PhoneNumberField(IntegerField): class PositiveIntegerField(IntegerField): def get_manipulator_field_objs(self): return [oldforms.PositiveIntegerField] + + def formfield(self, **kwargs): + defaults = {'min_value': 0} + defaults.update(kwargs) + return super(PositiveIntegerField, self).formfield(**defaults) class PositiveSmallIntegerField(IntegerField): def get_manipulator_field_objs(self): return [oldforms.PositiveSmallIntegerField] + def formfield(self, **kwargs): + defaults = {'min_value': 0} + defaults.update(kwargs) + return super(PositiveSmallIntegerField, self).formfield(**defaults) + class SlugField(CharField): def __init__(self, *args, **kwargs): kwargs['max_length'] = kwargs.get('max_length', 50) diff --git a/django/db/models/manager.py b/django/db/models/manager.py index 040b86656a..7b2e916738 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -111,3 +111,7 @@ class ManagerDescriptor(object): if instance != None: raise AttributeError, "Manager isn't accessible via %s instances" % type.__name__ return self.manager + +class EmptyManager(Manager): + def get_query_set(self): + return self.get_empty_query_set() diff --git a/django/db/models/manipulators.py b/django/db/models/manipulators.py index c3e5292198..e0085d13ff 100644 --- a/django/db/models/manipulators.py +++ b/django/db/models/manipulators.py @@ -9,7 +9,6 @@ from django.utils.datastructures import DotExpandedDict from django.utils.text import capfirst from django.utils.encoding import smart_str from django.utils.translation import ugettext as _ -import types def add_manipulators(sender): cls = sender @@ -38,7 +37,7 @@ class ManipulatorDescriptor(object): bases = [self.base] if hasattr(model, 'Manipulator'): bases = [model.Manipulator] + bases - self.man = types.ClassType(self.name, tuple(bases), {}) + self.man = type(self.name, tuple(bases), {}) self.man._prepare(model) return self.man |
