Hi! I used your filter scheme in an application, but I'm having trouble paginating the Results. Can you help me? Thank you for your videos, your channel is excellent and has great content!
sir everything is working perfecting up to this video but the category filter not., even we are getting the value from drop down to back end ,but it keep saying the field is empty or other words its not filtering
Thank you for the fantastic tutorial. All was working fine, but if I open the site new without parameters an error occurs: "Cannot use None as a query value". Do you have a solution for that problem? Thanks
When you open a new site, the view runs the "request.GET.get()" which returns None because no form was submitted. one way to fix this is to create another view for the new site: views.py class PostListView(ListView): # home view that contains the search form model = Post template_name = 'erf24/home.html' # /_.html context_object_name = 'posts' # default >> erf24/post_list.html ordering = ['-date_posted'] paginate_by = 3 def is_valid_queryparam(param): return param != '' and param is not None class SearchView(ListView): # home view that contains search results # model = Post template_name = 'erf24/home.html' # /_.html context_object_name = 'posts' # default >> erf24/post_list.html ordering = ['-date_posted'] paginate_by = 3 def get_queryset(self): # new key = self.request.GET.get('key') minp = self.request.GET.get('min') maxp = self.request.GET.get('max') mind = self.request.GET.get('start') maxd = self.request.GET.get('end')
if is_valid_queryparam(key): obj = Post.objects.filter(Q(content__icontains=key) | Q(location__icontains=key)).distinct() if is_valid_queryparam(minp): obj = Post.objects.filter(Q(price__gte=minp)).distinct() if is_valid_queryparam(maxp): obj = Post.objects.filter(Q(price__lte=maxp)).distinct() if is_valid_queryparam(mind): obj = Post.objects.filter(Q(date_posted__gte=mind)).distinct() if is_valid_queryparam(maxd): obj = Post.objects.filter(Q(date_posted__lte=maxd)).distinct() return obj urls.py urlpatterns = [ path('', PostListView.as_view(), name='home'), path('search/', SearchView.as_view(), name='home-search'), ]
sir i m your student i have problem i want to develop youtube like ads on video. how to embed run time ads in video , for example banner ads skip ads . thank you sir
You are my fave Django TH-camr. Thanks!
awesome explanation sir
It's a high quality content. Thank you!
Muito top, seu tutorial me ajudou a resolver um problema de 1 mês show demais. Ganhou 1 inscrito.
Thank you so much!
Use "selected disable" for the category
Thanks, it helps me
Thank you so much! god bless you
awesome video!!
Nice!
Nice! Thanks.
what about just refresh table content after click the search button?just like ajax request
Hi! I used your filter scheme in an application, but I'm having trouble paginating the Results. Can you help me?
Thank you for your videos, your channel is excellent and has great content!
sir everything is working perfecting up to this video but the category filter not., even we are getting the value from drop down to back end ,but it keep saying the field is empty or other words its not filtering
thanks alot man
can we use ajax here?
Bro after this series do Django with angular 😍
Reviewed and not reviewed should be excluyent options but like this the user can select both and search
Thank you for the fantastic tutorial.
All was working fine, but if I open the site new without parameters an error occurs: "Cannot use None as a query value".
Do you have a solution for that problem? Thanks
When you open a new site, the view runs the "request.GET.get()" which returns None because no form was submitted.
one way to fix this is to create another view for the new site:
views.py
class PostListView(ListView):
# home view that contains the search form
model = Post
template_name = 'erf24/home.html' # /_.html
context_object_name = 'posts' # default >> erf24/post_list.html
ordering = ['-date_posted']
paginate_by = 3
def is_valid_queryparam(param):
return param != '' and param is not None
class SearchView(ListView):
# home view that contains search results
# model = Post
template_name = 'erf24/home.html' # /_.html
context_object_name = 'posts' # default >> erf24/post_list.html
ordering = ['-date_posted']
paginate_by = 3
def get_queryset(self): # new
key = self.request.GET.get('key')
minp = self.request.GET.get('min')
maxp = self.request.GET.get('max')
mind = self.request.GET.get('start')
maxd = self.request.GET.get('end')
if is_valid_queryparam(key):
obj = Post.objects.filter(Q(content__icontains=key) | Q(location__icontains=key)).distinct()
if is_valid_queryparam(minp):
obj = Post.objects.filter(Q(price__gte=minp)).distinct()
if is_valid_queryparam(maxp):
obj = Post.objects.filter(Q(price__lte=maxp)).distinct()
if is_valid_queryparam(mind):
obj = Post.objects.filter(Q(date_posted__gte=mind)).distinct()
if is_valid_queryparam(maxd):
obj = Post.objects.filter(Q(date_posted__lte=maxd)).distinct()
return obj
urls.py
urlpatterns = [
path('', PostListView.as_view(), name='home'),
path('search/', SearchView.as_view(), name='home-search'),
]
sir i m your student i have problem i want to develop youtube like ads on video.
how to embed run time ads in video ,
for example banner ads skip ads .
thank you sir
in django