Last active
July 13, 2022 01:17
-
-
Save Abdurahman-hassan/ab9c0bd35769d86e7090875f00f3b214 to your computer and use it in GitHub Desktop.
queryset in django, one context that contains a different cases of searches in view file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .models import Product | |
# Create your views here. | |
# pricee = {"price1": "50", "product1": "car"} | |
class SearchIn: | |
def product(request): | |
return render(request, "products/product.html") | |
def products(request): | |
f = Product.objects.all() | |
filterd_pro = f.filter(price=4000) | |
return render(request, "products/products.html", | |
{'prodcs': Product.objects.all(), 'single_pro': Product.objects.get(price=50000), | |
'filterd_products': filterd_pro, 'ordered_products': Product.objects.all().order_by('name'), | |
'excluded_products': Product.objects.all().exclude(price=4000), | |
'exact_filter': Product.objects.all().filter(name__exact='macbook pro'), | |
'filter_in': Product.objects.all().filter(price__in=[3000, 4000, 50000]), | |
'filter_range': Product.objects.filter(price__range=(1000, 4000))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment