Pick values between two dates and display in the Django template

Asked

Viewed 250 times

2

I have two models, flow and report, in the stream there is a date field, and in the report there are two fields, start date and end date, I want to make the report show the records in the flow between the dates selected in the report, the way I did not return any record, follow the code:

model report

class Relatorio(models.Model):

data_inicio = models.DateField(default=timezone.now)
data_fim  = models.DateField(default=timezone.now)
def imprimir(self):
    return mark_safe("<a target='_blank' href='%s'>Imprimir</a>" % self.get_absolute_url())
    imprimir.allow_tags = True
def get_absolute_url(self):
    return reverse('fluxo_list', args=[self.pk, ])

The flow model consists only of the date field

View method:

def get_context_data(self, **kwargs):
    inicio = self.kwargs.get('data_inicio')
    fim = self.kwargs.get('data_fim')
    return dict(
        super(RelatorioDetail, self).get_context_data(**kwargs),   

        fluxo_list = Fluxo.objects.filter(data__range=[inicio, fim])


    )
  • Lucas, your question was not clear to me. And if it is possible to put the flow model would also help.

  • Question still very obscure, where is this such "report"? Cade a template? Why not post the whole view?

  • Have you looked if it is not the format of the dates? Because in the bank it saves as 2020-20-03 and the entry was 20/03/2020

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.