很难将下面的 SQL 语句转换为 Django ORM。任何帮助深表感谢。SELECT a.state, a.city, a.postcode, b.rate_authority, b.rate, b.rate_descr FROM fileload_taxratemodel AS a INNER JOIN fileload_taxrateresponsemodel AS b ON b.jurs_id_id = a.id ORDER BY state ASC Django 模型:尝试根据外键从两个模型中提取字段。class TaxRateModel(models.Model):company_code = models.CharField(max_length = 10)document_date = models.DateTimeField()country = models.CharField(max_length = 30, default = "US")province = models.CharField(max_length = 100, null= True,blank= True)state = models.CharField(max_length = 100)county = models.CharField(max_length = 100,blank=True, null=True)city = models.CharField(max_length = 100,blank=True, null=True)district = models.CharField(max_length = 100, blank=True, null=True)postcode = models.CharField(max_length = 5, blank=True, null=True)rate_code = models.CharField(max_length = 30,default = "ST")Django 2 模型:class TaxRateResponseModel(models.Model):jurs_id = models.ForeignKey(TaxRateModel,on_delete=models.CASCADE,related_name='rates')rate_authority = models.CharField(max_length = 100, blank=True, null=True, default='')rate_descr = models.CharField(max_length = 100, blank=True, null=True, default ='')rate = models.DecimalField(max_digits= 10, decimal_places=5)
添加回答
举报
0/150
提交
取消