From 57d59e962cc4ce267e0446fd2fbd5b3208a86677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Mon, 29 Jul 2024 13:52:44 +0200 Subject: [PATCH] add possibility to set additional data parameters in resource --- .../0011_exportjob_resource_kwargs.py | 20 +++++++++++++++++++ import_export_celery/models/exportjob.py | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 import_export_celery/migrations/0011_exportjob_resource_kwargs.py diff --git a/import_export_celery/migrations/0011_exportjob_resource_kwargs.py b/import_export_celery/migrations/0011_exportjob_resource_kwargs.py new file mode 100644 index 0000000..4acd517 --- /dev/null +++ b/import_export_celery/migrations/0011_exportjob_resource_kwargs.py @@ -0,0 +1,20 @@ +# Generated by Django 5.0.7 on 2024-07-29 08:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("import_export_celery", "0010_auto_20231013_0904"), + ] + + operations = [ + migrations.AddField( + model_name="exportjob", + name="resource_kwargs", + field=models.JSONField( + blank=True, default=None, null=True, verbose_name="Resource additional data parameters" + ), + ), + ] diff --git a/import_export_celery/models/exportjob.py b/import_export_celery/models/exportjob.py index 66f5691..66671d2 100644 --- a/import_export_celery/models/exportjob.py +++ b/import_export_celery/models/exportjob.py @@ -67,6 +67,13 @@ def __init__(self, *args, **kwargs): default="", ) + resource_kwargs = models.JSONField( + verbose_name=_("Resource additional data parameters"), + default=None, + null=True, + blank=True, + ) + queryset = models.TextField( verbose_name=_("JSON list of pks to export"), null=False, @@ -110,7 +117,7 @@ def get_queryset(self): # apply filter directly on the model. resource_class = self.get_resource_class() if hasattr(resource_class, "get_export_queryset"): - return resource_class().get_export_queryset().filter(pk__in=pks) + return resource_class(**self.resource_kwargs).get_export_queryset().filter(pk__in=pks) return self.get_content_type().model_class().objects.filter(pk__in=pks) def get_resource_choices(self):