Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
ImportError: cannot import name 'Affiliate' from partially initialized module 'affiliate.models' (most likely due to a circular import)

I'm getting a circular import error in django and can't seem to solve it. here's my models.py in affiliate(app)

from member.models import Member

class SubAffiliate(models.Model):
    member_id = models.ForeignKey(Member, on_delete=models.CASCADE)

and here's my models.py in member(app)

from affiliate.models import Affiliate

class Member(models.Model):
    affiliates = models.ManyToManyField(Affiliate, blank=True, related_name="members_affiliate")

for solving the problem I tried importing like this

import affiliate.models

and there use it like this

affiliate.models.Affiliate

then I get this error AttributeError: module 'affiliate' has no attribute 'models'

what should I do to resolve this error. Thank You!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The two models can not import each other. You can work with a string literal in case you need to refer to another module's model:

# no import from member.models!

class SubAffiliate(models.Model):
    member = models.ForeignKey(
        'member.Member',
        on_delete=models.CASCADE
    )

and for the other models.py file, you can also work with a string with the app_name.ModelName:

# no import from affiliate.models

class Member(models.Model):
    affiliates = models.ManyToManyField(
        'affiliate.Affiliate',
        blank=True,
        related_name='members_affiliate'
    )
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda