Reputation: 67
I have 5 classes, Customer
, Supplier
, Order
, Design
and OutSource
.
The Order
has 3 relationships, one to one with Customer
, many to many with Design
and one to one with OutSourse
. first I just did add its one to one relationship with
Customer(customer=models.ForeignKey(Customer)), now I wanna add the those 2 relationships with
Designand
Outsourse`.
design=models.ManyToManyField(Design)
outSource=models.OneToOneField(OutSource)
when I do that and run the "makemigrations" command I get this error--> "NameError:name "Design" is not defined" without those 2 lines of code I can migrate without any kinda problem...can't figure out where I'm going wrong. any help will be appreciated.
models.py
class Order(models.Model):
o_type=models.CharField(max_length=15, verbose_name='Order type')
number=models.IntegerField()
date=models.DateField()
status=models.CharField(max_length=25)
delivery_date=models.DateField()
customer=models.ForeignKey(Customer)
design=models.ManyToManyField(Design)
outSource=models.OneToOneField(OutSource)
class Design(models.Model):
dimension=models.IntegerField()
image=models.ImageField(upload_to='images/%Y/%m/%d')
number_of_colors=models.IntegerField()
sides=models.IntegerField(verbose_name='side(s)')
class OutSource(models.Model):
date=models.DateField()
number=models.IntegerField()
description=models.CharField(max_length=100)
code=models.IntegerField()
supplier=models.ForeignKey(Supplier)
Upvotes: 1
Views: 902
Reputation: 2254
You are declaring the class Design
after actually defining the ManyToManyField
relationship. It cannot find the class with name Design
and hence the NameError
.
Declare the class Design
before class Order
and things should work for you.
Upvotes: 5