Skip to content

Commit

Permalink
Merge pull request #193 from Ircam-WAM/develop
Browse files Browse the repository at this point in the history
add "id" as an optional value of the serializer fields returning the haystack internal id
  • Loading branch information
decibyte authored Oct 2, 2024
2 parents fd2b72e + feb4871 commit 6883b1e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drf_haystack/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def get_fields(self):
if declared_fields:
for field_name in declared_fields:
field_mapping[field_name] = declared_fields[field_name]

if "id" in fields:
field_mapping['id'] = HaystackCharField()

return field_mapping

def to_representation(self, instance):
Expand All @@ -236,7 +240,7 @@ def to_representation(self, instance):
if index == current_index:
ret[field] = ret[orig_field]
del ret[orig_field]
elif field not in chain(instance.searchindex.fields.keys(), self._declared_fields.keys()):
elif field not in chain(instance.searchindex.fields.keys(), self._declared_fields.keys(), ["id"]):
del ret[orig_field]

# include the highlighted field in either case
Expand Down

0 comments on commit 6883b1e

Please sign in to comment.