Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
How to check if an input value is exists and validate if yes in Django

I made a text input filed with jquery autocomplete where I query the users. So if I start typing the name of a user it shows the related users. It works fine but I like to avoid that if the user like not to choose from the pupped up list and possibly type all the name and it has a mistake. So I like to make a function that checks if the added value of the field is equals with any of the users in the database. How to do that?

html

<input type="text" class="form-control" placeholder="Type name here" name="kap_bar_01" id="kap_bar_01"> 

<script>
     $(function() {
        var names  =  [

          {% for u in related_users %}
            "{{ u.user.last_name }} {{ u.user.first_name }}",
          {% endfor %}
        ];

        $( "#kap_bar_01" ).autocomplete({
           source: names
        });
     });
  </script>

models.py

class Kapcsolodasok(models.Model):

    def __str__(self):
        return str(self.user_name)

    user_name = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    date = models.DateField(auto_now_add=True, auto_now=False, blank=True)
    kap_bar_01 = models.TextField(max_length=200)

views.py

def kapcsolodasok(request):

    profile = Profile.objects.get(user=request.user)
    related_users = Profile.objects.filter(projekt=profile.projekt)

    context = {
        'related_users': related_users,
        'profile': profile,
    }

    #lots of stuffs here

    return render(request, 'stressz/kapcsolodasok.html', context)

Thank you in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

from django.contrib.auth.models import User
userList = User.objects.values()

The above code will get the usernames as list and loopover to check the username entered.But i think you want it to be checked in realtime so you have to use channels or ajax etc.Otherwise just pass the username value as url url/ and check it

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!