Carausel model code
model.py
from django.db import models
# Create your models here.
class Carausel(models.Model):
image = models.ImageField(upload_to='pics/%y/%m/%d/')
title = models.CharField(max_length=100)
sub_title = models.CharField(max_length=100)
featured = models.BooleanField(null=True, blank=True)
def __str__(self):
return self.title
views.py
def index(request):
allPosts= Post.objects.all()
featured = Post.objects.filter(featured=True)
latest = Post.objects.order_by('-timestamp')[0:3]
most_recent = Post.objects.order_by('-timestamp')[:5]
# slide = Carausel.objects.all()
slide_featured = Carausel.objects.filter(featured=True)
# subscriptins signup
if request.method=="POST":
email=request.POST['email']
if len(email)<3: a="" allposts="" code="" context="" else:="" email="" featured="" fully="" have="" index.html="" latest="" lease="" messages.error="" messages.success="" most_recent="" object_list="" ou="" render="" request="" return="" signup.save="" signup="Signup(email=email)" slide_featured="" subscribe="" success="" type="" valid="" website="">3:>
index.html
<div id="carouselExampleIndicators" class="container carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li> <li data-target="#carouselExampleIndicators" data-slide-to="1"></li> <li data-target="#carouselExampleIndicators" data-slide-to="2"></li> </ol> <div class="carousel-inner"> {% for object in slide_featured %} <div class="carousel-item {% if forloop.first %} active {% endif %}"> <img src="{{object.image.url}}" class="d-block w-100" alt="..."> <div class="carousel-caption d-none d-md-block"> <h5>{{object.title}}</h5> <p>{{object.sub_title}}</p> </div> </div> {% endfor %} </div> <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a></div>