Skip to content

Instantly share code, notes, and snippets.

diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
index 879497d..0b78455 100644
--- a/django/contrib/sites/models.py
+++ b/django/contrib/sites/models.py
@@ -33,9 +33,9 @@ class SiteManager(models.Manager):
project's settings. The ``Site`` object is cached the first
time it's retrieved from the database.
"""
- from django.conf import settings
+ from django.core.urlresolvers import get_site
@loic
loic / gist:5861660
Last active December 18, 2015 23:29
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 8024981..bcaee9c 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -441,7 +441,7 @@ class ForeignRelatedObjectsDescriptor(object):
def create(self, **kwargs):
kwargs[rel_field.name] = self.instance
db = router.db_for_write(self.model, instance=self.instance)
- return super(RelatedManager, self.db_manager(db)).create(**kwargs)
+ return self.db_manager(db).get_queryset().create(**kwargs)
@loic
loic / gist:5867688
Last active December 19, 2015 00:19
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index b9caf8b..324adfd 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -19,6 +19,7 @@ from django.db.backends.sqlite3.introspection import DatabaseIntrospection
from django.db.models import fields
from django.db.models.sql import aggregates
from django.utils.dateparse import parse_date, parse_datetime, parse_time
+from django.utils.encoding import force_text
from django.utils.functional import cached_property
@loic
loic / gist:5899006
Last active December 19, 2015 04:39
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 4823883..f175d91 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -1,7 +1,7 @@
# encoding: utf-8
from __future__ import absolute_import, unicode_literals
-from datetime import datetime
+from datetime import datetime, timedelta, tzinfo
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 4823883..5b2cb9a 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -1,7 +1,8 @@
# encoding: utf-8
from __future__ import absolute_import, unicode_literals
-from datetime import datetime
+from datetime import datetime, timedelta, tzinfo
@loic
loic / gist:5939296
Last active December 19, 2015 10:19
diff --git a/django/template/context.py b/django/template/context.py
index 1ef7e88..8e4706c 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -12,6 +12,19 @@ class ContextPopException(Exception):
"pop() has been called more times than push()"
pass
+class ContextDict(dict):
+ def __init__(self, context, *args, **kwargs):
@loic
loic / gist:5999900
Last active December 19, 2015 18:38
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
index 160cdc7..49ed772 100644
--- a/docs/ref/templates/api.txt
+++ b/docs/ref/templates/api.txt
@@ -297,8 +297,8 @@ dictionary syntax::
>>> c['newvariable']
'hello'
-.. method:: pop()
-.. method:: push()
@loic
loic / gist:6008551
Last active December 19, 2015 19:48
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 09c62c5..d64295c 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -1800,3 +1800,24 @@ class M2mHelpTextTest(TestCase):
html = form.as_p()
self.assertInHTML('<ul id="id_status">', html)
self.assertInHTML(dreaded_help_text, html, count=0)
+
+
@loic
loic / gist:6009660
Last active December 19, 2015 19:58
The first time you call ``is_valid()`` or access the ``errors`` attribute of a
``ModelForm`` triggers :ref:`form validation <form-and-field-validation>` as
-well as :ref:`model validation <validating-objects>`. This has the side-effect
-of cleaning the model you pass to the ``ModelForm`` constructor. For instance,
-calling ``is_valid()`` on your form will convert any date fields on your model
-to actual date objects. If form validation fails, only some of the updates
-may be applied. For this reason, you'll probably want to avoid reusing the
-model instance passed to the form, especially if validation fails.
+well as :ref:`model validation <validating-objects>`.
+