Nasrullah
Sure
Thanks a lot, as soon as I reach to my laptop I'll send you what I did okay?
sanaz
Hello friends I have a question for those who work with Django and are familiar with full-text search in PostgreSQL. def filter_by_search(self, queryset, name, value):     query_input = SearchQuery(value)     search_vector = SearchVector('categoryname', 'name', 'tagsname')     trigram_similarity = TrigramSimilarity('name', value)     search_rank = SearchRank(search_vector, query_input)     results = queryset.annotate(         trigram_similarity=trigram_similarity,         rank=search_rank).filter(trigram_similarity__gt=0.1).order_by('-rank')     return results This is my search code.  As you can see, I only used the search vector in the search rank, which basically means that the rank field only stores a number during annotation.  Now, the issue is that every time I search, it returns the same product or record twice, meaning I get duplicate products in the output. But when I manipulate the search vector here and keep only one field (name), it returns just one of that product or record and works correctly.  It doesn't matter if I add the tags or category name; even if I have two fields instead of three, the output still becomes duplicated for each record.  For example, when I search for "t-shirt," only one exists, but it returns two.  What's the issue? Where is my problem? And how is the search vector related to filtering and annotation here since it is only used in the search rank?
chowmin
Hello friends I have a question for those who work with Django and are familiar with full-text search in PostgreSQL. def filter_by_search(self, queryset, name, value):     query_input = SearchQuery(value)     search_vector = SearchVector('categoryname', 'name', 'tagsname')     trigram_similarity = TrigramSimilarity('name', value)     search_rank = SearchRank(search_vector, query_input)     results = queryset.annotate(         trigram_similarity=trigram_similarity,         rank=search_rank).filter(trigram_similarity__gt=0.1).order_by('-rank')     return results This is my search code.  As you can see, I only used the search vector in the search rank, which basically means that the rank field only stores a number during annotation.  Now, the issue is that every time I search, it returns the same product or record twice, meaning I get duplicate products in the output. But when I manipulate the search vector here and keep only one field (name), it returns just one of that product or record and works correctly.  It doesn't matter if I add the tags or category name; even if I have two fields instead of three, the output still becomes duplicated for each record.  For example, when I search for "t-shirt," only one exists, but it returns two.  What's the issue? Where is my problem? And how is the search vector related to filtering and annotation here since it is only used in the search rank?
Instead of passing multiple fields as separate arguments, combine them into a single,Your issue arises because SearchVector treats each field separately when passed as multiple arguments. Merging them using + and applying .distinct() will fix the duplicate results.
chowmin
search_vector = ( SearchVector('categoryname', weight='A') + SearchVector('name', weight='B') + SearchVector('tagsname', weight='C') )
sanaz
Instead of passing multiple fields as separate arguments, combine them into a single,Your issue arises because SearchVector treats each field separately when passed as multiple arguments. Merging them using + and applying .distinct() will fix the duplicate results.
Thank you very much for your explanation. I just don't understand one thing: what is the connection between vector search and annotation? Because I only used search rank in the annotation; how does vector search affect the result when rank only stores a number? Also, could you explain the vector search issue more? Why does it return two results? And if I do what you suggested, won't this happen anymore? I mean, is there a solution besides using the function to remove duplicates?
𝚂 𝙷 𝙰 𝙼 𝙼 𝙰 𝚂
def loginn(request): if request.method == 'POST': unm = request.POST.get('unm') pwd = request.POST.get('pwd') myuser = authenticate(request ,username=unm,password=pwd) if myuser is not None: login(request,myuser) print("Login Success") return HttpResponse("Login Success") else: print("Login Failed") return HttpResponse("Wrong credentials") return render(request,'login.html') myuser is returning None
𝚂 𝙷 𝙰 𝙼 𝙼 𝙰 𝚂
Please share more dertails
got the solution. i was using this way => my_user = User(username=unm,password=pwd,email=email) my_user.save()
~
Hello everyone, is there a library that can block an account if on some attempt at unsuccessful login block the account
Ibrohim
Hello, I have a database, postgres and sqlite, and in my opinion when postgres doesn’t work, should be work sqlite DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': env.str('PG_DATABASE', default='postgres'), 'USER': env.str('PG_USER', default='postgres'), 'PASSWORD': env.str('PG_PASSWORD', default='postgres'), 'HOST': env.str('DB_HOST', default='db'), 'PORT': env.int('DB_PORT', default=5432), }, ‘extra’: { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } Can someone explain why it doesn’t work?
Ibrohim
it doesn't work that way... what are you basing your opinion on? if you want DB redundancy, you should configure it at DBMS layer, Django's DB configuration is not for that
My opinion based on one YouTube Tutorial, which shows this move, he explain it terse, when default doesn’t work, will work next
Pablo
that's why you shouldn't use YouTube to "learn" things
How so? YouTube is a great resource for learning Just that not all videos are great but it’s a good resource for learning quick
cj
How so? YouTube is a great resource for learning Just that not all videos are great but it’s a good resource for learning quick
it's no, it's good to watch videos of kittens and listen to music, if you want to learn things, use official documentation or a well rated book
Pablo
it's no, it's good to watch videos of kittens and listen to music, if you want to learn things, use official documentation or a well rated book
That’s true but YouTube is indeed a great place for learning. Because it doesn’t work for you does not mean it will not work for others
Pablo
I have learnt lots from there. Documentation is great don’t get me wrong but YouTube is also a good place to learn
Charly
How so? YouTube is a great resource for learning Just that not all videos are great but it’s a good resource for learning quick
They key point is "quick", because it is clearly slower to listen than reading and that makes most of videos just showing superficial information
Pablo
They key point is "quick", because it is clearly slower to listen than reading and that makes most of videos just showing superficial information
Yes but discrediting YouTube as a good learning place isn’t good. A lot of success stories have come from there. I believe one should always refer to official docs but that doesn’t mean watching a video of somebody explaining the thing is bad either
Pablo
You can get away with not using YouTube as a source. The same does not work for official documentation.
I am not saying get rid of documentation bro. I stated that developers should definitely refer to docs first but learning from YouTube isn’t bad
Pablo
Because let’s face it, how many people here haven’t watched a “tutorial” on Django here on YouTube?
Pablo
Probably more than you'd think.
Lmao yeah sure bro, you have never in your life searched up a YouTube video on how a certain tech topic works. Anyway, Doesn’t make YouTube a bad learning source
clouded
I am not saying get rid of documentation bro. I stated that developers should definitely refer to docs first but learning from YouTube isn’t bad
Learning from YouTube may be helpful. And it may be gruesome. Official documentation rarely is unhelpful.
clouded
Lmao yeah sure bro, you have never in your life searched up a YouTube video on how a certain tech topic works. Anyway, Doesn’t make YouTube a bad learning source
If it doesn't work for you that I haven't watched YouTube videos of Django, you expand the scope to almost anything.
clouded
Yup
Let's leave it at that.
cj
That’s true but YouTube is indeed a great place for learning. Because it doesn’t work for you does not mean it will not work for others
I never said it doesn't work for me, because I don't use YouTube to learn things, YouTube is not for that
Pablo
I never said it doesn't work for me, because I don't use YouTube to learn things, YouTube is not for that
Yes you don’t use YouTube to learn but that doesn’t stop other people from using it to learn does it?
cj
Yes you don’t use YouTube to learn but that doesn’t stop other people from using it to learn does it?
and you see those people that use YouTube to learn come here asking why the things they "learn" on YouTube don't work ¯\_(ツ)_/¯
Pablo
I've never searched YouTube to learn things or to see how tech work, YouTube is not for that
Just so you know, I have a YouTube channel where I have taught over 400k student. I see comments everyday about how I have been able to help them land jobs and how they utilised what I taught them so I am speaking from personal experience. It’s a great learning source and you don’t use it. Doesn’t stop others from using it
Brown
Viewset is a life saver
cj
Just so you know, I have a YouTube channel where I have taught over 400k student. I see comments everyday about how I have been able to help them land jobs and how they utilised what I taught them so I am speaking from personal experience. It’s a great learning source and you don’t use it. Doesn’t stop others from using it
yes, people use it, but yet they come asking why things don't work, or why things don't work the way they're expecting things to work because they saw a random guy doing that thing on YouTube but it's not working...
cj
YouTube is great to watch kittens videos and listen to music... to learn things, you'd better use documentation or well rated books, that's all
cj
even Udemy or Coursera or similar sites are not really good sources, because, you know, the same people that make YouTube videos to "teach others" are the same uploading videos to those sites, but yet they are kind of better than YouTube on some certain courses, but still not the greatest source to learn things
supreme
good day sir please which books do you recommend we read?
Doragonsureiyā
good day sir please which books do you recommend we read?
Check out @PythonRes, a channel for Python resources - video courses, pdf books, tutorials and other info to help you learn Python.
Lalit
I am using Simple JWT for token authentication and setting the access token and refresh token as HTTP-only cookies upon login in my React app. The tokens are stored in cookies, but when I make an API call from the React app, the cookies are not being sent to the backend.
S
Anyone hosted django website on godaddy with mysql??
Doragonsureiyā
Anyone hosted django website on godaddy with mysql??
Adding the word Django to your Off-Topic question doesn't magically turn it to a Django specific question, so delete your question here and move to the @PythonOfftopic group and ask there.
Lalit
I have added CORS and set CORS_ALLOW_CREDENTIALS =TRUE, but the cookies are still not being sent to the backend when making an API call from my React app.
Lalit
Http only cookies
clouded
Http only cookies
Wait. I don't understand what cookies have to do with CORS.
Lalit
do you expect the frontend to change behavior as a result of the backend configuration?
I need the access token in the backend to verify the token, so I am sending the token from React by setting withCredentials: true. However, in the backend, request.COOKIES is empty.
Lalit
That doesn't sound as if it has anything to do with CORS.
To retrieve HttpOnly cookies in an API call for token verification, I am setting CORS_Allow_Credentials =true
Lalit
How can I check if my access token and refresh token, stored in HttpOnly cookies, are valid?
Georg
helo! Is there a field in DRF like PrimaryKeyRelatedField but with a key for request, and with a structure of object for response?
Georg
I do it using separate serializers (one for request and another for response), but is there a way do it "in one bottle"?
Georg
you don't understand. I mean only in DRF, not django
Maxim
Georg
🤦🏻‍♂️ omagod
Georg
forget
Lalit
I am setting http only cookies like below: response.set_cookie( key="accessToken", value=access_token, httponly=True, secure=False, samesite="Strict" ) response.set_cookie( key="refreshToken", value=refresh_token, httponly=True, secure=False, samesite="Strict" )
Lalit
I also changed samesite Strict to None
Mirco
Yes
if the first level domain is the same, u can just link cookies to ".<main-domain> and they will be visible samesite should be None then
️امیر
you can't use DRF without Django
I guess he was talking about serializers
HAJI MASTAN
can anyone suggest me which front end framework will work great with django as i searched alot and found the answer to nextjs but i want to conform here also, thanks
clouded
can anyone suggest me which front end framework will work great with django as i searched alot and found the answer to nextjs but i want to conform here also, thanks
If you want to get job done quickly, I would suggest not to learn React. On the other hand, if the requirement is to use a (SPA) frontend framework, you can pretty much use any, since the frontend will merely talk to the API of Django Restframework, which, by the way, you will have to use to get a suitable API for an SPA frontend framework. That or another less commonly used extension to Django.
HAJI MASTAN
If you want to get job done quickly, I would suggest not to learn React. On the other hand, if the requirement is to use a (SPA) frontend framework, you can pretty much use any, since the frontend will merely talk to the API of Django Restframework, which, by the way, you will have to use to get a suitable API for an SPA frontend framework. That or another less commonly used extension to Django.
I don’t have a specific project lined up right now—I’m just trying to get a sense of which frontend framework might pair well with Django for something I might work on next. Do you think sticking to just Django, would be a solid option too? I’m wondering if that might keep things simpler for a solo project, or if you’d still recommend pairing it with a frontend framework.
clouded
I don’t have a specific project lined up right now—I’m just trying to get a sense of which frontend framework might pair well with Django for something I might work on next. Do you think sticking to just Django, would be a solid option too? I’m wondering if that might keep things simpler for a solo project, or if you’d still recommend pairing it with a frontend framework.
Certainly, just using Django without Django Restframework and without a separate single-page application frontend framework is the simpler choice. But it's not as shiny as with a SPA framework. The whole page needs to reload when you do something. So, the answer depends on the type of project. If you want data to be reloaded in the background without having to reload the page and that is kind of a frequent requirement of the project, go for SPA, even if it initially is more effort to learn and to set up the project.
clouded
If you need to have the management of the data decoupled from the frontend, for other clients to use it, for instance, you should also consider creating a REST API that can be consumed by both, a frontend framework and different types of clients.
HAJI MASTAN
Certainly, just using Django without Django Restframework and without a separate single-page application frontend framework is the simpler choice. But it's not as shiny as with a SPA framework. The whole page needs to reload when you do something. So, the answer depends on the type of project. If you want data to be reloaded in the background without having to reload the page and that is kind of a frequent requirement of the project, go for SPA, even if it initially is more effort to learn and to set up the project.
Thanks for breaking it down! I get what you mean—sticking with just Django does sound simpler, even if it’s not as flashy as an SPA setup. The page reload thing doesn’t bother me too much for what I’m thinking. Right now, I’ve got two projects going—one’s a school management system and the other’s for a hospital. Honestly, I don’t need SPA for either since they’re pretty straightforward. I was just curious about trying a frontend framework for a few pages, but after hearing you say Django alone can handle it, I’m kinda sold on that too. Keeps things easy, right?