AlexMessi10 0 Newbie Poster

Hello everyone, I am making my thesis in the university using Python as programming language and Django as framework, I have doubts about choose data from de models class, for example I have the class Tribunal, and I am able to generate an Excel with all the objects of that class Tribunal, I mean all the presidents, all the secretaries, all the vocals and all the assistants, but I only want that in the Excel be shown all the presidents and all the secretaries, not the others(vocals and assitants no). I put under the model class and the function that generates the Excel.

class Tribunal(models.Model):
    presidente=models.CharField(max_length=90)
    secretario=models.CharField(max_length=90)
    vocal=models.CharField(max_length=90)
    def __str__(self):
                return self.presidente

This is the function:

def excelejemplo(request):
	book = xlwt.Workbook(encoding='utf8')
	sheet = book.add_sheet('untitled')
	default_style = xlwt.Style.default_style
	datetime_style = xlwt.easyxf(num_format_str='dd/mm/yyyy hh:mm')
	date_style = xlwt.easyxf(num_format_str='dd/mm/yyyy')
	lista = Tribunal.objects.all()	
	formato=ExcelFormatter()
        estilosimple = ExcelStyle(vert=2,wrap=1)
	formato.addBodyStyle(estilosimple)
	formato.setWidth('presidente,secretario,vocal',3000)	
	simple_report=ExcelReport()
	simple_report.addSheet("Prueba sencilla")
	#filter=ExcelFilter(order='presidente,secretario,vocal')
	simple_report.addQuerySet(lista,REPORT_HORZ,formato)
	response = HttpResponse(simple_report.writeReport(),mimetype='application/ms-excel')
        response['Content-Disposition'] = 'attachment; filename=simple_test.xls'
        return response

I hope that somebody could help me, greetings for everyone.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.