circular imports error

24 views
Skip to first unread message

frank dilorenzo

unread,
Jun 11, 2021, 7:22:17 PM6/11/21
to Django users
Hello,  I have 3 separate app as follow:
from django.db import models

# Create your models here.

# Supplier can have many shipments
class Supplier(models.Model):
name = models.CharField(max_length=120, null=True)
phone = models.CharField(max_length=15, null=True)
email = models.CharField(max_length=120, null=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def __str__(self):
return self.name
-----------------------------------------
from django.db import models
from django.utils import timezone

# Create your models here.

# A specie can belong to many shipments
class Specie(models.Model):
name = models.CharField(max_length=120, null=True)
image = models.ImageField(upload_to="species", default="no_picture.png")
created = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.name
--------------------------------------------
from django.db import models
from .models import Supplier

# from .models import Supplier, Specie

# Create your models here.

# A shipment can have many species
class Shipment(models.Model):

supplier = models.ManyToManyField(Suppliers)
specie = models.ManyToManyField(Species)

name = models.CharField(
max_length=120, null=True, help_text="enter name from Supplier above..."
)
slabel = models.CharField(max_length=10)
received = models.PositiveIntegerField(default=0)
bad = models.PositiveIntegerField(default=0)
non = models.PositiveIntegerField(default=0)
doa = models.PositiveIntegerField(default=0)
para = models.PositiveIntegerField(default=0)
released = models.PositiveIntegerField(default=0)
entered = models.BooleanField(default=False)
created = models.DateTimeField(default=timezone.now)

def __str__(self):
return f"{self.slabel}"

=======================

when trying to migrate I get this error message:

ImportError: cannot import name 'Supplier' from partially initialized module 'shipments.models' (most likely due to a circular import) (/Users/frankd/django_projects/stlzoo/src/shipments/models.py)

I am stuck here and cannot seem to resolve this error.  I would truly appreciate any help on this.  Thanks.

Frank

Adam Stein

unread,
Jun 11, 2021, 7:43:46 PM6/11/21
to django...@googlegroups.com
Since you said 3 separate apps, I assume each of these classes are in a separate file. However, you have the line:

from .models import Supplier

which would make it seem that Supplier is defined in the same file as Shipment. Shipment should be in ".models" and if Supplier is also defined in the same file, no need to import it. If it's defined in a different file, then the import should reference another place, not ".models".
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0aff4c4-651a-43ad-9ac9-42c6452a33f4n%40googlegroups.com.

frank dilorenzo

unread,
Jun 11, 2021, 10:30:06 PM6/11/21
to django...@googlegroups.com
I hate to sound corny but you sir are my hero!.  Thanks,  it all works now
 
frank-


Adam Stein

unread,
Jun 12, 2021, 12:00:40 AM6/12/21
to django...@googlegroups.com
Glad to be of help. Sometimes it just takes a fresh pair of eyes.
Reply all
Reply to author
Forward
0 new messages