Django : Why is string condition False if select_related field not coated in STR()?

47 views Asked by At

In my function, my query is :

 mappings = MappingField.objects.filter(
        fl_fiche_header_flow_id=fhf.pk).order_by('fl_fiche_inside_field_position')
            .select_related('fl_fiche_header_flow')

Why when I print (label is models.Charfield):

mapping.fl_fiche_header_flow.label

I got well : appli1

And when I check the condition :

if mapping.fl_fiche_header_flow.label == 'appli1':

I obtain False?

Why do I need to str(mapping.fl_fiche_header_flow.label) in my condition for getting true?

Is it only due to select_related or is it a general principle ?

0

There are 0 answers