Results of Questionnaire to be downloaded as a spreadsheet

So i have this Model namely Questionnaire in models.py file of a Django project

class Questionnaire(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField(blank=True, null=True)
    formula = models.CharField(
        max_length=200,
        default='{total}',
        help_text="Formula to calculate the total score for this questionnaire. Use {total} and {number_of_questions} as placeholders."
    )
    color = models.CharField(
        max_length=7,
        default='#000000',
        help_text="Color in HEX format. Examples: #FF5733 (red), #33FF57 (green),"
                  " #3357FF (blue), #FF33A1 (pink), #A133FF (purple), #33FFF5 (cyan), #FF8C33 (orange)"
    )

what i want to do is i want to download the results of the Questionnaire in a spreed sheet form?

i also have a admin.py file having the model there to represent or show it on UI like this

class QuestionnaireAdmin(nested_admin.NestedModelAdmin):
    model = Questionnaire
    inlines = [QuestionInline]
    list_display = ['title', 'description', 'color']
    search_fields = ['title', 'description']

so i think the best way to do this is to add an action button and the client be able to download it by a click

You might want to try out django-import-export. Follow the installation instructions and then you can configure your admin.py as follows:

# ... other imports
from import_export.admin import ExportMixin


class QuestionnaireAdmin(nested_admin.NestedModelAdmin, ExportMixin):
    model = Questionnaire
    inlines = [QuestionInline]
    list_display = ['title', 'description', 'color']
    search_fields = ['title', 'description']

This will add a download button to your admin panel. For more customisation options, please refer to the official documentation

Вернуться на верх