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

175
Views
Publicación de datos de fecha en el modelo de Django

Me preguntaba si alguno de ustedes aquí sabía cómo solucionar este error, he estado lidiando con él durante bastantes horas, tiene que ver con la publicación de la fecha json (una fecha de un selector de fecha html) en un modelo de back-end usando el framework web django. Por favor, hágamelo saber si mi pregunta no está clara.

VerPedidos.html

 <form id="form"> <label for="start">Drop Off Date Selector:</label> <br> <input type="date" id="dropOffDate" name="drop_Off_Date" min="2022-01-01" max="3000-12-31"> <button type="submit" value="Continue" class="btn btn-outline-danger" id="submit-drop-off-date" >Submit Drop Off Date</button> </form> 

 <script type="text/javascript"> var form = document.getElementById('form') form.addEventListener('submit', function(e){ e.preventDefault() submitDropOffData() console.log("Drop Off Date submitted...") }) function submitDropOffData() { var dropOffDateInformation = { 'dropOffDate':null, } dropOffDateInformation.dropOffDate = form.drop_Off_Date.value var url = "/process_drop_off_date/" fetch(url, { method:'POST', headers:{ 'Content-Type':'application/json', 'X-CSRFToken':csrftoken, }, body:JSON.stringify({'drop-off-date':dropOffDateInformation}), }) .then((response) => response.json()) .then((data) => { console.log('Drop off date has been submitted...') alert('Drop off date submitted'); window.location.href = "{% url 'home' %}" }) } </script>

Vistas.py

 def processDropOffDate(request): data = json.loads(request.body) DropOffDate.objects.create( DropOffDate=data['drop-off-date']['dropOffDate'], ) return JsonResponse('Drop off date submitted...', safe=False)

Modelos.py

 class DropOffDate(models.Model): dropOffDate = models.CharField(max_length=150, null=True) def __str__(self): return str(self.dropOffDate)

errores

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La solución a esto fue que había creado un objeto con el nombre de campo incorrecto, por lo que la respuesta de Json no era válida.

 class DropOffDate(models.Model): dropOffDate = models.CharField(max_length=150, null=True) def __str__(self): return str(self.dropOffDate)

Cambiado a:

 class DropOffDate(models.Model): DropOffDate = models.CharField(max_length=150, null=True) def __str__(self): return str(self.DropOffDate)
about 4 years ago · Juan Pablo Isaza Report
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!