Пример #1
0
    def post(self, request, *args, **kwargs):

        persona_form = PersonaForm(self.request.POST, self.request.FILES)
        cliente_form = ClienteForm(data=self.request.POST)

        if persona_form.is_valid() and cliente_form.is_valid():
            persona = persona_form.save(commit=False)

            if 'foto' in self.request.FILES:
                self.set_foto(persona, (self.request.FILES['foto']))
            persona.save()
            cliente_form.instance.persona = persona
            cliente_form.save()

            messages.add_message(
                request, messages.SUCCESS, 'CLIENTE CREADO CON EXITO')

            return HttpResponseRedirect('/clientes/modi/%s' %
                                        str(cliente_form.instance.id))

        messages.add_message(
            request, messages.SUCCESS, 'EL FORMULARIO CONTIENE ERRORES')

        return render_to_response(
            'clientes/cliente_form.html',
            {
                'form': persona_form,
                'cliente_form': cliente_form
            },
            context_instance=RequestContext(request)
        )
Пример #2
0
    def post(self, request, *args, **kwargs):
        cliente = Cliente.objects.get(pk=kwargs['pk'])
        persona = Persona.objects.get(pk=cliente.persona.id)

        persona_form = PersonaForm(self.request.POST, self.request.FILES,
                                   instance=persona)
        cliente_form = ClienteForm(self.request.POST, instance=cliente)

        if persona_form.is_valid() and cliente_form.is_valid():

            if 'foto' in self.request.FILES:
                self.set_foto(persona_form, self.request.FILES['foto'])

            persona = persona_form.save()
            cliente_form.instance.persona = persona

            cliente_form.save()

            messages.add_message(
                request, messages.SUCCESS, 'CLIENTE MODIFICADO CON EXITO')

            return HttpResponseRedirect('/clientes/modi/%s' % kwargs['pk'])

        messages.add_message(
            request, messages.SUCCESS, 'EL FORMULARIO CONTIENE ERRORES')

        return render_to_response(
            'clientes/cliente_form.html',
            {
                'form': persona_form,
                'cliente_form': cliente_form
            },
            context_instance=RequestContext(request)
        )
Пример #3
0
    def get(self, request, *args, **kwargs):

        persona_form = PersonaForm()
        cliente_form = ClienteForm()

        return render_to_response(
            'clientes/cliente_form.html',
            {
                'form': persona_form,
                'cliente_form': cliente_form
            },
            context_instance=RequestContext(request)
        )
Пример #4
0
    def get(self, request, *args, **kwargs):

        cliente = Cliente.objects.get(pk=kwargs['pk'])

        persona = Persona.objects.get(pk=cliente.persona.id)
        persona_form = PersonaForm(instance=persona)

        cliente_form = ClienteForm(instance=cliente)

        return render_to_response(
            'clientes/cliente_form.html',
            {
                'form': persona_form,
                'cliente_form': cliente_form
            },
            context_instance=RequestContext(request)
        )