Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Django invalid literal for int() with base 10: 'Stalone'

I'm trying to get the users that I'm marking as True on my website in data['checked_users']:

models.py

class Player(models.Model):
    jucator = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, related_name='jucator')
    porecla = models.CharField(max_length=50, null=True, blank=True)
    selectat = models.BooleanField(default=False)

    def __str__(self):
        return u'%s' % self.jucator

views.py

def check_user(request):
    data = dict()
    data['players'] = Player.objects.all()
    if request.method == 'POST':
        list_of_checks = request.POST.getlist('checks[]')
        # data['checked_users'] = list_of_checks
        data['checked_users'] = Player.objects.filter(jucator__in=list_of_checks)
    return render(request, 'checkbox.html', data)

checkbox.html

<body>
    {% block content %}
        <form action="" method="POST">{% csrf_token %}
            <table>
                    {% if request.user.is_superuser %}
                        {% for user in players %}
                            <tr>
                                <td><input type="checkbox" name="checks[]" value="{{ user.jucator }}" title="selected_players">{{ user.jucator }}<br></td>
                            </tr>
                        {% endfor %}
                            <tr>
                                <td><input type="submit" name="submit" value="Submit"></td>
                            </tr>
                    {% else %}
                        {% for user in players %}
                            <tr><td>{{ user.jucator }}</td></tr>
                        {% endfor %}
                    {% endif %}
            </table>
        {% for player in checked_users %}
            {{ player }}
        {% endfor %}
        </form>
    {% endblock %}
</body>

If I try this, it shows the players:

data['checked_users'] = list_of_checks

If I try with filter, I get this error:

invalid literal for int() with base 10: 'Stalone'
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to put inside value="{{ user.jucator }}" the actual id of the jucator object. Not the jucator object itself.

So, change to this: value="{{ user.jucator.id }}". Now you can query with Player.objects.filter(jucator__in=list_of_checks) since list_of_checks containts a list of integers (the ids of jucators).

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda