Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
Django non-UTC timezone aware dates in queryset

I'm running Django with Postgres.

  1. I want timezone-aware datetime objects returned from the database.
  2. I want all the datetimes in querysets to be set to the user's locale, not UTC.
  3. I can get timezone aware dates in querysets if I set USE_TZ=True in settings, but they are all in UTC.
  4. If USE_TZ=False and set TIME_ZONE='America/New_York', I can get my results back in the user's correct locale, but the dates are all naive.

How can I get timezone-aware datetimes in the user's locale returned in my querysets by default?

Looping through the results and setting them all manually is not an option. It's way too slow.

I'm not interested in Django's ability to convert the dates to the user's timezone at render time, i.e. in a template or serializer. I need the timezone shifted dates before the view for processing.

Note: I think I've read the entire Internet on this topic and found one SO post (Ouput timezone aware django datetime fields without filters) that comes close to the same problem I want to solve, but no solution was provided.

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda