|
1 | 1 | # Copyright (C) 2019 o.s. Auto*Mat |
2 | 2 | from django.utils import timezone |
3 | | -import json |
4 | 3 |
|
5 | 4 | from author.decorators import with_author |
6 | 5 |
|
@@ -67,8 +66,9 @@ def __init__(self, *args, **kwargs): |
67 | 66 | default="", |
68 | 67 | ) |
69 | 68 |
|
70 | | - queryset = models.TextField( |
71 | | - verbose_name=_("JSON list of pks to export"), |
| 69 | + |
| 70 | + queryset = models.JSONField( |
| 71 | + verbose_name=_("JSON list of pks to export or dict of queryset filters"), |
72 | 72 | null=False, |
73 | 73 | ) |
74 | 74 |
|
@@ -104,14 +104,19 @@ def get_content_type(self): |
104 | 104 | return self._content_type |
105 | 105 |
|
106 | 106 | def get_queryset(self): |
107 | | - pks = json.loads(self.queryset) |
| 107 | + queryset_spec = self.queryset |
| 108 | + if isinstance(queryset_spec, list): |
| 109 | + filters = {"pk__in": queryset_spec} |
| 110 | + elif isinstance(queryset_spec, dict): |
| 111 | + filters = queryset_spec |
| 112 | + |
108 | 113 | # If customised queryset for the model exists |
109 | 114 | # then it'll apply filter on that otherwise it'll |
110 | 115 | # apply filter directly on the model. |
111 | 116 | resource_class = self.get_resource_class() |
112 | 117 | if hasattr(resource_class, "get_export_queryset"): |
113 | | - return resource_class().get_export_queryset().filter(pk__in=pks) |
114 | | - return self.get_content_type().model_class().objects.filter(pk__in=pks) |
| 118 | + return resource_class().get_export_queryset().filter(**filters) |
| 119 | + return self.get_content_type().model_class().objects.filter(**filters) |
115 | 120 |
|
116 | 121 | def get_resource_choices(self): |
117 | 122 | return [ |
|
0 commit comments