0% found this document useful (0 votes)
17 views14 pages

Nidhi Lab7 Grp4

This document contains code for a web application that functions as an online car store. It includes code for models, forms, URLs, views, and templates. Stylesheets are included to control design elements like colors, fonts, and layout. Templates extend a base template and include blocks for common elements. Views render templates to display lists of vehicles, vehicle details, an about page, and order form. URLs are named to map to views. Models define vehicles, orders, and car types with fields. Forms are created for ordering and contact.

Uploaded by

Nidhi Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

Nidhi Lab7 Grp4

This document contains code for a web application that functions as an online car store. It includes code for models, forms, URLs, views, and templates. Stylesheets are included to control design elements like colors, fonts, and layout. Templates extend a base template and include blocks for common elements. Views render templates to display lists of vehicles, vehicle details, an about page, and order form. URLs are named to map to views. Models define vehicles, orders, and car types with fields. Forms are created for ordering and contact.

Uploaded by

Nidhi Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Internet Applications & Distributed Systems COMP8347-02

Group 4 LAB 7

Submitted by:
Meet Shah 110093118
Kandarp Dave 110092004
Fenil Das 110093407
Harsh Patel 110091547
Mohit Desai 110089874
Nidhi Patel 110089413
Prachi Patel 110093162
Sachin Desai 110089793
Internet Applications & Distributed Systems COMP8347-02

PART 1
A.

style.css
h1 {
background-color: grey;
color: lightgray; /* Default text color */
font-size: 40px; /* Default font size */
font-family: Arial, sans-serif; /* Default font family */
font-style: normal; /* Default font style */
font-weight: bold; /* Default font weight */
text-align: center; /* Default text alignment */
}

.type {
text-align: center;
}

.card-height {
min-height: 200px;
Internet Applications & Distributed Systems COMP8347-02

.card-body {
font-size: 25px;
/* text-align: center; */
}

.hbar1 {
display: inline;
margin: 15px;
}

.fixed-bottom {
background-color: #343a40!important;
padding-top: 25px;
/* size: 20px; */
font-size: 20px;
}

B.
Internet Applications & Distributed Systems COMP8347-02

C.
base.html
<!DOCTYPE html>
{% load static %}
<html>

<head>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.m
in.css"
integrity="sha384-pzjw8f+ua7qCAL+F0KwjuvZ7OWUZTR+8j3y6szP8TG/dLs6vp7NkMg
PQeVkLJ7nB" crossorigin="anonymous">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.mi
n.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ
8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static
'/carapp/style.css' %}" />
<title> CarSite - {% block title %} Welcome! {% endblock %}</title>
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<span class="navbar-text">
<h1>{% block myhdg %} Welcome To Our Online Car Store {% endblock
%}</h1>
</span>
</nav>

{% block body_block %}*** {% endblock %}


<hr />
<div class="fixed-bottom">
<ul>
<li class="hbar1"><a href="{% url 'vehicles' %}"> List of vehicles
</a></li>
<li class="hbar1"><a href="{% url 'aboutus' %}"> Find out
about this site </a></li>
Internet Applications & Distributed Systems COMP8347-02

<li class="hbar1"><a href="{% url 'homepage' %}"> Click here to


return to the home page </a><br /></li>
</ul>
</div>
</body>

homepage.html
<!DOCTYPE html>
<html>

<head lang="en">
<meta charset="UTF-8">
<title> Car Site </title>
{% extends 'carapp/base.html' %}
</head>

<body>
{% block body_block %}
{% if cartype_list %}
<h2 class="type"> Type of Cars </h2>
<hr>
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<div class="row row-cols-3 row-cols-md-3 g-4">
{% for cartype in cartype_list %}
<div class="col">
<div class="card h-100 card-height border-dark">
<div class="card-body align-items-center d-flex
justify-content-center">
<a href="{% url 'cardetail' forloop.counter %}">
{{ cartype.name}} </a>
</div>
</div>
</div>
{% endfor %}
</div>
Internet Applications & Distributed Systems COMP8347-02

</div>
<div class="col-1"></div>
</div>
{% else %}
<strong> None of the car types is available! </strong>
{% endif %}

<!--hardcoded URL-->
<!--<p><a href="/carapp/aboutus">About Page</a></p>-->

<!--URL namespacing-->
<!-- <p><a href="{% url 'aboutus' %}">About Us</p> -->
{% endblock %}

</body>

</html>
Internet Applications & Distributed Systems COMP8347-02

