|
|
@@ -1,6 +1,11 @@
|
|
1
|
1
|
from django.shortcuts import render, redirect
|
|
2
|
2
|
from backend.models import Patient
|
|
3
|
|
-
|
|
|
3
|
+from cms.models import Post
|
|
|
4
|
+from fruit.models import Product
|
|
|
5
|
+from .forms import SearchForm
|
|
|
6
|
+from itertools import chain, tee
|
|
|
7
|
+from operator import attrgetter
|
|
|
8
|
+from django.db.models import Q
|
|
4
|
9
|
# Create your views here.
|
|
5
|
10
|
|
|
6
|
11
|
def index(request):
|
|
|
@@ -39,6 +44,35 @@ def agri_market(request):
|
|
39
|
44
|
pass
|
|
40
|
45
|
|
|
41
|
46
|
|
|
|
47
|
+def stores(request):
|
|
|
48
|
+ top_stores = Post.objects.filter(cat__name="Top Stores", status="publish").order_by("-created_at")
|
|
|
49
|
+ return render(request, "front/stores.html", {'top_stores': top_stores})
|
|
|
50
|
+
|
|
|
51
|
+def search(request):
|
|
|
52
|
+ form = SearchForm(request.GET)
|
|
|
53
|
+
|
|
|
54
|
+ results = None
|
|
|
55
|
+ if form.is_valid():
|
|
|
56
|
+ o = form.save(commit = False)
|
|
|
57
|
+ o.created_by = request.user
|
|
|
58
|
+ o.save()
|
|
|
59
|
+
|
|
|
60
|
+ q = Q()
|
|
|
61
|
+ q2 = Q()
|
|
|
62
|
+ if o.content_cat != None:
|
|
|
63
|
+ q = q & Q(cat = o.content_cat)
|
|
|
64
|
+
|
|
|
65
|
+ if o.product_type != None:
|
|
|
66
|
+ q2 = q2 & Q(product_type = o.product_type)
|
|
|
67
|
+
|
|
|
68
|
+ q = q & ( Q(title__contains = o.q ) | Q(body__contains = o.q))
|
|
|
69
|
+ q2 = q2 & ( Q(name__contains = o.q ) | Q(description__contains = o.q))
|
|
|
70
|
+
|
|
|
71
|
+ r1 = Post.objects.filter(q)
|
|
|
72
|
+ r2 = Product.objects.filter(q2)
|
|
|
73
|
+ results = list(sorted(chain(r1, r2), key = lambda obj: obj.created_at, reverse = True))
|
|
|
74
|
+
|
|
|
75
|
+ return render(request, "front/search.html", {'form': form, 'results': results})
|
|
42
|
76
|
|
|
43
|
77
|
def mystore(requeset):
|
|
44
|
78
|
pass
|