mirror of
https://github.com/django/django.git
synced 2025-07-06 18:59:13 +00:00
queryset-refactor: Merged to [6197]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6335 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bf6a46d8ad
commit
d29c457ad1
1
AUTHORS
1
AUTHORS
@ -278,6 +278,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Frank Tegtmeyer <fte@fte.to>
|
Frank Tegtmeyer <fte@fte.to>
|
||||||
thebjorn <bp@datakortet.no>
|
thebjorn <bp@datakortet.no>
|
||||||
Zach Thompson <zthompson47@gmail.com>
|
Zach Thompson <zthompson47@gmail.com>
|
||||||
|
Deepak Thukral <deep.thukral@gmail.com>
|
||||||
tibimicu@gmax.net
|
tibimicu@gmax.net
|
||||||
tobias@neuyork.de
|
tobias@neuyork.de
|
||||||
Tom Tobin
|
Tom Tobin
|
||||||
|
1
django/contrib/admin/media/css/null.css
Normal file
1
django/contrib/admin/media/css/null.css
Normal file
@ -0,0 +1 @@
|
|||||||
|
/* Nothing to see here. Dummy file to feed to the high pass filter which hides CSS from IE5/win. Details: http://tantek.com/CSS/Examples/highpass.html */
|
@ -302,7 +302,8 @@ def sql_model_create(model, style, known_models=set()):
|
|||||||
|
|
||||||
if opts.has_auto_field:
|
if opts.has_auto_field:
|
||||||
# Add any extra SQL needed to support auto-incrementing primary keys.
|
# Add any extra SQL needed to support auto-incrementing primary keys.
|
||||||
autoinc_sql = connection.ops.autoinc_sql(opts.db_table)
|
auto_column = opts.auto_field.db_column or opts.auto_field.name
|
||||||
|
autoinc_sql = connection.ops.autoinc_sql(opts.db_table, auto_column)
|
||||||
if autoinc_sql:
|
if autoinc_sql:
|
||||||
for stmt in autoinc_sql:
|
for stmt in autoinc_sql:
|
||||||
final_output.append(stmt)
|
final_output.append(stmt)
|
||||||
@ -385,7 +386,7 @@ def many_to_many_sql_for_model(model, style):
|
|||||||
final_output.append('\n'.join(table_output))
|
final_output.append('\n'.join(table_output))
|
||||||
|
|
||||||
# Add any extra SQL needed to support auto-incrementing PKs
|
# Add any extra SQL needed to support auto-incrementing PKs
|
||||||
autoinc_sql = connection.ops.autoinc_sql(f.m2m_db_table())
|
autoinc_sql = connection.ops.autoinc_sql(f.m2m_db_table(), 'id')
|
||||||
if autoinc_sql:
|
if autoinc_sql:
|
||||||
for stmt in autoinc_sql:
|
for stmt in autoinc_sql:
|
||||||
final_output.append(stmt)
|
final_output.append(stmt)
|
||||||
|
@ -56,7 +56,7 @@ class BaseDatabaseOperations(object):
|
|||||||
a backend performs ordering or calculates the ID of a recently-inserted
|
a backend performs ordering or calculates the ID of a recently-inserted
|
||||||
row.
|
row.
|
||||||
"""
|
"""
|
||||||
def autoinc_sql(self, table):
|
def autoinc_sql(self, table, column):
|
||||||
"""
|
"""
|
||||||
Returns any SQL needed to support auto-incrementing primary keys, or
|
Returns any SQL needed to support auto-incrementing primary keys, or
|
||||||
None if no SQL is necessary.
|
None if no SQL is necessary.
|
||||||
|
7
django/db/backends/creation.py
Normal file
7
django/db/backends/creation.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class BaseCreation(object):
|
||||||
|
"""
|
||||||
|
This class encapsulates all backend-specific differences that pertain to
|
||||||
|
database *creation*, such as the column types to use for particular Django
|
||||||
|
Fields.
|
||||||
|
"""
|
||||||
|
pass
|
@ -31,20 +31,23 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
uses_custom_queryset = True
|
uses_custom_queryset = True
|
||||||
|
|
||||||
class DatabaseOperations(BaseDatabaseOperations):
|
class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def autoinc_sql(self, table):
|
def autoinc_sql(self, table, column):
|
||||||
# To simulate auto-incrementing primary keys in Oracle, we have to
|
# To simulate auto-incrementing primary keys in Oracle, we have to
|
||||||
# create a sequence and a trigger.
|
# create a sequence and a trigger.
|
||||||
sq_name = get_sequence_name(table)
|
sq_name = get_sequence_name(table)
|
||||||
tr_name = get_trigger_name(table)
|
tr_name = get_trigger_name(table)
|
||||||
|
tbl_name = self.quote_name(table)
|
||||||
|
col_name = self.quote_name(column)
|
||||||
sequence_sql = 'CREATE SEQUENCE %s;' % sq_name
|
sequence_sql = 'CREATE SEQUENCE %s;' % sq_name
|
||||||
trigger_sql = """
|
trigger_sql = """
|
||||||
CREATE OR REPLACE TRIGGER %s
|
CREATE OR REPLACE TRIGGER %(tr_name)s
|
||||||
BEFORE INSERT ON %s
|
BEFORE INSERT ON %(tbl_name)s
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
WHEN (new.id IS NULL)
|
WHEN (new.%(col_name)s IS NULL)
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT %s.nextval INTO :new.id FROM dual;
|
SELECT %(sq_name)s.nextval
|
||||||
END;/""" % (tr_name, self.quote_name(table), sq_name)
|
INTO :new.%(col_name)s FROM dual;
|
||||||
|
END;/""" % locals()
|
||||||
return sequence_sql, trigger_sql
|
return sequence_sql, trigger_sql
|
||||||
|
|
||||||
def date_extract_sql(self, lookup_type, field_name):
|
def date_extract_sql(self, lookup_type, field_name):
|
||||||
|
@ -440,6 +440,7 @@ class AutoField(Field):
|
|||||||
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."
|
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."
|
||||||
super(AutoField, self).contribute_to_class(cls, name)
|
super(AutoField, self).contribute_to_class(cls, name)
|
||||||
cls._meta.has_auto_field = True
|
cls._meta.has_auto_field = True
|
||||||
|
cls._meta.auto_field = self
|
||||||
|
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
return None
|
return None
|
||||||
@ -545,7 +546,12 @@ class DateField(Field):
|
|||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
# Casts dates into string format for entry into database.
|
# Casts dates into string format for entry into database.
|
||||||
if value is not None:
|
if value is not None:
|
||||||
value = value.strftime('%Y-%m-%d')
|
try:
|
||||||
|
value = value.strftime('%Y-%m-%d')
|
||||||
|
except AttributeError:
|
||||||
|
# If value is already a string it won't have a strftime method,
|
||||||
|
# so we'll just let it pass through.
|
||||||
|
pass
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
|
@ -33,7 +33,7 @@ class Options(object):
|
|||||||
self.admin = None
|
self.admin = None
|
||||||
self.meta = meta
|
self.meta = meta
|
||||||
self.pk = None
|
self.pk = None
|
||||||
self.has_auto_field = False
|
self.has_auto_field, self.auto_field = False, None
|
||||||
self.one_to_one_field = None
|
self.one_to_one_field = None
|
||||||
self.parents = []
|
self.parents = []
|
||||||
|
|
||||||
|
@ -105,6 +105,14 @@ import unittest, difflib, pdb, tempfile
|
|||||||
import warnings
|
import warnings
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
if sys.platform.startswith('java'):
|
||||||
|
# On Jython, isclass() reports some modules as classes. Patch it.
|
||||||
|
def patch_isclass(isclass):
|
||||||
|
def patched_isclass(obj):
|
||||||
|
return isclass(obj) and hasattr(obj, '__module__')
|
||||||
|
return patched_isclass
|
||||||
|
inspect.isclass = patch_isclass(inspect.isclass)
|
||||||
|
|
||||||
# Don't whine about the deprecated is_private function in this
|
# Don't whine about the deprecated is_private function in this
|
||||||
# module's tests.
|
# module's tests.
|
||||||
warnings.filterwarnings("ignore", "is_private", DeprecationWarning,
|
warnings.filterwarnings("ignore", "is_private", DeprecationWarning,
|
||||||
|
@ -985,7 +985,7 @@ validation if a particular field's value is not given. ``initial`` values are
|
|||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
The ``widget`` argument lets you specify a ``Widget`` class to use when
|
The ``widget`` argument lets you specify a ``Widget`` class to use when
|
||||||
rendering this ``Field``. See "Widgets"_ below for more information.
|
rendering this ``Field``. See `Widgets`_ below for more information.
|
||||||
|
|
||||||
``help_text``
|
``help_text``
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
@ -325,7 +325,8 @@ The default formatting to use for date fields on Django admin change-list
|
|||||||
pages -- and, possibly, by other parts of the system. See
|
pages -- and, possibly, by other parts of the system. See
|
||||||
`allowed date format strings`_.
|
`allowed date format strings`_.
|
||||||
|
|
||||||
See also DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and MONTH_DAY_FORMAT.
|
See also ``DATETIME_FORMAT``, ``TIME_FORMAT``, ``YEAR_MONTH_FORMAT``
|
||||||
|
and ``MONTH_DAY_FORMAT``.
|
||||||
|
|
||||||
.. _allowed date format strings: ../templates/#now
|
.. _allowed date format strings: ../templates/#now
|
||||||
|
|
||||||
@ -338,7 +339,8 @@ The default formatting to use for datetime fields on Django admin change-list
|
|||||||
pages -- and, possibly, by other parts of the system. See
|
pages -- and, possibly, by other parts of the system. See
|
||||||
`allowed date format strings`_.
|
`allowed date format strings`_.
|
||||||
|
|
||||||
See also DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and MONTH_DAY_FORMAT.
|
See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
|
||||||
|
``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
|
||||||
|
|
||||||
.. _allowed date format strings: ../templates/#now
|
.. _allowed date format strings: ../templates/#now
|
||||||
|
|
||||||
@ -350,8 +352,8 @@ Default: ``False``
|
|||||||
A boolean that turns on/off debug mode.
|
A boolean that turns on/off debug mode.
|
||||||
|
|
||||||
If you define custom settings, django/views/debug.py has a ``HIDDEN_SETTINGS``
|
If you define custom settings, django/views/debug.py has a ``HIDDEN_SETTINGS``
|
||||||
regular expression which will hide from the DEBUG view anything that contins
|
regular expression which will hide from the DEBUG view anything that contains
|
||||||
``'SECRET``, ``PASSWORD``, or ``PROFANITIES'``. This allows untrusted users to
|
``'SECRET'``, ``'PASSWORD'``, or ``'PROFANITIES'``. This allows untrusted users to
|
||||||
be able to give backtraces without seeing sensitive (or offensive) settings.
|
be able to give backtraces without seeing sensitive (or offensive) settings.
|
||||||
|
|
||||||
Still, note that there are always going to be sections of your debug output that
|
Still, note that there are always going to be sections of your debug output that
|
||||||
@ -656,8 +658,8 @@ drilldown, the header for a given day displays the day and month. Different
|
|||||||
locales have different formats. For example, U.S. English would say
|
locales have different formats. For example, U.S. English would say
|
||||||
"January 1," whereas Spanish might say "1 Enero."
|
"January 1," whereas Spanish might say "1 Enero."
|
||||||
|
|
||||||
See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT,
|
See `allowed date format strings`_. See also ``DATE_FORMAT``,
|
||||||
TIME_FORMAT and YEAR_MONTH_FORMAT.
|
``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``YEAR_MONTH_FORMAT``.
|
||||||
|
|
||||||
PREPEND_WWW
|
PREPEND_WWW
|
||||||
-----------
|
-----------
|
||||||
@ -815,7 +817,7 @@ highlighted.
|
|||||||
Note that Django only displays fancy error pages if ``DEBUG`` is ``True``, so
|
Note that Django only displays fancy error pages if ``DEBUG`` is ``True``, so
|
||||||
you'll want to set that to take advantage of this setting.
|
you'll want to set that to take advantage of this setting.
|
||||||
|
|
||||||
See also DEBUG.
|
See also ``DEBUG``.
|
||||||
|
|
||||||
TEMPLATE_DIRS
|
TEMPLATE_DIRS
|
||||||
-------------
|
-------------
|
||||||
@ -905,8 +907,8 @@ The default formatting to use for time fields on Django admin change-list
|
|||||||
pages -- and, possibly, by other parts of the system. See
|
pages -- and, possibly, by other parts of the system. See
|
||||||
`allowed date format strings`_.
|
`allowed date format strings`_.
|
||||||
|
|
||||||
See also DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and
|
See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
|
||||||
MONTH_DAY_FORMAT.
|
``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
|
||||||
|
|
||||||
.. _allowed date format strings: ../templates/#now
|
.. _allowed date format strings: ../templates/#now
|
||||||
|
|
||||||
@ -980,8 +982,8 @@ drilldown, the header for a given month displays the month and the year.
|
|||||||
Different locales have different formats. For example, U.S. English would say
|
Different locales have different formats. For example, U.S. English would say
|
||||||
"January 2006," whereas another locale might say "2006/January."
|
"January 2006," whereas another locale might say "2006/January."
|
||||||
|
|
||||||
See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT,
|
See `allowed date format strings`_. See also ``DATE_FORMAT``,
|
||||||
TIME_FORMAT and MONTH_DAY_FORMAT.
|
``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``MONTH_DAY_FORMAT``.
|
||||||
|
|
||||||
.. _cache docs: ../cache/
|
.. _cache docs: ../cache/
|
||||||
.. _middleware docs: ../middleware/
|
.. _middleware docs: ../middleware/
|
||||||
|
@ -20,6 +20,11 @@ class Article(models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
|
|
||||||
|
class Movie(models.Model):
|
||||||
|
#5218: Test models with non-default primary keys / AutoFields
|
||||||
|
movie_id = models.AutoField(primary_key=True)
|
||||||
|
name = models.CharField(max_length=60)
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
(NOTE: Part of the regression test here is merely parsing the model
|
(NOTE: Part of the regression test here is merely parsing the model
|
||||||
declaration. The verbose_name, in particular, did not always work.)
|
declaration. The verbose_name, in particular, did not always work.)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user