Hello. Can someone review this and let me know what I’m missing? I’ve specified the information in models.py, views.py, urls.py, settings.py, and plans.html. I have the folders in the directory showing the pictures. I have the admin page set up to upload the information and pictures. The info and pictures are shown and save into the database.
models.py
class Plans(models.Model):plan_number = models.CharField(max_length=50, blank=False, unique=True)slug = models.SlugField(max_length=50, unique=True)square_footage = models.CharField(max_length=50, blank=False)bedrooms = models.CharField(max_length=50, blank=False)bathrooms = models.CharField(max_length=50, blank=False)stories = models.CharField(max_length=50, blank=False)garage_stalls = models.CharField(max_length=50, blank=False)house_width = models.CharField(max_length=50, blank=False)house_depth = models.CharField(max_length=50, blank=False)description = models.TextField(max_length=500, blank=True)plan_price = models.DecimalField(max_digits=10, decimal_places=2)images = models.ImageField(upload_to='photos/plans')is_available = models.BooleanField(default=True)house_style = models.ForeignKey(HouseStyle, on_delete=models.CASCADE)created_date = models.DateTimeField(auto_now_add=True)modified_date = models.DateTimeField(auto_now=True)class Meta:verbose_name = "plan"verbose_name_plural = 'plans'def get_url(self):return reverse('plans', args=[self.house_style.slug, self.slug])def __str__(self):return self.plan_number
views.py
def plans_for_sale(request, house_style_slug=None):house_styles = Noneplans = Noneif house_style_slug != None:house_styles = get_object_or_404(HouseStyle, slug=house_style_slug)plans = Plans.objects.filter(category=house_styles, is_available=True)paginator = Paginator(plans, 1)else:plans = Plans.objects.all().filter(is_available=True).order_by('-plan_number')paginator = Paginator(plans, 12)page = request.GET.get('page')paged_plans = paginator.get_page(page)plan_count = plans.count()context = {'plans': paged_plans,'plan_count': plan_count,}return render(request, 'plans/plans.html', context)def plan_number(request, house_style_slug, plan_slug):plan_card = Plans.objects.get(house_style__slug=house_style_slug, slug=plan_slug)plan_gallery = PlanGallery.objects.filter(product_id=plan_card.id)context = {'plan_card': plan_card,'plan_gallery': plan_gallery,}return render(request, 'plans/plan_number.html', context)
plans.html
<section class="bg-white text-black pb-5 pb-lg-6"><div class="container py-2"><ul class="list-unstyled row row-cols-1 row-cols-md-2 gy-4 mt-n6 mb-md-5 thumb"><li class="col"><div class="card bg-white border-0 img-rising"><img src="{{ plan_card.images.url }}" class="card-img-top img-fluid" alt="Clean design, better experience" width="640" height="400"><div class="card-body"><div class="small text-secondary text-uppercase mb-1">Plan # {{ plan_card.plan_number }}</div><h2 class="card-title h4"><a href="{{ plan_card.images.url }}" class="link-body-emphasis stretched-link" target="mainImage" src="{{ plan_card.images.url }}" alt="Plan Card Image">{{ plan_card.house_style }}</a>{% for i in plan_gallery %}<a href="{{ i.image.url }}" target="mainImage"><img src="{{ i.image.url }}" alt="Plan Card Image"></a>{% endfor %}</h2><div class="small text-secondary mb-2">{{ plan_card.modified_date }}</div><p class="card-text text-dark">This is a sample intro paragraph and can be used to introduce readers to your article.</p></div></div></li></ul>
