-
**basically, i want to develop a website like pc part picker in Django I want to select a motherboard on the basis of socket and chipset supported by CPU problem is it can fetch all motherboard I want to select only those motherboard having the same socket and chipset stored in session problem in build_mobo
**here are models**** class vendor(models.Model): vendor_name=models.CharField(max_length=250) def __str__(self): return self.vendor_name class socket(models.Model): socket_type = models.CharField(max_length=250) def __str__(self): return self.socket_type class chipset(models.Model): cpu_chipset=models.CharField(max_length=250) def __str__(self): return self.cpu_chipset class CPU(models.Model): image = models.ImageField(upload_to="uploads/product/") vendor = models.ForeignKey(vendor , on_delete=models.CASCADE) cpu_name=models.CharField(max_length=250) cpu_price = models.CharField(max_length=250 , default="") generation = models.CharField(max_length=250) socket= models.ForeignKey(socket ,on_delete=models.CASCADE) chipset =models.ManyToManyField(chipset) def __str__(self): return self.cpu_name class Motherboard(models.Model): mobo_name= models.CharField(max_length=250) chipset = models.ForeignKey(chipset , on_delete=models.CASCADE) socket = models.ForeignKey(socket ,on_delete=models.CASCADE) vendor = models.ForeignKey(vendor , on_delete=models.CASCADE) DIMM_sockets = models.CharField(max_length=250 ,default="single", choices=(("dual","dual"), ("single","single"),("4","4"))) Supported_ram= models.CharField(max_length=250 ,default="ddr3", choices=(("ddr3","ddr3"), ("ddr4","ddr4"))) Onboard_Graphics= models.CharField(max_length=250,blank=True,null=True) Expensions_socket_version= models.CharField(max_length=250 ,default="version 1", choices=(("version 1","version 1"), ("version 2","version 2"), ("version 3","version 3"))) Audio =models.CharField(max_length=250,blank=True,null=True) LAN =models.CharField(max_length=250 ,blank=True,null=True) Storage_Interface =models.TextField(max_length=250 ,blank=True,null=True) USB =models.TextField(max_length=250 ,blank=True,null=True) def __str__(self): return self.mobo_name
my view is :
def build_cpu(request): data = CPU.objects.all() d = {'data1': data} return render(request, 'build/cpu.html', d) def build_home(request): if request.method == 'POST': cpu_id = request.POST['cid'] cpu_nam = request.POST['nammm'] dat = CPU.objects.get(cpu_name=cpu_nam) chip = dat.chipset.all() request.session['socket'] = dat.socket.socket_type request.session['cpuname'] = dat.cpu_name li = [] for d in chip: li.append(d.cpu_chipset) request.session['listt'] = li return render(request, 'shop/build.html') def build_mobo(request): data = Motherboard.objects.all() request.session.get('socket') print("xxxxxxxxxxxxxxxxx") x = request.session['listt'] y = request.session.get('socket') print(x) print(y) xxi = Motherboard.objects.filter(Q(socket__socket_type=y) & Q(chipset__cpu_chipset__icontains=x)) print(xxi.query) d = {'data1': data} return render(request, 'build/mobo.html', d)
vendredi 30 avril 2021
Hello hope all of you are well i want to select motherboard on the basis of socket and chipset supported by CPU but it can fetch all motherboard
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire