Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed managing foreignkey in different backend engine

  • Loading branch information...
commit edcdc1d9364224fcbc3b810b9d9fa19a10cd537c 1 parent 62baf86
Alberto Paro authored
View
6 README
@@ -10,6 +10,12 @@ Future backends to support are:
- ...
+IMPORTANT COMMITS:
+------------------
+
+- http://github.com/aparo/django/commit/62baf86ff872b3a271619a4327d7b08180c89337 allows to redefin the king of autofield in DatabaseOperations of an engine
+
+
All documentation is in the "docs" directory and online at
http://docs.djangoproject.com/en/dev/. If you're just getting started, here's
View
2  django/__init__.py
@@ -1,5 +1,7 @@
VERSION = (1, 2, 0, 'rc', 1)
+MODIFIED = True
+
def get_version():
version = '%s.%s' % (VERSION[0], VERSION[1])
if VERSION[2]:
View
9 django/db/models/fields/related.py
@@ -851,8 +851,13 @@ def get_db_prep_save(self, value, connection):
if value == '' or value == None:
return None
else:
- return self.rel.get_related_field().get_db_prep_save(value,
- connection=connection)
+ if connection.alias!=self.rel.to.objects.db:
+ #Cross database management
+ #TODO: check also engine name?
+ return value
+ else:
+ return self.rel.get_related_field().get_db_prep_save(value,
+ connection=connection)
def value_to_string(self, obj):
if not obj:
View
28 django/forms/fields.py
@@ -195,9 +195,13 @@ def to_python(self, value):
return smart_unicode(value)
def widget_attrs(self, widget):
+ attrs = {}
if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
# The HTML attribute is maxlength, not max_length.
- return {'maxlength': str(self.max_length)}
+ attrs['maxlength'] = str(self.max_length)
+ if self.required and isinstance(widget, (TextInput, PasswordInput)):
+ attrs['required'] = "required"
+ return attrs
class IntegerField(Field):
default_error_messages = {
@@ -207,8 +211,9 @@ class IntegerField(Field):
}
def __init__(self, max_value=None, min_value=None, *args, **kwargs):
+ self.max_value = max_value
+ self.min_value = min_value
super(IntegerField, self).__init__(*args, **kwargs)
-
if max_value is not None:
self.validators.append(validators.MaxValueValidator(max_value))
if min_value is not None:
@@ -230,6 +235,16 @@ def to_python(self, value):
raise ValidationError(self.error_messages['invalid'])
return value
+ def widget_attrs(self, widget):
+ attrs = {}
+ if self.max_value is not None and isinstance(widget, TextInput):
+ attrs['max'] = str(self.max_value)
+ if self.min_value is not None and isinstance(widget, TextInput):
+ attrs['min'] = str(self.min_value)
+ if self.required and isinstance(widget, (TextInput, PasswordInput)):
+ attrs['required'] = "required"
+ return attrs
+
class FloatField(IntegerField):
default_error_messages = {
'invalid': _(u'Enter a number.'),
@@ -423,6 +438,15 @@ def __init__(self, regex, max_length=None, min_length=None, error_message=None,
self.regex = regex
self.validators.append(validators.RegexValidator(regex=regex))
+ def widget_attrs(self, widget):
+ attrs = {}
+ if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
+ # The HTML attribute is maxlength, not max_length.
+ attrs['maxlength'] = str(self.max_length)
+ if self.required and isinstance(widget, (TextInput, PasswordInput)):
+ attrs['required'] = "required"
+ return attrs
+
class EmailField(CharField):
default_error_messages = {
'invalid': _(u'Enter a valid e-mail address.'),
Please sign in to comment.
Something went wrong with that request. Please try again.