【问题标题】:I want to Compare two tables Column (Table1 - Balance_sheet, Table2- Account_list) (Column-split,column-account) and get the similar data in django我想比较两个表 Column (Table1 - Balance_sheet, Table2- Account_list) (Column-split,column-account) 并在 django 中获取相似的数据
【发布时间】:2022-08-03 21:31:58
【问题描述】:

模型.py:

 class Balance_Sheet(models.Model): #name of the table

    # date = models.DateField() # Name of the column
    # transaction_type = models.CharField(max_length=100,blank=False)
    # num = models.IntegerField()
    name = models.CharField(max_length=100,blank=True)
    # description = models.CharField(max_length=100,blank=True)
    split = models.CharField(max_length=100,blank=False)
   

    # class Meta:
    #     abstract : True
    
class Account_List(models.Model):
    account = models.CharField(max_length=100,blank=True,null=True)
    type = models.CharField(max_length=100,blank=True, null=True)
    split =models.ForeignKey(Balance_Sheet,null=False, default=True,on_delete=models.CASCADE)

    def __str__(self):
        return \'Account : {0} Type : {1} \'.format(self.account,self.type)

视图.py:

def DisplayUVL(request):

    # Excel page changes
    Ven_list = Balance_Sheet.objects.filter(account_list__isnull=True).values_list(\'split\', flat=True)
    print(\"SQL Query:\",Ven_list.query)
    context = {
        \'items\': Ven_list
        # \'header\': \'Vendor List\'
       
    }
    return render(request, \'services2.html\', context)

    标签: python django django-models django-views


    【解决方案1】:

    select_relations 可能有助于您比较两个表格信息并获得共同的信息。 select_relations 是原生方式。

    如果您使用的是 postgresql,则可以直接使用内部连接 ​​sql 查询。

    这个线程可能对你有帮助

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 2023-01-25
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多