Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] boton elminar en python con Django

Estas en el tema de boton elminar en python con Django en el foro de Python en Foros del Web. Hola buenas noches estoy haciendo un CRUD en python con Django 1.6.5 estoy usando vistas genericas ya e echo el link "agregar" y el de ...
  #1 (permalink)  
Antiguo 12/06/2014, 22:59
 
Fecha de Ingreso: julio-2011
Ubicación: Peru
Mensajes: 92
Antigüedad: 12 años, 9 meses
Puntos: 1
boton elminar en python con Django

Hola buenas noches estoy haciendo un CRUD en python con Django 1.6.5
estoy usando vistas genericas ya e echo el link "agregar" y el de "editar" quisiera saber como puedo hacer un link "eliminar" y me elimine registro, este es mi codigo

forms.py

Código:
from django.forms import ModelForm
from models import Paciente


class PacienteForm(ModelForm):
    class Meta:
        model = Paciente

views.py
Código:
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.views.generic import TemplateView, ListView, FormView, CreateView, UpdateView
from models import Paciente
from forms import PacienteForm
from django.template import RequestContext
import json as simplejson



class Home(TemplateView):
    template_name ='mostrar.html'

#============ Paciente =============
class ListarPaciente(TemplateView):
    template_name = 'listar_paciente.html'

    def get_context_data(self, **kwargs):
        context = super(ListarPaciente, self).get_context_data(**kwargs)
        context['lista_data'] = Paciente.objects.all()
        return context


class AgregarPaciente(CreateView):
    template_name = 'agregar.html'
    model = Paciente
    form_class = PacienteForm
    success_url = '/'

class EditarPaciente(UpdateView):
    template_name = 'agregar.html'
    model = Paciente
    from_class = PacienteForm
    success_url = '/'

    def get_object(self, queryset=None):
        obj = Paciente.objects.get(pk=self.kwargs['pk'])
        return obj

urls.py
Código:
from django.conf.urls import patterns, include, url

import views

urlpatterns = patterns('',
    url(r'^$', views.Home.as_view(), name='home'),

    url(r'^listarpaciente/?$', views.ListarPaciente.as_view(), name='listar-paciente' ),
    url(r'^agregar/?$', views.AgregarPaciente.as_view(), name='agregar'),
    url(r'^editarpaciente/(?P<pk>\d+)/?$', views.EditarPaciente.as_view(), name='editarpaciente'),)
mis template
template
...agregar.html
...listar_paciente.html

codigo de mi listar_paciente.html

Código HTML:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <a href="{% url 'agregar' %}">Agregar</a>
    <table>
        <thead>
            <tr>

                <th>Nombres y apellidos </th>

                <th>Acción</th>
            </tr>
        </thead>
        <tbody>
            {% for data in lista_data %}
                <tr>
                    <td>
                        {{data.nombres}}
                        {{data.apePat}}
                        {{data.apeMat}}
                    <td>
                        <a href="{% url 'editarpaciente' data.pk %}">Editar</a>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</body>
</html> 
Espero su pronta ayuda gracias
  #2 (permalink)  
Antiguo 13/06/2014, 09:45
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: boton elminar en python con Django

Si tienes un CreateView para crear, un UpdateView para actualizar, lo mas logico seria tener un DeleteView para borrar.

Etiquetas: django
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:28.