8.1. Creating the homepage banners
First, we'll create a Banner
class to manage the banners on the homepage. Each banner will have several properties, including an image, an output link (which determines where users are redirected upon clicking), and an active state to indicate whether the banner's link is currently enabled or not.
class Banner(models.Model) :
image = models.ImageField(null=True, blank=True)
link_output = models.CharField(max_length=400, null=True, blank=True) #? where the user will be sent after clicking the banner
active = models.BooleanField(default=False) #? whether the link is currently active or not
def __str__(self):
return f"{self.link_output} - Active: {self.active}"
Additionally, we implemented a __str__
method to enhance object representation, providing a clear overview of where each banner redirects users and whether it is currently active.
Now we will migrate the changes:
python manage.py makemigrations
python manage.py migrate
Lastly, we will register the new Banner class inside our admin.py
file so it can appear on the admin page:
admin.site.register([Categoric, Client, Type, Product, ItemStock, Order, OrderedItem, Adres, Banner])

Last updated