I am working on a practice project to create 3 separate pages that is Brand Page, Car Model Page and Car Model Variant detail page.
I am working on a project with three models car brands, car model, car model variantsWhen an user opens the Car model page they should see the list of variants in that car model
class BrandName(models.Model): FullName = models.CharField(max_length= 100) Slogan = models.CharField(max_length = 255) slug = models.SlugField(unique=True) def __str__(self): return f"{self.FullName}"class CarModel(models.Model): Brand = models.ForeignKey(BrandName, on_delete = models.CASCADE,null=True, related_name = "brands") ModelName = models.CharField(max_length = 200) slug = models.SlugField(unique=True) def __str__(self): return f"{self.ModelName}"class CarModelVariant(models.Model): ModelVariantName = models.CharField(max_length = 100) Brandname = models.ForeignKey(BrandName, on_delete = models.CASCADE, null = True, related_name="brands1") Model1 = models.ForeignKey(CarModel, on_delete = models.CASCADE, null = True, related_name = "model1") Doors = models.IntegerField SeatingCapacity = models.IntegerField def __str__(self): return f"{self.ModelVariantName}"
**In views.py of the app
**
from django.shortcuts import renderfrom django.http import HttpResponsefrom . models import CarModelVariant, CarModel, BrandNamefrom django.views.generic import ListView, DetailViewclass CarModelVariantView(ListView): template_name = "carlist.html" model = CarModelVariant def get_queryset(self): list_model = super().get_queryset() data = list_model.filter(Model1= CarModel_instance) return data
In urls.py of the app
`from django.urls import pathfrom . import views
urlpatterns = [path("slug:slug", views.CarModelVariantView.as_view())]`
I am facing a blank page while loading carlist.html template
`{% extends "base.html" %}{% block title%}Car Brand Variants List{% endblock%}{% block content %}<ul> {% for variant in data %}<li>{{ variant }}</li> {% endfor %}</ul>{% endblock %}`