Hi ,
trying to display the member's list present in DB, the code works fine with 
sample scripts where as with django view-model-template output doesn't come 
properly.

urls.py
=======
url(r'^list',ListContactView.as_view(),name='member-list'),

models.py
=======
class member(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    dob       = models.DateField()
   
    def get_fields(self):
        return(self.__dict__.keys()[0:len(self.__dict__.keys())-2])


views.py
======
class ListContactView(ListView):
   
    template_name = 'member_list.html'
    model=member
    member_list = member.objects.all()
    memberobj   = member()
    def listcontacttab(self):
        import tablib
        head=memberobj.get_fields()
        d=tablib.Dataset()
        d.headers=head
        for obj in member_list:
            values=[]
            for mem in head:
                values.append(obj.__dict__[mem].__str__())
            d.append(values)
           
       
        return render_to_response(template_name,{'member_list':d})



template:
========
<ul>
  {{ d.html }}
</ul>


*The output prints only a letter S

*where as table has below datas:*

|  6 | srk1       |sinn     | 1980-01-01 |
|  7 | x          | x         | 1990-01-01 |
*



Where as same code works fine with a sample script
==================================================

from demoproj.models import member
import tablib
obj=member.objects.all()
obj1=member()
head=obj1.get_fields()
d = tablib.Dataset()
d.headers=head
count=0
for a in obj:
    count=count+1
    values=[]
    heading="heading"+`count`
    for mem in head:
        values.append(a.__dict__[mem].__str__())
    d.append(values)
print d.html


<table>
<thead>
<tr><th>dob</th>
<th>first_name</th>
<th>last_name</th></tr>
</thead>
<tr><td>1982-01-01</td>
<td>abc</td>
<td>abc1</td></tr>
<tr><td>1981-01-01</td>
<td>suman</td>
<td>mishra</td></tr>
<tr><td>1980-01-01</td>
<td>srk1</td>
<td>mis</td></tr>
<tr><td>1990-01-01</td>
<td>x</td>
<td>x</td></tr>
</table>

1) How to debug django.py view code

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to