Package: django-simple-export-admin
django-simple-export-adminA simple django admin allow your export queryset to xlsx file.Installpipinstalldjango-simple-export-adminUsagepro/settings.pyINSTALLED_APPS=[...'django_static_fontawesome','django_changelist_toolbar_admin','django_simple_export_admin',...]django_static_fontawesome, django_changelist_toolbar_admin and django_simple_export_admin are required.app/models.pyfromdjango.dbimportmodelsclassCategory(models.Model):name=models.CharField(max_length=32)classBook(models.Model):name=models.CharField(max_length=32)author=models.CharField(max_length=32)category=models.ForeignKey(Category,on_delete=models.SET_NULL,null=True,blank=True)is_published=models.NullBooleanField()published_date=models.DateField(null=True)count=models.IntegerField(default=0)defpreview(self):return"/preview/{0}.png".format(self.pk)preview.short_description="Preview Image Path"classMeta:permissions=[("export_filtered_books","Export all filtered books"),]app/admin.pyfromdjango.contribimportadminfromdjango_simple_export_admin.adminimportDjangoSimpleExportAdminfromdjango_simple_export_admin.adminimportNullBooleanRenderfromdjango_simple_export_admin.adminimportDateRenderfromdjango_simple_export_admin.adminimportSumfrom.modelsimportBookclassBookAdmin(DjangoSimpleExportAdmin,admin.ModelAdmin):list_display=["name","author"]list_filter=["is_published","published_date","author"]django_simple_export_admin_exports={"filtered-books":{"label":"Export All Filtered Books","icon":"fas fa-book","filename":"Book","fields":[{"field":"forloop.counter1","label":"Index"},{"field":"name","label":"Book Name","footer-value":"Sum:"},{"field":"count","label":"Stock","footer-value":lambda:Sum()},{"field":"category__name"},{"field":"author","label":"Author","empty_value":"-"},{"field":"is_published","label":"Is Published","render":NullBooleanRender("UNKNOWN","YES","NO")},{"field":"published_date","label":"Published Date","render":DateRender()},],"export-filtered":True,"permissions":["django_simple_export_admin_example.export_filtered_books"],}}labeldefault to _("Export").icondefault to None means no icon.filenamedefault to model_name.export-filtereddefault to False, means always export all queryset without filtering.permissionsdefault to None, means only super admin have permission to do exporting.fieldsfieldcan be field of the model instance, callable function of the model instance, callable function of the admin which takes model instance parameter. Similar with field name inlist_display.field == forloop.counter1will always display row index, e.g. 1,2,3...labelis the header of the column. If missing label, field.verbose_name or function.short_description will be used firstly. If still null, use the field name.renderis a callable object that transform the original value to display value.empty_valueonly works whenrenderis not provided, it is the display value for orignal None value.footer-valueis the value display at the bottom row. It can be an instance of Aggregate that accept every item value of this field and calc the final value at last. It can be a staic value.start-row-indexis row index where begin to write data. starts from 1.xlsx-templatetemplate xlsx file path.show-headerTrue or False means show header or not.colWhich col the field value will be stored. Mostly it is 1-based index number. Use list so that you can split long string into multiple cells. Xlsx cell size limit to 32*1024 characters.Shipped Rendersdjango_simple_export_admin.admin.ForceStringRenderdjango_simple_export_admin.admin.DateRenderdjango_simple_export_admin.admin.BooleanRenderdjango_simple_export_admin.admin.NullBooleanRenderShipped Aggregatesdjango_simple_export_admin.admin.Sumdjango_simple_export_admin.admin.Averagedjango_simple_export_admin.admin.CountReleasesv0.1.0First release.v0.1.1Fix footer-value problem. If use an instance of Aggregate in settings, the instance is used globally, so that the final value if not correct. So you must add lambda to dynamically to create a new instance very time.v0.1.2Fix document.v0.1.3Fix queryset limited by list_per_page problem, reset it to MAX_ROWS=999999.Fix related field problem.Change __row_index to forloop.counter1, because __ used for related object property.If field label setting missing, found it's field-verbose-name or function-short-description first.Use get_xxx_display() for choice field.Add xlsx-template support.Add start-row-index support.Add show-header support.v0.1.4Fix loop.counter1 problem when start-row-index != 1.v0.1.5Fix requirements.txt in setup stage.Add app_requires in django_simple_export_admin.init.py to work with django-app-requires.v0.1.6Add long string value split into multiple cells support.v0.1.7Doc update.v0.1.9Fix ugettext problem.v0.1.10Fix urlquote problem.