Skip to content

Commit

Permalink
add possibility to set additional data parameters in resource
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Aug 19, 2024
1 parent 7a9ec54 commit 8bcc25f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions import_export_celery/migrations/0011_exportjob_resource_kwargs.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
10 changes: 9 additions & 1 deletion import_export_celery/models/exportjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Check warning on line 121 in import_export_celery/models/exportjob.py

View check run for this annotation

Codecov / codecov/patch

import_export_celery/models/exportjob.py#L120-L121

Added lines #L120 - L121 were not covered by tests
return self.get_content_type().model_class().objects.filter(pk__in=pks)

def get_resource_choices(self):
Expand Down

0 comments on commit 8bcc25f

Please sign in to comment.