Django - how to create proper categories and subcategories - python

I am currently working on a store made in Django and I have a problem because I have a model for Category as well as Subcategory. The problem is that I don't really know what I did wrong, because in the html file I try to call both categories and subcategories, but in each category all subcategories are displayed, instead of belonging to a specific category. I would like to ask for your help, and check, if files below are correctly written. Thanks in advance
models.py
from django.db import models
from django.urls import reverse
# Class model for category
class Category(models.Model):
name = models.CharField(max_length=200,
db_index=True)
slug = models.SlugField(max_length=200,
db_index=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('selcorshop:product_list_by_category',
args=[self.slug])
# Class model for subcategory
class Subcategory(models.Model):
category = models.ForeignKey(Category,
related_name='category',
on_delete=models.CASCADE)
name = models.CharField(max_length=200,
db_index=True)
slug = models.SlugField(max_length=200,
db_index=True)
class Meta:
ordering = ('name',)
verbose_name = 'subcategory'
verbose_name_plural = 'subcategories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('selcorshop:product_list_by_subcategory',
args=[self.slug])
# Class model for product
class Product(models.Model):
subcategory = models.ForeignKey(Subcategory,
related_name='products',
on_delete=models.CASCADE)
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True)
image = models.ImageField(upload_to='products/%Y/%m/%d',
blank=True)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ('name',)
index_together = (('id', 'slug'),)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('selcorshop:product_detail',
args=[self.id, self.slug])
views.py
from django.shortcuts import render, get_object_or_404
from .models import Category, Subcategory, Product
from cart.forms import CartAddProductForm
# View for product list in site
def product_list(request, category_slug=None, subcategory_slug=None):
category = None
categories = Category.objects.all()
subcategory = None
subcategories = Subcategory.objects.all()
products = Product.objects.filter(available=True)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
subcategory = get_object_or_404(Subcategory, slug=subcategory_slug)
products = products.filter(category=category)
return render(request,
'selcorshop/product/list.html',
{'category': category,
'categories': categories,
'subcategory': subcategory,
'subcategories': subcategories,
'products': products})
# View for single product
def product_detail(request, id, slug):
product = get_object_or_404(Product,
id = id,
slug = slug,
available = True)
# Add to cart button
cart_product_form = CartAddProductForm()
return render(request,
'selcorshop/product/detail.html',
{'product': product,
'cart_product_form': cart_product_form})
urls.py
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
app_name = 'selcorshop'
urlpatterns =[
path('', views.product_list, name='product_list'),
path('<slug:category_slug>/', views.product_list, name='product_list_by_category'),
path('<slug:subcategory_slug>/', views.product_list, name='product_list_by_subcategory'),
path('<int:id>/<slug:slug>/', views.product_detail, name='product_detail'),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
list.html
{% extends "selcorshop/base.html" %}
{% load static %}
{% block title %}
{% if category %}{{ category.name }}{% else %}Produkty{% endif %}
{% endblock %}
{% block content %}
<div class="row">
<div id="sidebar" class="col-2">
<div class="d-flex flex-column flex-shrink-0 p-3 text-white bg-dark" style="width: 280px;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="32" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"/>
</svg>
<span class="fs-4">Kategorie</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li {% if not category %}class="nav-item" {% endif %}>
Wszystkie
</li>
<div class="dropdown">
**{% for c in categories %}
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<li {% if category.slug == c.slug %} {% endif %}>
{{ c.name }}
</li>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{% for s in subcategories %}
<a class="dropdown-item" href="#">
<li {% if subcategory.slug == s.slug %} {% endif %}>
{{ s.name }}
</li>
</a>
{% endfor %}
</div>
{% endfor %}**
</div>
</ul>
<!-- <ul class="nav nav-pills flex-column mb-auto">-->
<!-- <li {% if not category %}class="nav-item" {% endif %}>-->
<!-- Wszystkie-->
<!-- </li>-->
<!-- {% for c in categories %}-->
<!-- <li {% if category.slug == c.slug %} {% endif %}>-->
<!-- {{ c.name }}-->
<!-- </li>-->
<!-- {% endfor %}-->
<!-- </ul>-->
</div>
</div>
<div id="main" class="product_list col-10">
<h2>{% if category %}{{ category.name }}{% else %}Produkty{% endif %}</h2>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static 'img/no_image.png' %}{% endif %}" alt="Obraz">
</a>
{{ product.name }}<br>
{{ product.price }} zł.
</div>
{% endfor %}
</div>
</div>
{% endblock %}

So after seeing your code I guess you want to create a dropdown menu in which all the subcategory list related to category open right so for that you can call it with related name which you pass in your subcategory model a use it in your HTML like that
{% for c in category_list %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false" style="font-weight:500">
<strong>{{ c.name }}</strong>
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDarkDropdownMenuLink">
{% for subcategory in c.category.all %}
<li><a class="dropdown-item" href="#">{{ subcategory.name }}</a>
{% endfor %}
</ul>
</li>
{% endfor %}
this has to solve your problem andd tell me if you still got any issue

Related

Book object is not iterable: Trying to display similar objects of an instance based on a field

I am working on a library project that displays books and each both is in a category(history, math, adventure, etc). On the detailed view of a book, I want a link (with "See similar books in this category") that will redirect the user to other books of the same category of the current book. So if the detail page of a book has a category of "history", the link will direct to other books in the "history" category. The redirection is to another template (Addon: In helping me out, I would love to display the "similar books" in the same page, not a different page)
error details
TypeError at /search/similar/bootsrtap/
'Book' object is not iterable
models.py
class Category(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('index')
choices = Category.objects.all().values_list('name', 'name')
choice_list = []
for item in choices:
choice_list.append(item)
class Book(models.Model):
title = models.CharField(max_length=255)
author = models.CharField(max_length=255)
category = models.CharField(max_length=255, choices=choice_list)
slug = models.SlugField(max_length=100, unique=True)
def __str__(self):
return self.author + ": " + self.title
def get_absolute_url(self):
return reverse('detail', kwargs={'slug': self.slug})
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
return super().save(*args, **kwargs)
def similar_book(self):
return Book.objects.filter(category=self.category)
urls.py
urlpatterns = [
path('detail/<slug:slug>/', BookDetail.as_view(), name='detail'),
path('search/similar/<slug:slug>/', views.search_similar_results, name='search_similar_results'),
views.py
def search_similar_results(request, slug):
books = get_object_or_404(Book, slug=slug)
books.similar_book()
return render(request, 'book/similar_results.html', {'books': books})
class BookDetail(generic.DetailView):
model = Book
context_object_name = 'book'
template_name = 'book/detail.html'
clickable link to lead to the template
Click to see Similar books in this category</h3>
<div class="row">
template
<div class="row">
{% if books %}
{% for book in books %}
<h2>Similar Books in {{ book.category } Category}</h2>
<figure class="col-lg-3 col-md-4 col-sm-6 col-12 tm-gallery-item animated bounce infinite">
<a href="{{ book.get_absolute_url }}">
<div class="tm-gallery-item-overlay">
{% if book.cover %}
<img src="{{ book.cover.url }}" alt="Image" class="img-fluid tm-img-center">
{% endif %}
<p class="small font-italic">Author: {{ book.author }}</p>
<p class="small font-italic text-left">Title: {{ book.title }}</p>
<p class="small font-italic">Category: {{ book.category }}</p>
</div>
</a>
</figure>
{% endfor %}
{% else %}
<p>There are No Available Books</p>
{% endif %}
</div>
details.html
<div class="tm-main-content no-pad-b">
<!-- Book Detail Page Display -->
<section class="row tm-item-preview">
{% if book.cover %}
<div class="col-md-6 col-sm-12 mb-md-0 mb-5">
<img src="{{ book.cover.url }}" alt="Image" class="img-fluid tm-img-center-sm card-img-top">
<h2>Title {{ book.title }}</h2>
</div>
{% else %}
<p>No book cover</p>
{% endif %}
</section>
<!-- Similar Books Display by Category -->
<div class="tm-gallery no-pad-b">
<h3 style="color: white; text-align: center;">Similar books you might be interested in</h3>
<div class="row">
{% for item in similar_book%}
<figure class="col-lg-3 col-md-4 col-sm-6 col-12 tm-gallery-item">
<a href="{{ book.get_absolute_url }}">
<div class="tm-gallery-item-overlay">
<img src="{{ book.cover.url }}" alt="Image" class="img-fluid tm-img-center">
</div>
<p class="tm-figcaption">Title: {{ book.title}}</p>
<p class="tm-figcaption">Category: {{ book.category }}</p>
</a>
</figure>
{% endfor %}
</div>
</div>
</div>
You need to pass the result of the similar books to the template, so:
def search_similar_results(request, slug):
book = get_object_or_404(Book, slug=slug)
books = book.similar_book()
return render(request, 'book/similar_results.html', {'books': books})
In the DetailView, you can pass the `similar books with:
class BookDetail(generic.DetailView):
model = Book
context_object_name = 'book'
template_name = 'book/detail.html'
def similar_books(self):
return self.object.similar_book()
Then in the template we work with:
{% for item in view.similar_books %}
<!-- … -->
{% endfor %}

Django sorting by a category and pagination combining both in one function view

I'm trying to sort my projects by categories: all, css, HTML, Django, and so on. and also trying to add pagination when showing all projects have a limit of 6 projects per page. I'm stuck and have trouble combining either the pagination work or the filter/ sorting the items work, here's my code. Please Help :)
models.py
class Category (models.Model):
category_name = models.CharField(max_length=150)
slug = models.SlugField(unique=True)
class Meta:
ordering = ('-category_name',)
def __str__(self):
return self.category_name
def get_absolute_url(self):
return reverse('mainpages:project_by_category', args=[self.slug])
class Project(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, default='', null=True)
title = models.CharField(max_length=100)
description = models.TextField()
technology = models.CharField(max_length=20)
proj_url = models.URLField(max_length=200, blank=True)
blog_link = models.URLField(max_length=200, blank=True)
image = models.ImageField(default='post-img.jpg', upload_to='proj-img')
class Meta:
ordering = ('-title',)
def __str__(self):
return self.title
view.py
def portfolioView(request, category_slug=None):
# added
category = None
categories = Category.objects.all()
# filtering by project
projs = Project.objects.all()
# paginator added
projects = Project.objects.all()
paginator = Paginator(projects, 3)
page = request.GET.get('page')
try:
projects = paginator.page(page)
except PageNotAnInteger:
projects = paginator.page(1)
except EmptyPage:
projects = paginator.page(paginator.num_pages)
# added
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
projs = projs.filter(category=category)
#
return render(request, 'mainpages/portfolio.html', {
'category': category,
'categories': categories,
'projects': projects,
'page': page,
'projs': projs,
})
def projectDetail(request, pk):
project = Project.objects.get(pk=pk)
context = {
'project': project
}
return render(request, 'mainpages/portfolio-detail.html', context)
pagination.html
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
Previous
{% endif %}
<span class="current">
Page {{ page.number }} of {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
Next
</span>
{% endif %}
</div>
porftfolio.html
{% extends 'mainpages/base.html' %}
{% load static %}
{% block content %}
<!-- -->
<section class="portfolio-section">
<!-- -->
<div class="portfolio-info">
<h1>PORTFOLIO</h1>
<p>Industry's so electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop</p>
</div>
<!-- -->
<div class="category-container">
<div class="category-wrapper">
<div class="category-title">
<h3>Catergories</h3>
</div>
<!-- -->
<div class="category-links">
<ul>
<li>ALL</li>
{% for c in categories %}
<li>
{{ c.category_name}}
</li>
{% endfor %}
</ul>
</div>
<div>
<h1>
{% if category %}
<p class="center-category">All {{ category.category_name }} Projects</p>
{% else %}
<p class="center-category">All Projects</p>
{% endif %}
</h1>
{% for p in project %}
{{ p.title }}
{% endfor %}
</div>
<!-- -->
</div>
</div>
<div class="work-container">
<div class="work-wrapper">
{% for project in projects %}
<div class="work-links">
<div class="card">
<img class="work-img" src="{{ project.image.url }}" alt="">
<h6 class="title">{{ project.title }}</h6>
<span> {{ project.description |truncatechars:50 }}</span>
<button class="works-btn">
View Project
</button>
</div>
</div>
{% endfor %}
</div>
</div>
{% include 'mainpages/pagination.html' with page=projects %}
</section>
{% endblock %}

django.db.utils.OperationalError: no such column: home_post.assign_to_id

I want to assign a task to one of the users who commented on the post. But when I try to go on post_detail.html an error occurs, and i.e.
OperationalError at /home/
no such column: home_post.assign_to_id
PS: I have done python manage.py makemigrations and python manage.py migrate
So, here is the code snippet. I can give more information if needed. Thanks in advance!
views.py
def SaveAssigned(request):
if request.method == "POST":
if request.POST.get('assigned'):
savevalue = Post()
savevalue.assign_to = request.POST.get('assigned')
savevalue.save()
return render(request, 'post_detail.html')
else:
return render(request, 'post_detail.html')
class PostDetailView(DetailView):
model = Post
# template_name = 'home/post_detail.html'
def get_context_data(self, *args, **kwargs):
post_available = get_object_or_404(Post, id=self.kwargs['pk'])
cat_menu = Category.objects.all()
context = super(PostDetailView, self).get_context_data()
context["cat_menu"] = cat_menu
return context
urls.py
urlpatterns = [
path('', PostListView.as_view(), name='home'),
path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
path('post/new/', PostCreateView.as_view(), name='post-create'),
path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
path('post/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),
path('post/<int:pk>/comment/', AddCommentView.as_view(), name='add-comment'),
path('add_category/', AddCategoryView.as_view(), name='add-category'),
path('category/<str:cats>/', CategoryView, name='category'),
path('category-list/', CategoryListView, name='category-list'),
]
models.py
class Post(models.Model):
title = models.CharField(max_length = 100)
snippet = models.CharField(max_length= 200)
content = RichTextField(blank=True, null=True)
date_posted = models.DateTimeField(default = timezone.now)
author = models.ForeignKey(User, on_delete= models.CASCADE)
category = models.CharField(max_length=255, default='Coding')
assign_to = models.ForeignKey(User,related_name='assign_to', on_delete=models.CASCADE, null=True)
def __str__(self):
return self.title + ' | ' + str(self.author)
def get_absolute_url(self):
return reverse('home')
post_detail.html
{% extends 'users/base.html' %}
{% block body %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ object.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ object.author }}</a>
<small class="text-muted">{{ object.category }}</small>
<small class="text-muted" style="float: right;">{{ object.date_posted|date:"F d, Y" }}</small>
</div>
<h2 class="article-title">{{ object.title }}</h2>
<p class="article-content">{{ object.content|safe }}</p>
</div>
</article>
{% if object.author == user %}
<div>
<a class="btn btn-outline-secondary bt-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update</a>
<a class="btn btn-outline-danger bt-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete</a>
<a class="btn btn-outline-primary bt-sm mt-1 mb-1" style="float: right;" href="">Done</a>
</div>
<form method="POST">
{% csrf_token %}
<select name="assigned">
<option selected disabled="true"> Select User</option>
{% if not post.comments.all %}
<option>NA</option>
{% else %}
{% for comment in post.comments.all %}
<option>{{ comment.author }}</option>
{% endfor %}
{% endif %}
</select>
<input type="submit" value="Assign" name="">
</form>
{% endif %}
<br>
<hr>
<h2>Comment Section</h2>
<br>
{% if not post.comments.all %}
No Comments yet
<br>
Be the first Ont to Comment!
{% else %}
Add a comment
<br>
{% for comment in post.comments.all %}
<strong>
{{ comment.author }} - {{ comment.date_added }}
</strong>
<br>
{{ comment.body }}
<br><br>
{% endfor %}
<hr>
{% endif %}
<br><br>
{% endblock %}
This error occurs when your model does not contain the specific column and you are trying to add the value in that model with a specific column name.
You can solve this by following steps -
Step - 1. python manage.py makemigration
Step - 2. python manage.py migrate

i want to display the list of pruducts based on the choice of the category chosing -django

so i want to khow what i have to add in the urls.py and in the views.py to add this functionnality: if i click in one of this categories here my categories display some products based on the category chosen.
and this the models.py
class Product(models.Model):
name=models.CharField(max_length=200,null=True)
price=models.DecimalField(max_digits=7,decimal_places=2)
digital=models.BooleanField(default=False,null=True,blank=True)
image=models.ImageField(blank=True,null=True,upload_to ='images/',default="images/default.jpg")
categories = models.ForeignKey(Category,on_delete=models.CASCADE,blank=True, null=True)
def __str__(self):
return self.name
#property
def imageURL(self):
if self.image and hasattr(self.image, 'url'):
return self.image.url
else:
return '/static/images/default.png'
class Category(models.Model):
name = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, unique=True,
help_text='Unique value for product page URL, created from name.')
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'categories'
ordering = ['-created_at']
verbose_name_plural = 'Categories'
def __unicode__(self):
return self.name
and this is the template :
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<form method="get" action="">
{% for c in active_categories %}
<a class="dropdown-item" href='#'>{{ c.name }}</a>
{% endfor %}
<a class="dropdown-item" href="#">something else</a>
</form>
</div>
This is simplest way. You can change code as per requirement.
urls.py
from . import views # import views.py file
urlpatterns = [
path('product_list/<id>', views.product_list, name='product_list'),
]
views.py
def product_list(request, id):
products = Product.objects.filter(categories__pk=id)
context = {
'products': products,
}
return render(request, 'product_list.html', context)
link template (Check the change in link)
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<form method="get" action="">
{% for c in active_categories %}
<a class="dropdown-item" href="{% url 'product_list' id=c.pk %}">{{ c.name }}</a>
{% endfor %}
<a class="dropdown-item" href="#">something else</a>
</form>
</div>
product_list.html
Your regular html things +
{% for product in products %}
<p>{{ product.name }}</p>
<p>{{ product.price }}</p>
{% empty %} # in case there is no product in this category
<p>No product available for this category</p>
{% endfor %}
I hope this will help. Please comment if get any error.
If you products to load without refreshing the page, you can use ajax. Reply if need that.
You can try this:
views.py
def my_view(request):
category_id = request.GET.get('category_id')
context = {}
if category_id:
products = Product.objects.filter(categories__id=category__id)
context["products"] = products
return render(request, 'template', context)
template
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<form method="get" action="">
{% for c in active_categories %}
<a class="dropdown-item" href='?category_id={{ c.id }}'>{{ c.name }}</a>
{% endfor %}
<a class="dropdown-item" href="#">something else</a>
</form>
</div>

The variables for my Job model is not showing

I have created a Job model that contains Member and Manager info. It looks great imo. I created a class based view that translates the job if the user has one. Right now it's not showing. It just shows as a blank with an empty image file. I don't know what I did wrong or if I mistakenly used the wrong variables in the html file.
Here's my views.py:
from django.shortcuts import render
from django.views.generic import ListView, CreateView
from .models import Job
from profiles.models import User
# Create your views here.
class jobs(ListView):
model = Job
template_name = 'users/user_jobs.html'
context_object_name = 'jobs'
def get_queryset(self):
return Job.objects.filter(member__member=self.request.user)
class createjob (CreateView):
model = Job
fields = ['member','title', 'description', 'file'
My Models.py:
from django.db import models
from profiles.models import User
# Create your models here.
class Points (models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
points = models.IntegerField(default=0, null=False)
def __str__(self):
return self.user.username
class Profile (models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.png',upload_to='profile_pics')
def __str__(self):
return f'{self.user.username}Profile'
class Manager (models.Model):
name = models.CharField(max_length=30, blank=True, null=True)
manager = models.ForeignKey(User,on_delete=models.CASCADE)
def __str__(self):
return self.name
class Member (models.Model):
name = models.CharField(max_length=30, blank=True, null=True)
manager = models.ForeignKey(Manager, on_delete=models.CASCADE)
member = models.ForeignKey(User,on_delete=models.CASCADE)
def __str__(self):
return self.name
class Job (models.Model):
manager = models.OneToOneField(Manager, on_delete=models.CASCADE)
member = models.OneToOneField(Member, on_delete=models.CASCADE)
title = models.CharField(max_length=30, blank=False, null=False)
description = models.TextField()
datePosted = models.DateTimeField (auto_now = True)
file = models.FileField(null=True, blank=True,upload_to='job_files')
def __str__(self):
return self.title
And user_jobs.html:
{% extends "profiles/base.html" %}
{% block content %}
<article class="media content-section">
<img class="rounded-circle article-img"src="{{ jobs.manager.profile.image.url}}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ objects.job.Manager }}</a>
<small class="text-muted">{{jobs.datePosted|date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="#">{{ jobs.title }}</a></h2>
<p class="article-content">{{ jobs.description }}</p>
</div>
</article>
{% if is_paginated %}
{% if page_obj.has_previous %}
<a class="btn btn-outline-info mb-4"href="?page=1"> First</a>
<a class="btn btn-outline-info mb-4"href="?page={{ page_obj.previous_page_number }}"> Previous</a>
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
<a class="btn btn-outline-info mb-4"href="?page={{ num }}"> {{ num }}</a>
{% elif num > page.obj.number|add:'-3' or num < page.obj.number|add:'3' %}
<a class="btn btn-outline-info mb-4"href="?page={{ num }}"> {{ num }}</a>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<a class="btn btn-outline-info mb-4"href="?page={{ page_obj.next_page_number }}"> Next </a>
<a class="btn btn-outline-info mb-4"href="?page={{ page_obj.paginator.num_pages }}"> Last </a>
{% endif %}
{%endif%}
{% endblock content %}
TIA for the help guys.
you have to loop through the object list output in your list template to see the out put
{% for object in jobs %}
{{ object.title }}
{% endfor %}

Categories