aboutus.html
{% extends 'carapp/base.html' %}
{% block body_block %}
<p>This is a Car Showroom</p>
{% endblock %}
<!--hardcoded URL-->
<!--<p><a href="/carapp/">BACK</a></p>-->

<!--URL namespacing-->
<!-- <p><a href="{% url 'homepage' %}">BACK</p> -->

cardetail.html
{% extends 'carapp/base.html' %}
{% block body_block %}
<h2>Following are the Vehicles in {{ car_type }} with Cartype No {{
cartype_no }}:</h2>
<ol>
{% for vehicle in vehicles %}
<li> {{ vehicle }} </li>
{% endfor %}
</ol>
Internet Applications & Distributed Systems COMP8347-02

{% endblock %}
Internet Applications & Distributed Systems COMP8347-02

PART 2
A.
models.py
class Vehicle(models.Model):
car_type = models.ForeignKey(CarType, related_name='vehicles',
on_delete=models.CASCADE)
car_name = models.CharField(max_length=200)
car_price = models.DecimalField(max_digits=10, decimal_places=4)
inventory = models.PositiveIntegerField(default=10)
instock = models.BooleanField(default=True)
product_description = models.CharField(max_length=300, blank=True,
null=True)
CAR_FEATURES = [
('Cruise Control','Cruise Control'),
('Audio Interface','Audio Interface'),
('Airbags','Airbags'),
('Air Conditioning','Air Conditioning'),
('Seat Heating','Seat Heating'),
('ParkAssist','ParkAssist'),
('Power Steering','Power Steering'),
Internet Applications & Distributed Systems COMP8347-02

('Reversing Camera','Reversing Camera'),


('Auto Start/Stop','Auto Start/Stop'),
]
car_features= models.CharField(max_length=300, choices=CAR_FEATURES,
default='Airbags')

def __str__(self):
return self.car_name

B.
forms.py
from django import forms
Internet Applications & Distributed Systems COMP8347-02

from carapp.models import OrderVehicle


from django.forms.widgets import Select

class OrderVehicleForm(forms.ModelForm):
buyer = forms.ModelChoiceField(
queryset = User.objects.all(),
widget=Select(attrs={'size': 1})
)
vehicle = forms.ModelMultipleChoiceField(
queryset=Vehicle.objects.all(),
widget=SelectMultiple
)
vehicles_ordered = forms.IntegerField(
label='Number of Vehicles Ordered'
)

class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
email = forms.EmailField()
subject = forms.CharField(max_length=200)
message = forms.CharField(widget=forms.Textarea)

C.
urls.py
urlpatterns = [
path("", views.homepage, name="homepage"),
path("aboutus/", views.aboutus, name="aboutus"),
path("<int:cartype_no>/", views.cardetail, name="cardetail"),
# path("members/", views.members, name="members"),
path('team-members/', TeamMembersView.as_view(), name='team_members'),
path("vehicles/", views.vehicles, name='vehicles'),
]

views.py
def vehicles(request):
Internet Applications & Distributed Systems COMP8347-02

vehicles = Vehicle.objects.all()
return render(request, 'carapp/vehicles.html', {'vehicles': vehicles})

vehicles.html
{% extends 'carapp/base.html' %}
{% block body_block %}
<h2>Vehicles</h2>
<ul>
{% for vehicle in vehicles %}
<li> {{ vehicle.car_name}} </li>
{% endfor %}
</ul>
<a href="{% url 'order' %}"> ORDER! </a>
{% endblock %}

base.html
<div class="fixed-bottom">
<ul>
<li class="hbar1"><a href="{% url 'vehicles' %}"> List of vehicles
</a></li>
<li class="hbar1"><a href="{% url 'aboutus' %}"> Find out
about this site </a></li>
<li class="hbar1"><a href="{% url 'homepage' %}"> Click here to
return to the home page </a><br /></li>
</ul>
</div>
Internet Applications & Distributed Systems COMP8347-02
Internet Applications & Distributed Systems COMP8347-02

—-For Order—-
urls.py
urlpatterns = [
path("", views.homepage, name="homepage"),
path("aboutus/", views.aboutus, name="aboutus"),
path("<int:cartype_no>/", views.cardetail, name="cardetail"),
# path("members/", views.members, name="members"),
path('team-members/', TeamMembersView.as_view(), name='team_members'),
path("vehicles/", views.vehicles, name='vehicles'),
path("order/", views.orderhere, name='order'),
]

views.py
def orderhere(request):
return render(request, 'carapp/order.html')

order.html
{% extends 'carapp/base.html' %}
{% block body_block %}
<h2>You can place your order here</h2>
{% endblock %}

You might also like