I'm learning Python and Django and emerged me the following error that I can not solve :
Exception Type: AttributeError
Exception Value: 'QuerySet' object has no attribute 'apellido'
(models)
class Humano(models.Model):
nombre = models.CharField(max_length=30)
apellido = models.CharField(max_length=30)
def __unicode__(self):
return self.nombre
def apellido(self):
return self.apellido
(forms)
class formulario(forms.Form):
nombre = forms.CharField(max_length=30)
apellido = forms.CharField(max_length=30)
(views)
def comparar(request):
if request.method == 'POST':
form = formulario(request.POST)
if form.is_valid():
objeto = Humano(
nombre = form.cleaned_data['nombre'],
apellido = form.cleaned_data['apellido'],
)
objeto2 = Humano.objects.all()
n = objeto2.apellido() # el error me marca esta linea
if n == objeto.apellido:
z = 'los apellidos son iguales'
else:
z = 'los apellidos son distintos'
return render_to_response('index.html', { 'z':z}, context_instance=RequestContext(request))
else:
form = formulario()
return render_to_response('index.html', {'form':form}, context_instance=RequestContext(request))
The purpose of the view is to compare a apellido received through a form and compare it with other existing in the database .