--
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/bc667e81-ce32-4df5-8f88-47dff3d852c8n%40googlegroups.com.
supplier.models:
class Supplier(models.Model):
name = models.CharField(max_length=50)
phone = models.CharField(max_length=15, null=True, blank=True)
email = models.CharField(max_length=120, null=True, blank=True)
country = models.CharField(max_length=120, null=True, blank=True)
address = models.CharField(max_length=120, null=True, blank=True)
city = models.CharField(max_length=120, null=True, blank=True)
state = models.CharField(max_length=120, null=True, blank=True)
zipCode = models.CharField(max_length=10, null=True, blank=True)
def __str__(self):
return self.name
shipment.models:
----------------
from django.db import models
from specie.models import Specie
from supplier.models import Supplier
# Create your models here.
class Shipment(models.Model):
created = models.DateTimeField()
specie = models.ManyToManyField(Specie)
label = models.CharField(max_length=10)
received = models.PositiveIntegerField()
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)
supplier = models.ForeignKey(Supplier, on_delete=models.DO_NOTHING)
def __str__(self):
return self.supplier
class Meta:
ordering = ["label"]
def __str__(self):
return self.label
# =================================#
When I add the line supplier = models.ForeignKey(Supplier, on_delete=models.DO_NOTHING)
I get this error:
File "/Users/frankd/django_projects/Insectarium/src/shipment/models.py", line 4, in <module>
from supplier.models import Supplier
File "/Users/frankd/django_projects/Insectarium/src/supplier/models.py", line 3, in <module>
from shipment.models import Shipment
ImportError: cannot import name 'Shipment' from partially initialized module 'shipment.models' (most likely due to a circular import) (/Users/frankd/django_
specie.models:
--------------
from django.db import models
from django.utils import timezone
from ckeditor.fields import RichTextField
from shipment.models import Shipment
# Create your models here.
class Specie(models.Model):
scientific_name = models.CharField(max_length=50)
common_name = models.CharField(max_length=50, blank=True, null=True)
description = RichTextField(blank=True, null=True)
image = models.ImageField(
upload_to="specie/images/species", default="no_picture.png"
)
shipment = models.ManyToManyField(Shipment)
created = models.DateField(default=timezone.now)
def __str__(self):
return self.scientific_name
class Meta:
ordering = [
"scientific_name",
]
def __str__(self):
return self.scientific_name
# ====================== #
when I add the line shipment = models.ManyToManyField(Shipment)
I get this error.
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/frankd/django_projects/Insectarium/src/shipment/models.py", line 3, in <module>
from specie.models import Specie
File "/Users/frankd/django_projects/Insectarium/src/specie/models.py", line 5, in <module>
from shipment.models import Shipment
ImportError: cannot import name 'Shipment' from partially initialized module 'shipment.models' (most likely due to a circular import) (/Users/frankd/django_
I think I tried this before but couldn't resolve these errors. Any suggestions would be appreciated.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f41caba-62f3-45e8-b4d6-e9584f9e8068n%40googlegroups.com.
shipment = models.ForeignKey(
Shipment, on_delete=models.DO_NOTHING, null=True, blank=True)
specie/models.py
----------------
no reference to any other model
supplier/models.py
-------------------
specie = models.ManyToManyField(Specie)
Thanks for all the suggestions.