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

77
Views
Enviar un formulario dentro de una vista detallada crea un nuevo objeto en lugar de reemplazarlo

Estoy tratando de crear un tablero para que los usuarios del personal completen y editen información sobre sus usuarios. El formulario funciona y se guarda con éxito, pero cuando lo envío por segunda vez, crea un nuevo objeto. No reemplazará al anterior:

Este es mi archivo views.py :

 class ScientificInfoView(FormMixin, DetailView): model = ScientificInfo template_name = 'reg/scientific-info.html' form_class = ScientificInfoForm def get_success_url(self): return reverse('scientific-info', kwargs={'pk': self.object.pk}) def get_context_date(self, **kwargs): context = super(ScientificInfoView, self).get_context_data(**kwargs) context['form'] = ScientificInfoForm() return context def post(self, request, *args, **kwargs): self.object = self.get_object() form = self.get_form() if form.is_valid(): return self.form_valid(form) else: return self.form_invalid(form) def form_valid(self, form): form.save() return super(ScientificInfoView, self).form_valid(form)

Y mi plantilla:

 <form method="POST" enctype="multipart/form-data" action="{% url 'scientific-info' pk=object.id %}"> {% csrf_token %} {{form}} <button type="submit">submit</button> </form>

Archivo urls.py :

 path('surveys/scientific/<pk>', login_required(views.ScientificInfoView.as_view()), name='scientific-info')

Estoy bastante seguro de que la parte de acción en mi formulario está causando el problema, pero ¿cómo puedo resolverlo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Utilizar esta:

 def get_success_url(self): pk = self.kwargs["pk"] return reverse("scientific-info", kwargs={"pk": pk})

O

 class ScientificInfoView(FormMixin, DetailView): model = ScientificInfo template_name = 'reg/scientific-info.html' form_class = ScientificInfoForm def get_success_url(self): return reverse("scientific-info", args=[pk]) # You can replace pk
over 4 years ago · Santiago Trujillo 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!