首页 > 解决方案 > 使用过滤器搜索公司出现错误,获取类型错误只能将str(Not nonetype)连接到views.py中的str在线compsearchobj

问题描述

我使用这个定义来定义搜索和过滤页面,使用一个连接和保存的数据库。我已经为此添加了 views.py 和 models.py 代码。

视图.py

def multiplesearchcomp(request):
    if request.method=="POST":
        citycode=request.POST.get("citycode")
        statecode=request.POST.get("statecode")
        countrycode=request.POST.get("countrycode")
        revenue=request.POST.get("revenue")
        noofemployees=request.POST.get("noofemployees")
        domaincode=request.POST.get("domain_id")
        compsearchobj=DisplayCompanyDomain.objects.raw('select * from enquire_automation_app_displaycompanydomain where citycode="'+citycode+'" and statecode="'+statecode+'" and countrycode="'+countrycode+'" and domain_id="'+domaincode+'" and revenue="'+revenue+'" and noofemployees="'+noofemployees+'"')
        return render(request,'filtercompany.html',{"DisplayCompanyDomain":compsearchobj,"countries": Country_master.objects.all(), 'states': State_master.objects.all(), "cities": City_master.objects.all(), "domains": Domain_master.objects.all()})
    else:
        compobj=DisplayCompanyDomain.objects.raw('select * from enquire_automation_app_displaycompanydomain')
        return render(request,'filtercompany.html',{"DisplayCompanyDomain":compobj, "countries": Country_master.objects.all(), 'states': State_master.objects.all(), "cities": City_master.objects.all(), "domains": Domain_master.objects.all()})

模型.py

class DisplayCompanyDomain(models.Model):
    companyname = models.CharField(max_length=100)
    address = models.CharField(max_length=200)
    citycode = models.CharField(max_length=20)
    statecode = models.CharField(max_length=20)
    countrycode = models.CharField(max_length=20)
    foundedin = models.CharField(max_length=20)
    revenue = models.CharField(max_length=100)
    noofemployees = models.CharField(max_length=20)
    domesticprojects = models.IntegerField(default=0)
    globalprojects = models.IntegerField(default=0)
    website = models.CharField(max_length=50)
    domain_id=models.CharField(max_length=20)
    no_of_projects=models.IntegerField()

标签: pythondjangodjango-modelsdjango-viewsdjango-forms

解决方案


推荐阅读