mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
Merged to trunk r1320
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1321 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
commit
e66c99a356
@ -138,7 +138,6 @@ DATA_TYPES = {
|
||||
'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
|
||||
'DateField': 'smalldatetime',
|
||||
'DateTimeField': 'smalldatetime',
|
||||
'EmailField': 'varchar(75)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FloatField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
|
@ -154,7 +154,6 @@ DATA_TYPES = {
|
||||
'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
|
||||
'DateField': 'date',
|
||||
'DateTimeField': 'datetime',
|
||||
'EmailField': 'varchar(75)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FloatField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
|
@ -159,7 +159,6 @@ DATA_TYPES = {
|
||||
'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
|
||||
'DateField': 'date',
|
||||
'DateTimeField': 'timestamp with time zone',
|
||||
'EmailField': 'varchar(75)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FloatField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
|
@ -157,7 +157,6 @@ DATA_TYPES = {
|
||||
'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
|
||||
'DateField': 'date',
|
||||
'DateTimeField': 'datetime',
|
||||
'EmailField': 'varchar(75)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FloatField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
|
@ -778,9 +778,9 @@ class TimeField(TextField):
|
||||
|
||||
class EmailField(TextField):
|
||||
"A convenience FormField for validating e-mail addresses"
|
||||
def __init__(self, field_name, length=50, is_required=False, validator_list=[]):
|
||||
def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=[]):
|
||||
validator_list = [self.isValidEmail] + validator_list
|
||||
TextField.__init__(self, field_name, length, maxlength=75,
|
||||
TextField.__init__(self, field_name, length, maxlength=maxlength,
|
||||
is_required=is_required, validator_list=validator_list)
|
||||
|
||||
def isValidEmail(self, field_data, all_data):
|
||||
|
@ -604,6 +604,11 @@ def get_validation_errors(outfile):
|
||||
for f in opts.fields:
|
||||
if isinstance(f, meta.CharField) and f.maxlength in (None, 0):
|
||||
e.add(opts, '"%s" field: CharFields require a "maxlength" attribute.' % f.name)
|
||||
if isinstance(f, meta.FloatField):
|
||||
if f.decimal_places is None:
|
||||
e.add(opts, '"%s" field: FloatFields require a "decimal_places" attribute.' % f.name)
|
||||
if f.max_digits is None:
|
||||
e.add(opts, '"%s" field: FloatFields require a "max_digits" attribute.' % f.name)
|
||||
if isinstance(f, meta.FileField) and not f.upload_to:
|
||||
e.add(opts, '"%s" field: FileFields require an "upload_to" attribute.' % f.name)
|
||||
if isinstance(f, meta.ImageField):
|
||||
|
@ -890,12 +890,13 @@ def method_init(opts, self, *args, **kwargs):
|
||||
except KeyError:
|
||||
val = f.get_default()
|
||||
else:
|
||||
# Object instance was passed in.
|
||||
# Special case: You can pass in "None" for related objects if it's allowed.
|
||||
if rel_obj is None and f.null:
|
||||
val = None
|
||||
else:
|
||||
try:
|
||||
val = getattr(rel_obj, f.rel.field_name)
|
||||
val = getattr(rel_obj, f.rel.get_related_field().attname)
|
||||
except AttributeError:
|
||||
raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj))
|
||||
setattr(self, f.attname, val)
|
||||
@ -1028,7 +1029,12 @@ def method_get_many_to_one(field_with_rel, self):
|
||||
mod = field_with_rel.rel.to.get_model_module()
|
||||
if val is None:
|
||||
raise getattr(mod, '%sDoesNotExist' % field_with_rel.rel.to.object_name)
|
||||
retrieved_obj = mod.get_object(**{'%s__exact' % field_with_rel.rel.field_name: val})
|
||||
other_field = field_with_rel.rel.get_related_field()
|
||||
if other_field.rel:
|
||||
params = {'%s__%s__exact' % (field_with_rel.rel.field_name, other_field.rel.field_name): val}
|
||||
else:
|
||||
params = {'%s__exact'% field_with_rel.rel.field_name: val}
|
||||
retrieved_obj = mod.get_object(**params)
|
||||
setattr(self, cache_var, retrieved_obj)
|
||||
return getattr(self, cache_var)
|
||||
|
||||
@ -1094,7 +1100,7 @@ def method_get_related(method_name, rel_mod, rel_field, self, **kwargs):
|
||||
if self._meta.has_related_links and rel_mod.Klass._meta.module_name == 'relatedlinks':
|
||||
kwargs['object_id__exact'] = getattr(self, rel_field.rel.field_name)
|
||||
else:
|
||||
kwargs['%s__%s__exact' % (rel_field.name, rel_field.rel.to.pk.name)] = getattr(self, rel_field.rel.field_name)
|
||||
kwargs['%s__%s__exact' % (rel_field.name, rel_field.rel.to.pk.name)] = getattr(self, rel_field.rel.get_related_field().attname)
|
||||
kwargs.update(rel_field.rel.lookup_overrides)
|
||||
return getattr(rel_mod, method_name)(**kwargs)
|
||||
|
||||
|
@ -460,6 +460,13 @@ class DateTimeField(DateField):
|
||||
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
|
||||
class EmailField(Field):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['maxlength'] = 75
|
||||
Field.__init__(self, *args, **kwargs)
|
||||
|
||||
def get_internal_type(self):
|
||||
return "CharField"
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
return [formfields.EmailField]
|
||||
|
||||
|
@ -240,6 +240,15 @@ See our `Django-friendly Web hosts`_ page.
|
||||
|
||||
.. _`Django-friendly Web hosts`: http://code.djangoproject.com/wiki/DjangoFriendlyWebHosts
|
||||
|
||||
Should I use the official version or development version?
|
||||
---------------------------------------------------------
|
||||
|
||||
The Django developers improve Django every day and are pretty good about not
|
||||
checking in broken code. We use the development code (from the Subversion
|
||||
repository) directly on our servers, so we consider it stable. With that in
|
||||
mind, we recommend that you use the latest development code, because it
|
||||
generally contains more features and fewer bugs than the "official" releases.
|
||||
|
||||
Using Django
|
||||
============
|
||||
|
||||
|
@ -591,8 +591,11 @@ TIME_ZONE
|
||||
|
||||
Default: ``'America/Chicago'``
|
||||
|
||||
A string representing the time zone for this installation.
|
||||
`See available choices`_.
|
||||
A string representing the time zone for this installation. `See available choices`_.
|
||||
|
||||
Note that this is the time zone to which Django will convert all dates/times --
|
||||
not necessarily the timezone of the server. For example, one server may serve
|
||||
multiple Django-powered sites, each with a separate time-zone setting.
|
||||
|
||||
USE_ETAGS
|
||||
---------
|
||||
|
@ -9,6 +9,7 @@ from django.core import meta
|
||||
class Reporter(meta.Model):
|
||||
first_name = meta.CharField(maxlength=30)
|
||||
last_name = meta.CharField(maxlength=30)
|
||||
email = meta.EmailField()
|
||||
|
||||
def __repr__(self):
|
||||
return "%s %s" % (self.first_name, self.last_name)
|
||||
@ -23,7 +24,7 @@ class Article(meta.Model):
|
||||
|
||||
API_TESTS = """
|
||||
# Create a Reporter.
|
||||
>>> r = reporters.Reporter(first_name='John', last_name='Smith')
|
||||
>>> r = reporters.Reporter(first_name='John', last_name='Smith', email='john@example.com')
|
||||
>>> r.save()
|
||||
|
||||
# Create an Article.
|
||||
|
@ -28,7 +28,7 @@ class Waiter(meta.Model):
|
||||
name = meta.CharField(maxlength=50)
|
||||
|
||||
def __repr__(self):
|
||||
return "%s the waiter at %s" % (self.name, self.get_restaurant())
|
||||
return "%s the waiter at %r" % (self.name, self.get_restaurant())
|
||||
|
||||
API_TESTS = """
|
||||
# Create a couple of Places.
|
||||
|
Loading…
x
Reference in New Issue
Block a user