У меня есть модель поставщиков из модуля покупки, и я просто импортирую ее в свой модуль инвентаризации.
Вот мой поставщик модели модуля покупки
from django.db import models
from django_countries.fields import CountryField
from Inventory.models import productDetails,products
from Accounts.models import elementaryhead
from datetime import datetime
import base64
# Create your models here.
class suppliers(models.Model):
companyName=models.CharField(max_length=30,verbose_name='Company Name')
companyAddress=models.CharField(max_length=50,verbose_name='Company Address')
city=models.CharField(max_length=20,verbose_name='City')
region=models.CharField(max_length=20,verbose_name='Region')
country=CountryField()
postalCode=models.IntegerField(verbose_name='Postal Code')
companyPhone=models.IntegerField(verbose_name="Company Phone")
companyFax=models.IntegerField(verbose_name='Company Fax')
elementaryID=models.ForeignKey(elementaryhead,on_delete=models.CASCADE,default=None,null=True,verbose_name='Elementary head',editable=False)
buyer=models.BooleanField(default=None,verbose_name='Is Buyer',editable=False)
supplier=models.BooleanField(default=None,verbose_name='Is Supplier',editable=False)
website=models.URLField(default=None,verbose_name='Website')
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
accountID = elementaryhead.objects.order_by('id').last().id + 1
code = '00003-000010-0000' + str(accountID)
subhead=10
elementaryhead.objects.create(subhead_id=subhead, name=self.companyName,fixed=False, codes=code, right=True)
accountID = elementaryhead.objects.order_by('id').last().id + 1
subhead=11
code = '00003-000011-0000' + str(accountID)
elementaryhead.objects.create(subhead_id=subhead, name=self.companyName+'(I/TAX PAYABLE)',fixed=False, codes=code, right=True)
accountID = elementaryhead.objects.order_by('id').last().id + 1
subhead=15
code = '00003-000015-0000' + str(accountID)
elementaryhead.objects.create(subhead_id=subhead, name=self.companyName+'(GST W/HELD PAYABLE)',fixed=False, codes=code, right=True)
self.supplier = True
self.buyer = False
super(suppliers,self).save()
def __str__(self):
return self.companyName
Вот моя модель модуля инвентаризации InventoryIn
from django.db import models
from datetime import datetime
from Purchase.models import suppliers,contracts
class inventoryIn(models.Model):
supplierID=models.ForeignKey(suppliers,on_delete=models.CASCADE,verbose_name='Supplier')
productID=models.ForeignKey(products,on_delete=models.CASCADE)
purchaseContractID=models.ForeignKey(contracts,on_delete=models.CASCADE)
unitsIn=models.IntegerField(verbose_name='Units In')
doID=models.IntegerField(verbose_name='Do ID')
doImage=models.ImageField(upload_to='/assets/image')
invoiceID=models.IntegerField(verbose_name='Invoice ID')
invoiceImage=models.ImageField(upload_to='/assets/image')
agingDate=models.DateField()
dateOfEntry=models.DateField(default=datetime.now())
def __str__(self):
return self.supplierID
Я в основном добавляю два ForeignKey (supplierID, purchaseContractID), который относится к модулю покупки. Но он выдает ошибку, что
ImportError: невозможно импортировать имя «поставщики», и я пытался импортировать его в класс модели InventoryIn.Но это не сработало для меня.