Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda