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

235
Visualizações
How to schedule posts for carousel in templates using django?

I'm having a hard time to come up with a solution on how to schedule posts for bootstrap carousel with dynamic data in django.

Example:

I created a post for Jan. 1 - Jan. 30 if today is Feb. 1 the post should not be visible on the carousel and vice-versa.

Models.py

class Carousel(models.Model):

above_text = models.CharField(max_length=200, null=True)
below_text = models.CharField(max_length=200, null=True)
image = models.ImageField(upload_to='static/website/images/profile-images', null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
date_start = models.DateTimeField(null=True)
date_end = models.DateTimeField(null=True)

class Meta: 
    verbose_name_plural = 'Carousel'

def __str__(self):
    return f'{self.above_text} Carousel'

Views.py

def index(request):

car = Carousel.objects.all()
faq = FAQ.objects.all()
team = Team.objects.all()
about = About.objects.all()

context = {

    'car' : car,
    'faq' : faq,
    'team': team,
    'about' : about,


}

template_name = 'main/index.html'
return render(request, template_name, context)

Template

              <div class="carousel-inner">
                {% for car in car %}
                <div class="carousel-item {% if forloop.counter0 == 0%} active {% endif %}" data-interval="2">
                    <div class="img-caro">
                        <img src="{{car.image}}" class="img-responsive">
                    </div>
                    <div class="container">
                        <h1>{{car.above_text}}</h1>
                        <p>{{car.below_text}}</p>
                    </div>
                </div>
                {% endfor %}
            </div>
            
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

looks like you want to show the Carousel objects when they are active between date_start and date_end. well, you need to filter your objects. you can either filter them in your view or create a manager for your model.

in your views.py:

car = Carousel.objects.all().filter(date_start__lte=datetime.now(), date_end__gte=datetime.now())

or use a manager:

class CarouselManager(models.Manager):

    def get_active(self):
        return super(CarouselManager, self).all().filter(date_start__lte=datetime.now(), date_end__gte=datetime.now())
about 4 years ago · Juan Pablo Isaza Relatório
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