0

I did the application on the sample from this lesson. Here, using DRF, a list of all added games is displayed on the page. I would really like to learn how to write a simple form of adding a new record to the database (two fields: title and description [as in the example]).

With js, I'm not very familiar with so far, so I do not know which side to get close to solving the problem.

1
  • 1
    You should give it a try and come back with specific questions. SO is not a coding for hire service. Commented Aug 16, 2017 at 17:04

2 Answers 2

1
  $scope.saveUser = function(event) {

        postForm({ id: 0 }, $('#FormName'), $scope, function(data) {

        })
    }

 function postForm(postInfo, form, $scope, callback,) {    

    var postData = new FormData(form.get(0));

    $.each(postInfo, function(key, value) {
      postData.append(key, value);
    });

    $.ajax({
      type: form.attr('method'),
      url: form.attr('action'),
      data: postData,
      cache: false,
      dataType: 'json',
      processData: false,
      contentType: false,
      headers: {
        "X-CSRFToken": app.getStorage("csrftoken")
      },
      beforeSend: function() {
        $('#loading-image').show();        
      },
      complete: function() {
        $('#loading-image').hide();
        if(typeof saveButtonId !== typeof undefined) {
          $('#'+saveButtonId).removeAttr('disabled');
        }
      },
      success: function(data) {


      },
      error: function(data) {

        // 
      }
    });
  };
Sign up to request clarification or add additional context in comments.

Comments

1

you'd be updating code in your mysite/backend folder to have some incoming route to insert data into django db using some serializer

sorry I don't have more specific details, but just wanted to convey the general idea

Here's some more information on Django serializers: http://www.django-rest-framework.org/api-guide/serializers/

another tutorial on adding an additional route to django could help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.