Opened 5 years ago

Closed 5 years ago

#22866 closed Uncategorized (duplicate)

quoted class names in foreign key definition causes ValueError

Reported by: Renato Oliveira Owned by: nobody
Component: Uncategorized Version: 1.6
Severity: Normal Keywords:
Cc: Ramiro Morales Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


my scenario

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


class Model_A(models.Model):
    name = models.CharField(...)


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


from app_b.models import Model_B

class FormModel_B(forms.ModelForm):
    class Meta:
        model = Model_B

On app_b/tests/ I have

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/ file

from app_a.models import Model_A

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



It works.

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

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

Best Regards.

Change History (1)

comment:1 Changed 5 years ago by Renato Oliveira

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top