-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
481e0af
commit b7c596f
Showing
5 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
env | ||
env/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
env/bin/activate |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
from django.contrib import admin | ||
from .models import Question | ||
from .models import Question, Answer | ||
from django.http import HttpResponse | ||
import csv | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(Question) | ||
def export_question_data(modeladmin, request, queryset): | ||
response = HttpResponse(content_type='text/csv') | ||
response['Content-Disposition'] = 'attachment; filename="dados-votos.csv"' | ||
writer = csv.writer(response) | ||
|
||
header = ["Question ID", "Question Title", "Answer ID", "Social Score", "Economic Score"] | ||
writer.writerow(header) | ||
|
||
for question in queryset: | ||
answers = Answer.objects.filter(question=question) | ||
for answer in answers: | ||
row = [question.id, question.title, answer.id, answer.social, answer.economic] | ||
writer.writerow(row) | ||
|
||
return response | ||
|
||
class QuestionAdmin(admin.ModelAdmin): | ||
list_display = ['id','title'] | ||
ordering = ['id'] | ||
|
||
actions = [export_question_data] | ||
|
||
|
||
admin.site.register(Question, QuestionAdmin) |
Binary file not shown.