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

Costumizing the ordering values based on the specific value in the column in django-elasticsearch-dsl-drf #261

Open
zahidsw opened this issue Jul 16, 2021 · 0 comments
Labels

Comments

@zahidsw
Copy link

zahidsw commented Jul 16, 2021

@api_view(['POST'])
@permission_classes((IsAuthenticated,))
def api_training_recommendation_view(request, Sku):
try:

    recommendations = Recommendation.objects.all()
except Recommendation.DoesNotExist:
    return Response(status=status.HTTP_404_NOT_FOUND)

try:
    recommendation = Recommendation.objects.filter(Sku=Sku)
    print(recommendation)
except Recommendation.DoesNotExist:
    return Response(status=status.HTTP_404_NOT_FOUND)

if request.method == 'POST':
    serializer_recommendations = RecommendationSerializer(recommendations, many=True)
    serializer_recommendation = RecommendationSerializer(recommendation)
    encoded_data = encoding_data(recommendations,recommendation)
    df_dicts = encoded_data.to_dict().values()
    return Response(df_dicts)
return Response(recommendation.errors, status=status.HTTP_400_BAD_REQUEST)

class PublisherDocumentView(DocumentViewSet):
document = RecommendationDocument
serializer_class = RecommendationElasicSerializer
lookup_field = 'first_name'
fielddata = True
filter_backends = [
FilteringFilterBackend,
OrderingFilterBackend,
CompoundSearchFilterBackend,
FilteringFilterBackend,
OrderingFilterBackend,
DefaultOrderingFilterBackend,
SearchFilterBackend,
SuggesterFilterBackend, # This should be the last backend
]

search_fields = (
    'sku','artikelNr1','artikelNr2', 'statusCode' ,'statusText' ,'saisonRetourenCode','saisonRetourenText','saisonCode','saisonText','geschlechtCode','geschlechtText','rayonCode','rayonText','warenArtCode','warenArtText','wuCode','wuText','waCode','warenGruppe','alterCode','farbe','material','bezeichnung','pictureName','picturePathLocal','kollektion','comCode' ,'lieferant','eKchf','eti','vp','groessenCode','categories','groessen','zlQty',  'productId','published','productName','shortDescription','fullDescription','flag'
)
multi_match_search_fields = (
    'sku','artikelNr1','artikelNr2', 'statusCode' ,'statusText' ,'saisonRetourenCode','saisonRetourenText','saisonCode','saisonText','geschlechtCode','geschlechtText','rayonCode','rayonText','warenArtCode','warenArtText','wuCode','wuText','waCode','warenGruppe','alterCode','farbe','material','bezeichnung','pictureName','picturePathLocal','kollektion','comCode' ,'lieferant','eKchf','eti','vp','groessenCode','categories','groessen','zlQty',  'productId','published','productName','shortDescription','fullDescription','flag'
)
filter_fields = {
    'artikelNr1': 'artikelNr1.raw',
    'artikelNr2': 'artikelNr2.raw',
    'statusText': 'statusText.raw',
    'flag.raw': {
                        'field': 'flag.raw',
                        'lookups': [
                            LOOKUP_FILTER_TERMS,
                            LOOKUP_FILTER_PREFIX,
                            LOOKUP_FILTER_WILDCARD,
                            LOOKUP_QUERY_IN,
                            LOOKUP_QUERY_EXCLUDE,
                        ],
                    },
}
ordering_fields = {
    'flag': 'flag.raw',
}
ordering = ('flag')

I want to costumizing the ordering of this flag field. does anybody has any idea how to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant