Django模型
class Product(models.Model):
product_name = models.CharField(max_length=50)
category = models.CharField(max_length=50)
desc = models.CharField(max_length=120)
company_name = models.CharField(max_length=50, default=None)
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
def __unicode__(self):
return self.product_name
class ProductDetails(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
batch = models.CharField(max_length=50)
quantity = models.IntegerField()
cost = models.FloatField(null=True, blank=True, default=None)
mfg = models.DateTimeField()
exp = models.DateTimeField()
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
def __unicode__(self):
return self.batch
class product_barcode(models.Model):
batch = models.ForeignKey(ProductDetails, on_delete=models.CASCADE)
barcode = models.BigIntegerField()
flag = models.IntegerField()
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
def __unicode__(self):
return self.barcode
我想计算company_name生成的条形码数量
我尝试了一些像
这样的代码w=Product.objects.all().filter(company_name="company name")
print "w>>>",w
pid = []
for Pdata in w:
pid.append(Pdata.id)
print "pid>>>",pid
在这里,我找到属于特定公司的产品名称ID,但之后我想查找属于产品ID的批次代码(在ProductDetails),之后我需要计算所有属于批次代码的条形码。< / p> 用简单的话说
批次代码,其中产品= [&#39;产品1&#39;,&#39;产品2&#39;,&#39;产品3&#39;]
计算条形码的批次代码[&#39; bxyz&#39;,&#39; b2xyz&#39;,&#39; b3xyz&#39;] [&#39; b1xyz&#39;,& #39; b4xyz&#39;&#39; b3xyz&#39;] [&#39; b9xyz&#39;&#39; b6xyz&#39;&#39; b3xyz&#39;]
< / LI> 醇>答案 0 :(得分:0)
我希望,我很清楚你想做什么,比如:
def exe(self):
browser = webdriver.Firefox()
wait = WebDriverWait(browser, 15)
yesterday = date.today() - timedelta(1)
browser.get("https://ssp.vertamedia.com")
try:
userElement = wait.until(EC.visibility_of_element_located((By.ID,'textfield-1020-inputEl')))
userElement.send_keys(self.cred.pop('User'))
time.sleep(# insert seconds)
wait.until(EC.visibility_of_element_located((By.ID,'button-1021-btnInnerEl'))).click()
passElement = wait.until(EC.visibility_of_element_located((By.ID, 'textfield-1027-inputEl')))
passElement.send_keys(self.cred.pop('Password'))
time.sleep(# insert seconds5)
wait.until(EC.visibility_of_element_located((By.ID,'button-1028'))).click()
except TimeoutException:
self.cred['Impression'] = "Login error"
self.cred['Revenue'] = "Login error"
self.cred['Date'] = yesterday.strftime('%m%d%y')
这应该返回公司名称等于&#39;公司名称&#39;的所有产品的条形码数量。
两个下划线用于连接表,例如在SQL中使用JOIN。根据{{3}},您应该更改条形码类的名称(count = product_barcode.objects.filter(batch__product__company_name='company name').count()
)。最好从未来开始。