▶️ Watch Entire Django Wednesdays Playlist ✅ Subscribe To My RUclips Channel: bit.ly/35Xo9jD bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN ▶️ Get The Code bit.ly/3sJpeV6
Actually this is my first comment in RUclips. I am a software developer in other languages, so I embarked to learn django, which i have been reading documentation, but when i started following your videos, I can proudly say that you deserve award. Your lecturer to say, is straight forward and on point. Good job.
there are a lot of tutorials in youtube but the secret key to understand a topic is the instructor style. i started to learn basics of django from you and know i started to make some mony from coding and when i get stuck in something i always come back to you videos and i always find the solution. learning from u is alwyas easy and fun thanks man. god bless you
If you want to search across multiple fields in the post/venue model (Like the content or the title), you can do it like this: from django.db.models import Q filtered_posts = Post.objects.filter(Q(content__contains=searched) | Q(title__contains=searched)) The pipe character, '|' means 'OR' so you can search across both the content and the tile at the same time!
I just added a new video to my channel about adding a "smart search" for your Django app. It's a lot more powerful than the Q search I mention in this comment.
At 10:30 in this video venues = Venue.objects.filter(name__contains=searched) provided a case-sensitive search. Looking at the docs, it appears I need to add an "i" before contains to make it case-insensitive, resulting in: venues = Venue.objects.filter(name__icontains=searched). Perhaps this was a change in Django 4?
@8:05 The reason brackets work here is because he is indexing the dictionary through bracket notation, i.e. request.POST['foo']. If you use the get method of a dictionary, THEN you use parentheses, i.e. request.POST.get('foo'). That's why people would see a difference. Both are acceptable.
Thanks for this video I was't sure where to start to add a search function for my django project and with your video I can now just adapt it to suit my needs. Very helpfull thanks.
Thanks a lot, I'm coming from your playlist Create a simple Django blog to add search bar feature. This video helped me a lot to implement it. your style is very easy to follow and less coding Thanks again.
Thanks John for your very helpful videos! I like them very much! If someone has the same problem with the views.py as me: I had to change the line to: searched = request.POST.get('searched') The both solutions shown in the video didn´t work for me.
But what should we do if we want the text we have searched stay in the searched bar after doing the search? In this sample the text disappears after clicking the search button
Hey, thanks for this straightforward video but I want to paginate the search results. Since we checking for searched in the if, the else get executed when you try to go to the next page. So my question is how can we paginate the search results without running into errors or triggering the else statement
Sir, thank you for the videos, you describe everything in perfect detail. But how can we search a name or something else inside of all the tables instead of just one table, in this case Venue. How do I query the entire database, for instance is there a way to change, venues = Venue.objects.filter(name__contains=searched) statement so that users would search the word in the entire database? Thanks again!
Thank you, Sir! Would you please help to query all the records from a specific start date to an end based on the DateTime field? I'm facing an issue. Kindly guide me through!
venues = Venue.objects.filter(name__contains=searched) -- was only showing case sensitive results for me after some searching: venues = Venue.objects.filter(name__icontains=searched) fixed that (note name__icontains was the change)
I keep getting an error if i use filter(id__contains=searched). Any idea how I can solve this? This is the error (1287, "1287: 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead", None). I'm working with a mysql database
Same way, just add another line like this to the views.py function: second_search= Venue.objects.filter(name__contains=searched) change Venue to whatever other model you want to search...then pass that variable to the context dictionary
Did anyone else have trouble getting the two html pages linked??? I've followed this tutorial exactly and when i click the search bar button it doesn't do anything! Any suggestions
@@Codemycom Ok Leave that... API connected Currency Convertor # Connected with an API that provides latest currencies value. def getcurrentlist(): import os os.system('pip install openexchangerate') from openexchangerate import OpenExchangeRates client=OpenExchangeRates(api_key='522e7989e9f64eb1ba21a035674dc275') global A,j k=client.currencies()[0] j=client.latest()[0] try: k.pop('VEF') # VEF has got Old except: pass A=[] for i in k: A.append([k[i],j[i]]) A.sort() getcurrentlist() from tkinter import * from tkinter.ttk import Combobox root=Tk() root.title('Currency Convertor') ComboboxList_Name=[] for i in A: ComboboxList_Name.append(i[0]) def load(e): if currency_Entry.get()=='': currency_Entry.insert(0,'0') x_name=Currency_combobox_1.get() for i in A: if i[0]==x_name: x_value=float(i[1]) break y_name=Currency_combobox_2.get() for i in A: if i[0]==y_name: y_value=float(i[1]) break feeded_value=float(currency_Entry.get()) calc_value=f'{round((y_value*feeded_value)/(x_value),2)}' display.config(text=f'{feeded_value} {x_name} equals {calc_value} {y_name}') Currency_combobox_1=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name) Currency_combobox_1.pack() Currency_combobox_1.set('Indian Rupee') Currency_combobox_1.bind('', load) currency_Entry=Entry(root, font=('Agency FB','30','bold'), borderwidth=0, bg='lightblue') currency_Entry.pack() currency_Entry.insert(0,round(j['INR'],2)) currency_Entry.bind('', load) To_label=Label(root, text='To', font=('Agency FB','30','bold')) To_label.pack() Currency_combobox_2=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name) Currency_combobox_2.pack() Currency_combobox_2.set('United States Dollar') Currency_combobox_2.bind('', load) display=Label(root, text=f'Rs. {round(j["INR"],2)} Indian Rupee equals ${j["USD"]} United States Dollar.', font=('Agency FB','30','bold')) display.pack(pady=30) root.mainloop()
try it and see...why would it return results for a thing that doesn't exist? If I search pancakes, it won't return anything either :-p But, we wouldn't want it to, right?
@@Codemycom I don't think it will. But how to do it. I created a proj where user can asks question and others can answer (like stackoverflow) and others can answer for it. If another user searches searches with related keywords in the question how to return results with related words searched by the user I know this is out of the scope of the project. But please help me out
@@saivarshan8288 really late and you've prbbly got it sorted out already but in case you have't, an immediate solution I can think of is training a searcher with some datasets so it can recognize mistyped words - such as vegan/vegaa/vegad/vegss for vegas, but this can get really complex if you've never used ML (an immediate DS I can think of is a decision tree) before. Then there's the dummy solution of including a list of mistyped versions for each keyword that the user can search by. Given how seemingly common this is, there should be exisiting algos/models that perform similarly, so you can give that a try too
The error message you are receiving indicates the DogRescue table does not contain a name field. Substitute the column name where the search should be looking for "name" (e.g., if you want to search on values in the Behavior field, your filter should be "searchfound = DogRescue.objects.filter(Behavior__icontains =search_list)".
views get the data i can print it in terminal but it doesn't display it in template, tried everything def SearchView(request): if request.method == 'POST': searched = request.POST.get('searched') print(searched) return render(request, 'search/search.html', { searched:'searched' }) else: return render(request, 'search/search.html', {}) you searched for {{ searched }} or {% if searched %} you searched for {{ searched }} {% else %} You didn't search {% endif %}
when i add the {%url 'show_venue' venue.id%} it gives me errors no Reverse for 'show_venue' with arguments '('',)' not found. 1 pattern(s) tried: ['show_venue/(?P[^/]+)$']
▶️ Watch Entire Django Wednesdays Playlist ✅ Subscribe To My RUclips Channel:
bit.ly/35Xo9jD bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
▶️ Get The Code
bit.ly/3sJpeV6
man ur awesome
this is not clickable Read more...
Actually this is my first comment in RUclips. I am a software developer in other languages, so I embarked to learn django, which i have been reading documentation, but when i started following your videos, I can proudly say that you deserve award. Your lecturer to say, is straight forward and on point. Good job.
Thanks! Glad you enjoy the videos!
there are a lot of tutorials in youtube but the secret key to understand a topic is the instructor style. i started to learn basics of django from you and know i started to make some mony from coding and when i get stuck in something i always come back to you videos and i always find the solution. learning from u is alwyas easy and fun thanks man. god bless you
Happy to hear it!
If you want to search across multiple fields in the post/venue model (Like the content or the title), you can do it like this:
from django.db.models import Q
filtered_posts = Post.objects.filter(Q(content__contains=searched) | Q(title__contains=searched))
The pipe character, '|' means 'OR' so you can search across both the content and the tile at the same time!
What is Q here?
@@amangautam1779 stands for query if I'm not mistaken
And if someone needs to search through Foreignkeys for example for events, you would add
Filter(Q(Venue__address__contains= searched)
Thank you a lot!!! I lost like 3 hours to find this info. Your coment helped me.
I just added a new video to my channel about adding a "smart search" for your Django app. It's a lot more powerful than the Q search I mention in this comment.
At 10:30 in this video venues = Venue.objects.filter(name__contains=searched) provided a case-sensitive search. Looking at the docs, it appears I need to add an "i" before contains to make it case-insensitive, resulting in: venues = Venue.objects.filter(name__icontains=searched). Perhaps this was a change in Django 4?
thanks a lot bro, was stuck on that bug the whole day, could u perhaps send a link to that part of the documentation so that i can read and learn more
your teaching skills are cool
@8:05 The reason brackets work here is because he is indexing the dictionary through bracket notation, i.e. request.POST['foo']. If you use the get method of a dictionary, THEN you use parentheses, i.e. request.POST.get('foo'). That's why people would see a difference. Both are acceptable.
I guess I was just tired last night, today I have seen all the lines I forget, and thanks bro five stars for you.
Glad you got it sorted!
If someone have problem like me with printing foreign object to the template, solution is (foreign_object__object_name__icontains=search)
Oh wow, thanks John, was waiting for this video for quite sometime 😅
Hope you enjoyed it!
Love your videos John! I was the 1000th view!
Awesome! Thanks for watching!
your video is very fantastic...... coup de chapeau .... absolument dingue.... thank you very much .🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
Glad you enjoyed it!
At 8:11, you use either request.POST['param'] or request.POST.get('param'). It's parentheses whenever we use a getter.
thanks man, I was struggling
Thanks man later worked for me
Live saver! thanks !
Thanks for this video I was't sure where to start to add a search function for my django project and with your video I can now just adapt it to suit my needs. Very helpfull thanks.
Glad it helped!
Thanks a lot for the best django learning page 🔥
Welcome! Glad you liked it!
Eagerly waiting for your videos sir...
Thanks for watching!
Thanks a lot, I'm coming from your playlist Create a simple Django blog to add search bar feature. This video helped me a lot to implement it. your style is very easy to follow and less coding
Thanks again.
Glad to hear you're enjoying the videos!
Thanks for great tutorials John - For the "search" field, would you advise to "Clean" it first before using it in the view to avoid XSS?
I suppose so...
Thank you so much...I had been searching for such a straight forward tutorial...I'm glad I found one..🤗thanks a bunch..
Glad you liked it!
GOOD ONE MY FRIENDS
thanks
Thanks John for your very helpful videos! I like them very much!
If someone has the same problem with the views.py as me: I had to change the line to: searched = request.POST.get('searched')
The both solutions shown in the video didn´t work for me.
So many thanks... it's really amazing how easy you make it look like. Thank you :)
Happy to help!
BEST TUTORIAL JESUS!!!!!
Ha thanks
realy best course for django search
thanks!
Is there a way to prevent the 'confirm form resubmission' popup from the search bar form only?
But what should we do if we want the text we have searched stay in the searched bar after doing the search? In this sample the text disappears after clicking the search button
so helpful tyyy!!!
Is that also workable in images in model?
you are amazing for sure i'll buy the full package :)
Awesome
Thank you! very ...very so much. you are saved me...rrrrss
Excellent Sir
Thanks
Thanks for video! but I get "" that , how can i fix this?
rewatch the video and try to figure out what you did differently
u are the best ♥
thanks!
Thank you man!
Welcome!
Thanks, John. ♥️
Thanks for watching!
Great video!
Thanks!
Great tutorial
Thanks!
Hey, thanks for this straightforward video but I want to paginate the search results. Since we checking for searched in the if, the else get executed when you try to go to the next page.
So my question is how can we paginate the search results without running into errors or triggering the else statement
Good question, I'll have to do a video on it
Sir, thank you for the videos, you describe everything in perfect detail. But how can we search a name or something else inside of all the tables instead of just one table, in this case Venue. How do I query the entire database, for instance is there a way to change, venues = Venue.objects.filter(name__contains=searched) statement so that users would search the word in the entire database? Thanks again!
Sure, pretty sure I have videos on that sort of thing
Thank you, Sir! Would you please help to query all the records from a specific start date to an end based on the DateTime field? I'm facing an issue. Kindly guide me through!
Interesting idea
Awesome!!
Thanks!
venues = Venue.objects.filter(name__contains=searched) -- was only showing case sensitive results for me
after some searching: venues = Venue.objects.filter(name__icontains=searched) fixed that (note name__icontains was the change)
I keep getting an error if i use filter(id__contains=searched). Any idea how I can solve this? This is the error (1287, "1287: 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead", None). I'm working with a mysql database
Hi, have you found any solution to this issue by any chance, I have the same issue...
Nice video!
Thanks!
Great tutorial as always. Can you do a multiple-column search Tutorial? Such as Excel filter when you can search for several columns.
Not a bad idea
i get a error like this: Field 'id' expected a number but got 'my search' how can i fix this?
what did you do differently from the video?
Thank u!!💗
welcome
Next for flask💙🤩
Flask fridays are awesome :-)
How to create one search bar for multiple fields. Like you can search users as well as Venues from one searchbar ?
Same way, just add another line like this to the views.py function:
second_search= Venue.objects.filter(name__contains=searched)
change Venue to whatever other model you want to search...then pass that variable to the context dictionary
@@Codemycom Good idea but,
Don't you think it sounds like a temporary solution !?
@@darshantank554 In no way whatsoever is that a temporary solution.
Did anyone else have trouble getting the two html pages linked??? I've followed this tutorial exactly and when i click the search bar button it doesn't do anything! Any suggestions
Then you didn't follow the tutorial exactly. Recheck your code :-)
Sir John, what is your perception about *WhiteHatJr*
I don't know what that is
@@Codemycom
Ok Leave that...
API connected Currency Convertor
# Connected with an API that provides latest currencies value.
def getcurrentlist():
import os
os.system('pip install openexchangerate')
from openexchangerate import OpenExchangeRates
client=OpenExchangeRates(api_key='522e7989e9f64eb1ba21a035674dc275')
global A,j
k=client.currencies()[0]
j=client.latest()[0]
try:
k.pop('VEF') # VEF has got Old
except:
pass
A=[]
for i in k:
A.append([k[i],j[i]])
A.sort()
getcurrentlist()
from tkinter import *
from tkinter.ttk import Combobox
root=Tk()
root.title('Currency Convertor')
ComboboxList_Name=[]
for i in A:
ComboboxList_Name.append(i[0])
def load(e):
if currency_Entry.get()=='':
currency_Entry.insert(0,'0')
x_name=Currency_combobox_1.get()
for i in A:
if i[0]==x_name:
x_value=float(i[1])
break
y_name=Currency_combobox_2.get()
for i in A:
if i[0]==y_name:
y_value=float(i[1])
break
feeded_value=float(currency_Entry.get())
calc_value=f'{round((y_value*feeded_value)/(x_value),2)}'
display.config(text=f'{feeded_value} {x_name}
equals
{calc_value} {y_name}')
Currency_combobox_1=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name)
Currency_combobox_1.pack()
Currency_combobox_1.set('Indian Rupee')
Currency_combobox_1.bind('', load)
currency_Entry=Entry(root, font=('Agency FB','30','bold'), borderwidth=0, bg='lightblue')
currency_Entry.pack()
currency_Entry.insert(0,round(j['INR'],2))
currency_Entry.bind('', load)
To_label=Label(root, text='To', font=('Agency FB','30','bold'))
To_label.pack()
Currency_combobox_2=Combobox(root, font=('Agency FB','30','bold'), value=ComboboxList_Name)
Currency_combobox_2.pack()
Currency_combobox_2.set('United States Dollar')
Currency_combobox_2.bind('', load)
display=Label(root, text=f'Rs. {round(j["INR"],2)} Indian Rupee
equals
${j["USD"]} United States Dollar.', font=('Agency FB','30','bold'))
display.pack(pady=30)
root.mainloop()
If we search vegan(wrong spelling) instead of vegas. Will it return results? If not how to do it.
try it and see...why would it return results for a thing that doesn't exist? If I search pancakes, it won't return anything either :-p But, we wouldn't want it to, right?
@@Codemycom I am asking this commonly and not in this proj specifically. I am asking If the user mistypes will it return results related to the search
@@Codemycom I don't think it will. But how to do it.
I created a proj where user can asks question and others can answer (like stackoverflow) and others can answer for it. If another user searches searches with related keywords in the question how to return results with related words searched by the user
I know this is out of the scope of the project. But please help me out
@@saivarshan8288 really late and you've prbbly got it sorted out already but in case you have't, an immediate solution I can think of is training a searcher with some datasets so it can recognize mistyped words - such as vegan/vegaa/vegad/vegss for vegas, but this can get really complex if you've never used ML (an immediate DS I can think of is a decision tree) before.
Then there's the dummy solution of including a list of mistyped versions for each keyword that the user can search by.
Given how seemingly common this is, there should be exisiting algos/models that perform similarly, so you can give that a try too
I have a case sensitive for characters problem what to do !!!! 😭
Sorry I don't know what that is...
try "icontains" instead of "contains"
Thank you so much
Welcome!
Hi, is this code available to look at?
Of course, it's always linked in the pinned comment.
Sir I am following all your videos but request to share ne the roles and permission access to templates in decoratorsq
No idea what you're talking about. There are no such things to share
What data inside the base. Html???
just what the video shows...? What's the confusion?
def searchlist(request):
if request.method == "POST":
search_list= request.POST['search_list']
searchfound = DogRescue.objects.filter(name__icontains= search_list)
return render(request,'search.html',{"search_list": search_list,
"searchfound": searchfound })
else:
return render(request,'search.html',{})
Cannot resolve keyword 'name' into field. Choices are: Behavior, Characteristics, Hero, Hero_id, Location, Message, id .H ow to do please help? Thankyou
The error message you are receiving indicates the DogRescue table does not contain a name field. Substitute the column name where the search should be looking for "name" (e.g., if you want to search on values in the Behavior field, your filter should be "searchfound = DogRescue.objects.filter(Behavior__icontains =search_list)".
In your video description u made a typo error.
It should be Venue.objects.filter(name__contains=searched)
Not name__containts as you wrote
Ha thanks
Can you please do a video of searching image
How can I search by address as well?
just filter by address instead of name in the query.
Ty
Welcome!
i got case error while searching.
how is that possible? :-p
the next playlist about this is discord.py bot maker so can u do it pls
No, sorry
hello :)
Hello
I LOVE YOUR WAY OF TEACHING AND YOUR INTRO
@@partialcoder6386 Thanks!
views get the data i can print it in terminal but it doesn't display it in template, tried everything
def SearchView(request):
if request.method == 'POST':
searched = request.POST.get('searched')
print(searched)
return render(request, 'search/search.html', {
searched:'searched'
})
else:
return render(request, 'search/search.html', {})
you searched for {{ searched }}
or
{% if searched %}
you searched for {{ searched }}
{% else %}
You didn't search
{% endif %}
where is the source code ):
In the pinned comment...just where I say it is in the video :-p
What about typo's and stuff. Sqlite3 can't deal with typo's and stuff. I was expecting something else. DISAPPOINTED !
lol what in the world are you talking about?
breaking bad
ha
when i add the {%url 'show_venue' venue.id%} it gives me errors no Reverse for 'show_venue' with arguments '('',)' not found. 1 pattern(s) tried: ['show_venue/(?P[^/]+)$']