replacing integer with tuple value in template

2010-12-13 Thread morgand
I have a tuple set

MY_TYPE = (
(0, 'Other'),
(1, 'This'),
(2, 'That'),
)

In my model I have a field that uses "choices" to set the value. Can
save/edit the model as  a modelform fine.

But I want to display a LIST of my records and replace the integer
with the respective text ..

so...

mylist = MyClass.objects.filter(key=lookup_value)

I can display the list, but it displays the integer value rather than
the "text" that I want. Help!!

In the template entering I have {% myObject.type %} which gives me the
0,1,2 etc...

-- 
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.



Help! I'm thick! First formset generating AttributeError

2010-12-08 Thread morgand
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

{{ formset.management_form }}
{% for form in formset.forms %}
{{ form.id }}

{{ form.id }}
{{ form.firstname }}
{{ form.lastname }}

{% endfor %}




-- 
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.