Here is my code
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 as below datas:
| 6 | srk1 |sinn | 1980-01-01 |
| 7 | x | x | 1990-01-01 |
-- 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 as below datas:
| 6 | srk1 |sinn | 1980-01-01 |
| 7 | x | x | 1990-01-01 |
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment