summaryrefslogtreecommitdiff
path: root/django/db/models/fields
diff options
context:
space:
mode:
authorJeremy Dunck <jdunck@gmail.com>2007-06-25 19:33:37 +0000
committerJeremy Dunck <jdunck@gmail.com>2007-06-25 19:33:37 +0000
commitfc779fe55aec84994e7e761c743716ba03484bcc (patch)
treed139f5ce44133e630c7bb1b965baa3120ba23c99 /django/db/models/fields
parentb0a56a9919d2304fa08b71373b53fdfb5ca72de9 (diff)
gis: Merged revisions 5491-5539 via svnmerge from
http://code.djangoproject.com/svn/django/trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5540 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/fields')
-rw-r--r--django/db/models/fields/__init__.py32
-rw-r--r--django/db/models/fields/related.py12
2 files changed, 32 insertions, 12 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 136ce31b8b..016e26099b 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -74,12 +74,16 @@ class Field(object):
core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True,
prepopulate_from=None, unique_for_date=None, unique_for_month=None,
unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
- help_text='', db_column=None):
+ help_text='', db_column=None, db_tablespace=None):
self.name = name
self.verbose_name = verbose_name
self.primary_key = primary_key
self.maxlength, self.unique = maxlength, unique
self.blank, self.null = blank, null
+ # Oracle treats the empty string ('') as null, so coerce the null
+ # option whenever '' is a possible value.
+ if self.empty_strings_allowed and settings.DATABASE_ENGINE == 'oracle':
+ self.null = True
self.core, self.rel, self.default = core, rel, default
self.editable = editable
self.serialize = serialize
@@ -91,6 +95,7 @@ class Field(object):
self.radio_admin = radio_admin
self.help_text = help_text
self.db_column = db_column
+ self.db_tablespace = db_tablespace
# Set db_index to True if the field has a relationship and doesn't explicitly set db_index.
self.db_index = db_index
@@ -201,7 +206,7 @@ class Field(object):
if callable(self.default):
return self.default()
return self.default
- if not self.empty_strings_allowed or self.null:
+ if not self.empty_strings_allowed or (self.null and settings.DATABASE_ENGINE != 'oracle'):
return None
return ""
@@ -806,6 +811,7 @@ class IPAddressField(Field):
validators.isValidIPAddress4(field_data, None)
class NullBooleanField(Field):
+ empty_strings_allowed = False
def __init__(self, *args, **kwargs):
kwargs['null'] = True
Field.__init__(self, *args, **kwargs)
@@ -875,10 +881,18 @@ class TimeField(Field):
Field.__init__(self, verbose_name, name, **kwargs)
def get_db_prep_lookup(self, lookup_type, value):
+ if settings.DATABASE_ENGINE == 'oracle':
+ # Oracle requires a date in order to parse.
+ def prep(value):
+ if isinstance(value, datetime.time):
+ value = datetime.datetime.combine(datetime.date(1900, 1, 1), value)
+ return str(value)
+ else:
+ prep = str
if lookup_type == 'range':
- value = [str(v) for v in value]
+ value = [prep(v) for v in value]
else:
- value = str(value)
+ value = prep(value)
return Field.get_db_prep_lookup(self, lookup_type, value)
def pre_save(self, model_instance, add):
@@ -896,7 +910,15 @@ class TimeField(Field):
# doesn't support microseconds.
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
value = value.replace(microsecond=0)
- value = str(value)
+ if settings.DATABASE_ENGINE == 'oracle':
+ # cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
+ if isinstance(value, datetime.time):
+ value = datetime.datetime(1900, 1, 1, value.hour, value.minute,
+ value.second, value.microsecond)
+ elif isinstance(value, basestring):
+ value = datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
+ else:
+ value = str(value)
return Field.get_db_prep_save(self, value)
def get_manipulator_field_objs(self):
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 42eec6b4f0..60503ce14f 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -10,9 +10,10 @@ from django import oldforms
from django import newforms as forms
from django.dispatch import dispatcher
-# For Python 2.3
-if not hasattr(__builtins__, 'set'):
- from sets import Set as set
+try:
+ set
+except NameError:
+ from sets import Set as set # Python 2.3 fallback
# Values for Relation.edit_inline.
TABULAR, STACKED = 1, 2
@@ -335,10 +336,7 @@ def create_many_related_manager(superclass):
(target_col_name, self.join_table, source_col_name,
target_col_name, ",".join(['%s'] * len(new_ids))),
[self._pk_val] + list(new_ids))
- if cursor.rowcount is not None and cursor.rowcount != 0:
- existing_ids = set([row[0] for row in cursor.fetchmany(cursor.rowcount)])
- else:
- existing_ids = set()
+ existing_ids = set([row[0] for row in cursor.fetchall()])
# Add the ones that aren't there already
for obj_id in (new_ids - existing_ids):