Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

javascript - Django - How to pass the name of a button to views.py from jQuery dialog

How do you pass the name of a button to views.py from a jQuery dialog?

I want to pass save_add from the HTML button name='save_add'

How can I do that? Could you help me up?

My jQuery:

  function addcontinue(){
    $('.confirm-continue-message').dialog({
      dialogClass:"confirm-modal",
        modal: true,
        buttons: {
            "save and continue": function() { $('#addform').submit().attr("name", "save_add"); },
            "cancel": function() { $(this).dialog('close'); },
        },
      resizeable : false,
      draggable: false,
      show: {
        effect: "fade",
        duration: 200
      },
      hide: {
        effect: "fade",
        duration: 200
      },
      focus:"none",
    });
  }

My views.py:

class StudentAdd(FormView):
    model = Student
    template_name = 'student/list_add.html'
    context_object_name = 'student'
    form_class = AddStudent

    def post(self, request):
        form = self.form_class(request.POST, request.FILES)
        if form.is_valid():
            student = form.save(commit=False)
            student.created_by = request.user

            student.save()
            messages.info(request, student.name + ' ??? ???????.', extra_tags='info')
            if "save_add" in self.request.POST:
                return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
            return redirect('student_detail', pk=student.pk, school_year=student.school_year)

        return FormView.post(self, request)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...