diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-08-12 14:15:08 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-08-12 14:15:08 +0000 |
| commit | 1d485cf14ffa58dbeb130db2d50aa147556e0244 (patch) | |
| tree | e883e8d12cceb1b7303fbbefb4d3c0f41ac6c4c8 /django | |
| parent | 386b12c1c668dd54d24704ef974e17b38abb825d (diff) | |
Fixed #10405 -- Raise a more useful error if the formfield of a related model field can't be created yet because the related model isn't loaded yet. Thanks ojii and charstring.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16604 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/exceptions.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py index 21be8702fa..201a854a4b 100644 --- a/django/core/exceptions.py +++ b/django/core/exceptions.py @@ -3,7 +3,7 @@ Global Django exception and warning classes. """ class DjangoRuntimeWarning(RuntimeWarning): - pass + pass class ObjectDoesNotExist(Exception): "The requested object does not exist" diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index e7f4b9b3de..3e861cddd2 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -905,6 +905,10 @@ class ForeignKey(RelatedField, Field): def formfield(self, **kwargs): db = kwargs.pop('using', None) + if isinstance(self.rel.to, basestring): + raise ValueError("Cannot create form field for %r yet, because " + "its related model %r has not been loaded yet" % + (self.name, self.rel.to)) defaults = { 'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.using(db).complex_filter(self.rel.limit_choices_to), |
