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

171
Visualizações
django model field default value not showing in template with jquery

when i remove the html data- , then django field value is showing there . but when i add the data-id, data-winner etc , django model field default value is not showing in template, how can i fix this . ?

models.py

class Contest(models.Model):
  title = models.CharField(max_length=50)
  name_winner = models.CharField(max_length=50,default="Announce")
  
  @property
    def winner(self):
        if something ...
           winner_name = something 
        else:
           winner_name = something 
        return name_winner 

html

{%for ....%}
 <td type="hidden" class="winner_click" data-winner="{{contest.winner}}" data-id="{{contest.id}}"> {{contest.name_winner}}</td>
{%end for%}
<script>

      $(".winner_click").click(function(){
        var get_id = $(this).data('id')
        var get_data = $(this).data('winner')
        $(this).html(get_data).css("color","black")
        

        $.ajax(
            {
                type:"POST",
                url: "/admin/save_winner",
                data:{
                    'contest_id': get_id,
                    'contest_winner':get_data,
                    "csrfmiddlewaretoken": '{{ csrf_token }}'
                    },
                success: function( data ) 
                {
                    $(this).html(get_data).css("color","black")
                }
            })
      });

</script>

in this case when i remove the data-id and data-winner then that td shows default django field value , in this case there is nothing shows .

views: save winner

def save_winner(request):
    if request.method == 'POST':
        contest_id = request.POST.get('contest_id')
        contest_winner = request.POST.get('contest_winner')
        Contest.objects.filter(id=contest_id).update(name_winner=contest_winner)
        return JsonResponse({"status":"success"}) 

how can i fix this ? why is this issue ?

Thank you

about 4 years ago · Juan Pablo Isaza
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