J
J
Jekson2018-07-26 15:53:51
Django
Jekson, 2018-07-26 15:53:51

How to write a condition that depends on the result of a function?

How to write an if condition correctly, depending on the result of executing the filter_by_type function ?

def filter_by_type(self, request, queryset, social_networks):
        type = request.query_params.get('type', None)
        if type is None:
            return queryset
        social_network_type = social_networks.get(type.upper(), None)
        if social_network_type is not None:
            queryset = queryset.filter(content_type=social_network_type.pk)
        return queryset

There are several types of social_network_type like youtube, instagram, vk etc. I want to make another function run only if social_network_type = youtube.
Something like
if social_network_type = youtube:
    pass

but bound to the result of filter_by_type , which returns queryset/ as a response

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-07-26
@Lepilov

if all([social_network_type is not None,social_network_type == 'youtube'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question