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..df0e37f 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,8 @@ 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) + kwargs = self.resource_kwargs or {} + return resource_class(**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):