[Django] #22866: quoted class names in foreign key definition causes ValueError

4 views
Skip to first unread message

Django

unread,
Jun 18, 2014, 6:32:30 PM6/18/14
to django-...@googlegroups.com
#22866: quoted class names in foreign key definition causes ValueError
--------------------------------+--------------------
Reporter: renatooliveira | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------
my scenario

Ramiro, I CCed you because of this comment: ticket:10405#comment:46

app_a/models.py
{{{#!python
class Model_A(models.Model):
name = models.CharField(...)
}}}

app_b/models.py
{{{#!python
class Model_B(models.Model):
field_a = models.ForeignKey('app_a.Model_A' ...)
}}}

app_b/forms.py

{{{#!python
from app_b.models import Model_B


class FormModel_B(forms.ModelForm):

class Meta:
model = Model_B
}}}

On app_b/tests/test_forms.py I have

{{{#!python
from app_b.forms import FormModel_B
}}}

And it gives me a {{{ValueError}}}

{{{ ValueError: Cannot create form field for 'field_a' yet, because its
related model 'app_a.Model_A' has not been loaded yet }}}

But when I just import Model_A on app_b/models.py file

{{{#!python
from app_a.models import Model_A


class Model_B(models.Model):
field_a = models.ForeignKey('app_a.Model_A' ...)
}}}

my settings.py

{{{#!python
INSTALLED_APPS = (
...
'app_a',
'app_b',
}
}}}

It works.

This is actually code from the project that I created to reproduce the
behavior.

https://github.com/renatooliveira/test_bug

I'm willing to try fix this issue since it's accepted.


Best Regards.

--
Ticket URL: <https://code.djangoproject.com/ticket/22866>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 18, 2014, 6:56:09 PM6/18/14
to django-...@googlegroups.com
#22866: quoted class names in foreign key definition causes ValueError
--------------------------------+--------------------------------------
Reporter: renatooliveira | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by renatooliveira):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Same issue as here: https://code.djangoproject.com/ticket/22865

Sorry

--
Ticket URL: <https://code.djangoproject.com/ticket/22866#comment:1>

Reply all
Reply to author
Forward
0 new messages