Skip to content

Commit db81f64

Browse files
242 Fix
1 parent 8cfe3b1 commit db81f64

File tree

8 files changed

+42
-60
lines changed

8 files changed

+42
-60
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.22.1
19+
----
20+
2021-04-29
21+
22+
- `DictionaryProxy` gets an optional `meta` argument, which will hold meta
23+
information of the hit.
24+
1825
0.22
1926
----
2027
2021-03-26

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.22.1
19+
----
20+
2021-04-29
21+
22+
- `DictionaryProxy` gets an optional `meta` argument, which will hold meta
23+
information of the hit.
24+
1825
0.22
1926
----
2027
2021-03-26

examples/simple/search_indexes/serializers/city.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from rest_framework import serializers
2+
13
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
24

35
from ..documents import CityDocument
@@ -8,6 +10,8 @@
810
class CityDocumentSerializer(DocumentSerializer):
911
"""Serializer for city document."""
1012

13+
es_id = serializers.SerializerMethodField()
14+
1115
class Meta:
1216
"""Meta options."""
1317

@@ -23,4 +27,10 @@ class Meta:
2327
'datetime_list',
2428
'float_list',
2529
'integer_list',
30+
'es_id',
2631
)
32+
33+
def get_es_id(self, obj):
34+
if hasattr(obj.meta, 'id'):
35+
return obj.meta.id
36+
return None

examples/simple/search_indexes/serializers/journal.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,6 @@
88
)
99

1010

11-
# class JournalDocumentSerializer(serializers.Serializer):
12-
# """Serializer for the Book document."""
13-
#
14-
# isbn = serializers.CharField(read_only=True)
15-
#
16-
# title = serializers.CharField(read_only=True)
17-
# description = serializers.CharField(read_only=True)
18-
# summary = serializers.CharField(read_only=True)
19-
#
20-
# publication_date = serializers.DateField(read_only=True)
21-
#
22-
# price = serializers.FloatField(read_only=True)
23-
# pages = serializers.IntegerField(read_only=True)
24-
# stock_count = serializers.IntegerField(read_only=True)
25-
# created = serializers.DateTimeField(read_only=True)
26-
#
27-
# class Meta:
28-
# """Meta options."""
29-
#
30-
# fields = (
31-
# 'title',
32-
# 'description',
33-
# 'summary',
34-
# 'publication_date',
35-
# 'state',
36-
# 'isbn',
37-
# 'price',
38-
# 'pages',
39-
# 'stock_count',
40-
# 'created',
41-
# )
42-
# read_only_fields = fields
43-
#
44-
# def create(self, validated_data):
45-
# """Create.
46-
#
47-
# Do nothing.
48-
#
49-
# :param validated_data:
50-
# :return:
51-
# """
52-
#
53-
# def update(self, instance, validated_data):
54-
# """Update.
55-
#
56-
# Do nothing.
57-
#
58-
# :param instance:
59-
# :param validated_data:
60-
# :return:
61-
# """
62-
63-
6411
class JournalDocumentSerializer(DocumentSerializer):
6512
"""Serializer for the Book document."""
6613

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import find_packages, setup
44

5-
version = '0.22'
5+
version = '0.22.1'
66

77
DOCS_TRANSFORMATIONS = (
88
(

src/django_elasticsearch_dsl_drf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"""
44

55
__title__ = 'django-elasticsearch-dsl-drf'
6-
__version__ = '0.22'
6+
__version__ = '0.22.1'
77
__author__ = 'Artur Barseghyan <[email protected]>'
88
__copyright__ = '2017-2020 Artur Barseghyan'
99
__license__ = 'GPL 2.0/LGPL 2.1'
1010

1111

1212
from django_nine import versions
1313

14-
if versions.DJANGO_LT_3_2:
14+
if versions.DJANGO_LTE_3_1:
1515
__all__ = ('default_app_config',)
1616
default_app_config = 'django_elasticsearch_dsl_drf.apps.Config'

src/django_elasticsearch_dsl_drf/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ def to_dict(self, *args, **kwargs):
5454
class DictionaryProxy(object):
5555
"""Dictionary proxy."""
5656

57-
def __init__(self, mapping):
57+
def __init__(self, mapping, meta=None):
5858
self.__mapping = mapping
59+
self.meta = meta
5960

6061
def __getattr__(self, item):
6162
val = self.__mapping.get(item, None)

src/django_elasticsearch_dsl_drf/viewsets.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,14 @@ def get_object(self):
218218
if not obj and self.ignore:
219219
raise Http404("No result matches the given query.")
220220
# TODO: Do we need obj on != ELASTICSEARCH_GTE_7_0 like below?
221-
return self.dictionary_proxy(obj.to_dict())
221+
if ELASTICSEARCH_GTE_7_0:
222+
dictionary_proxy = self.dictionary_proxy(
223+
obj.to_dict(),
224+
obj.meta
225+
)
226+
else:
227+
dictionary_proxy = self.dictionary_proxy(obj, obj.meta)
228+
return dictionary_proxy
222229
else:
223230
queryset = queryset.filter(
224231
'term',
@@ -234,9 +241,12 @@ def get_object(self):
234241
# May raise a permission denied
235242
self.check_object_permissions(self.request, obj)
236243
if ELASTICSEARCH_GTE_7_0:
237-
dictionary_proxy = self.dictionary_proxy(obj.to_dict())
244+
dictionary_proxy = self.dictionary_proxy(
245+
obj.to_dict(),
246+
obj.meta
247+
)
238248
else:
239-
dictionary_proxy = self.dictionary_proxy(obj)
249+
dictionary_proxy = self.dictionary_proxy(obj, obj.meta)
240250

241251
return dictionary_proxy
242252

0 commit comments

Comments
 (0)