0

I encountered a problem with Django 1.7. When I want make my migration I raise this exception : Models aren't loaded yet. I tried solution said here but it doesn't work. I saw this solution but I can't how do it with my models. Error is due to person_type field on UserProfile Class. When I removed it migrations works.

class Typo_model(BaseModel):
    key   = models.CharField(max_length=32, db_index=True)
    text = models.CharField(max_length=255)


class UserProfile(AbstractUser, BaseModel):
    person_type = models.ForeignKey(Typo_model, queryset =
    Typo_model.objects.filter(cle="person_type"), verbose_name="Person type")
Community
  • 1
  • 1
Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94

1 Answers1

0

I don't think you can set queryset on a ForeignKey. Purhaps limit_choices_to is what you are looking for. https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to

Like this:

person_type = models.ForeignKey(
    Typo_model,
    limit_choices_to={'cle': 'person_type'}
)
jproffitt
  • 6,225
  • 30
  • 42