0% found this document useful (0 votes)
3 views

Assignment 4 Q2

The document outlines a Django implementation for displaying a list of customers and the furniture they have purchased. It includes the code for views, HTML templates for the customer list and furniture details, and URL routing. The customer list allows users to click on furniture names to view detailed information about each item.

Uploaded by

Shweta Nirmanik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 4 Q2

The document outlines a Django implementation for displaying a list of customers and the furniture they have purchased. It includes the code for views, HTML templates for the customer list and furniture details, and URL routing. The customer list allows users to click on furniture names to view detailed information about each item.

Uploaded by

Shweta Nirmanik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 4

Q2. For the database Furniture mentioned in the previous question, create ListView
that displays list of customers with furniture names they have purchased. On
clicking furniture, furniture details should be displayed.

Solution
Views.py
from django.shortcuts import render

# Create your views here.


from assign4.models import Customer,Furniture
from django.views import generic

class CustomerListView(generic.ListView):
model = Customer
template_name = "customer_list.html"

class FurnitureDetailView(generic.DetailView):
model = Furniture
template_name = "furniture_detail.html"

customer_list.html
<html>
<head>
<title>Customer List</title>
</head>
<body>
<h1>Customers and Their Purchased Furniture</h1>
<ul>
{% for customer in customer_list %}
<li>{{ customer.customername }}</li>
<ul>
{% for furniture in customer.purchase.all %}
<li><a href= "/furniture_detail/ {{furniture.pk}}" >
{{furniture.furniture_name}} </a></li>
{% endfor %}
</ul>
{% endfor %}
</ul>
</body>
</html>

Furniture_detail.html
<html>
<head>
<title>Furniture Detail</title>
</head>
<body>
<h1>Furniture{{ furniture.furniture_name }}</h1>
<p>Type: {{ furniture.furniture_type }} </p>
<p>Features: {{ furniture.features }}</p>
<p>Price: {{ furniture.price }}</p>
<p>Material Used: {{ furniture.material_used }}</p>
</body>
</html>

Urls.py
from assign4.views import CustomerListView, FurnitureDetailView
urlpatterns = [
path('customers/', CustomerListView.as_view()),
path('furniture/<int:pk>/', FurnitureDetailView.as_view()),

Output

You might also like