Hi all and tank very much for your preciouse time

I have the following scenario:

#models.py

class Anagrafica(models.Model):
    GENERE_CHOICES = (
            (u'M', u'Maschio'),
            (u'F', u'Femmina'),
        )
    cognome = models.CharField(max_length=20)
    nome = models.CharField(max_length=20)
    indirizzo=models.CharField(max_length=30)

    def __unicode__(self):
        return self.cognome+" "+self.nome

#urls.py
    ....
    (r'^anag_edit/(?P<anag_id>\d+)/$',
'condor.condomini.forms.anag_form'),
    (r'^anag_edit/$', 'condor.condomini.forms.anag_form'),

#forms.py

from django import forms
from condor.condomini.models import *
from django.shortcuts import render_to_response, get_object_or_404,
redirect
from django.template import RequestContext
from django.http import HttpResponseRedirect


class AnagraficaForm(ModelForm):
    class Meta:
        model = Anagrafica

def anag_form(request, anag_id=None):
    if anag_id is None:
        x=Anagrafica.objects.create()
    else:
        x=Anagrafica.objects.get(pk=anag_id)

    form = AnagraficaForm(request.POST or None, instance=x) # A form
bound to the POST data
    if form.is_valid(): # All validation rules pass
        form.save()
        return HttpResponseRedirect('/ListaAnagrafica/') # Redirect
after POST

    return render_to_response('condomini/anag_edit.html', {'form':
form,})


#anag_edit.html
{% extends "base_menu.html" %}



{% block title %}Editing Anagrafica{% endblock %}



{% block content %}

<form action="." method="POST">

{% csrf_token %}

{{ form.as_p }}

<input type="submit" value="Invia" />



</form>

{% endblock %}


this works fine...almost

when i try to insert  new data with the empty form, data are correctly
added to my database, but an empty record also is added to my table.

Any help will be greatly appreciated.
thank


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to