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

158
Views
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
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!