Filter dates using foreignkey Django and Python

I need to filter a variable between two models using a foreign key.

models.py

class Vuelo(models.Model):
    fecha_de_vuelo = models.CharField(max_length=50)
    .......

class Novedad(models.Model):
    fecha_de_vuelo_novedad = models.ForeignKey(Vuelo, on_delete=models.CASCADE, related_name="fecha_de_vuelo_novedad", null=True, editable=False) 
    comandante_novedad = ......

view.py

def buscar_reporte_demoras(request):
        
        if request.method == "GET": 
            
            inicio = request.GET.get("fecha_inicio", None)
            fin = request.GET.get("fecha_fin", None)
            
            criterio_1 = Q(fecha_de_vuelo_novedad__fecha_de_vuelo__gte = inicio)
            criterio_2 = Q(fecha_de_vuelo_novedad__fecha_de_vuelo__lte = fin)

            busqueda = Novedad.objects.all()
            busqueda_con_filtro_fechas = busqueda.filter(criterio_1 & criterio_2)
            


            context = {

                'lista_vuelos': busqueda_con_filtro_fechas,
                'criterio_fecha_inicio': inicio,
                'criterio_fecha_fin': fin,  
            }
        
        return render(request, '.........html', context)

The problem is that when I try to filter by "fecha_de_vuelo" using related_name = "fecha_de_vuelo_novedad" it doesn't give me any results.

What would the error be?

Thank you for your help.

Вернуться на верх