Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Help! I'm thick! First formset generating AttributeError [RSS Feed]

#1 Dec. 8, 2010 12:22:51

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Help! I'm thick! First formset generating AttributeError


Either its age - the scotch - or some combination of both, but I am
having problems with a SIMPLE formset. (its my first).

On my formset I get an AttributeError - 'Client' object has no
attribute 'ordered'... .but I dont have an attribute of that
anywhere....???? I tried changing from a "get" to a "raw" but still
get a (similar) message.

My code is :
(models.py)

class Client(models.Model):
title = models.CharField(max_length=3, choices=TITLE_CHOICES)
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
mobilenumber = models.CharField(max_length=50)
phonenumber = models.CharField(max_length=50)
email = models.CharField(max_length=50)
street = models.CharField(max_length=50)
city = models.CharField(max_length=50)
state = models.CharField(max_length=10, choices=STATE_CHOICES)
class Meta:
ordering = ('lastname','firstname')
unique_together = ('firstname', 'lastname','mobilenumber')

def __unicode__(self):
return self.id


I have a forms.py containing

ClientFormSet = modelformset_factory(Client, extra=0, max_num=1)


In my view.py" I have the following... which is getting called and is
what generates the error....

def c4(request, client_id=None):
if client_id == None:
if request.method == 'POST':
formset = ClientFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
clients = Client.objects.all()
return SortableGrid(request,
clients).render_to_response("mylibrary/real.html")
else:
formset = ClientFormSet(request.POST, request.FILES)

else:
if request.method == 'POST':
formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))
if formset.is_valid():
formset.save()
clients = Client.objects.all()
return SortableGrid(request,
clients).render_to_response("mylibrary/real.html")

else:
formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))

return render_to_response("4.html", {
"formset": formset,
})


My "4.html" contains
<form method="post" action="">
{{ formset.management_form }}
{% for form in formset.forms %}
{{ form.id }}
<ul>
<li>{{ form.id }}</li>
<li>{{ form.firstname }}</li>
<li>{{ form.lastname }}</li>
</ul>
{% endfor %}
<input type="submit" value="Save" />
</form>
<FORM METHOD="LINK" ACTION="../3"><input type="submit" value="Cancel" /
></FORM>

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 8, 2010 15:00:15

f.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Help! I'm thick! First formset generating AttributeError


While I haven't worked with formsets, this line doesn't look correct:

formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))

mainly due to a parameter named queryset being passed a model object,
instead of a queryset of model objects. It would seem that you want
queryset=Client.objects.filter(pk=client_id) to achieve the same
result.

Then again, I could be wildly off.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Help! I'm thick! First formset generating AttributeError [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support