Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to set additional data parameters in resource #129

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
# 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
Loading