In this article, I am Going to Build an Online auction system Using Django. Physical auctions are limited by location but online auctions are accessible globally. It opens a broader range of buyers. It Can Connect the Seller, Buyer, and admin.
Tools & Technologies Used in this Project :
- Python
- Django
- Visual Studio Code
- HTML
- CSS
- Java Script
Implementation :
Follow the below steps to implement the discussed project :
Step 1: Download Visual Studio Code and install it in your Device.
Step 2: After Setup Visual Studio Code.Press (Cntrl + Shift + X) and Install Python & Django Extension in it.
Step 3: Open Command Promt and Create a Directory.
>Mkdir Online_Auction
>cd Online_Auction
>code .
Step 4: Open shell of VSCode and create and activate virtual environment using below commands.
virtualenv venv
venv/Scripts/activate
pip install django
Step 4: Create the Project and app using the below commands.
django-admin startproject Online_Auction
cd Online_Auction
python manage.py startapp auction
Step 5: Add app name in Settings.py file. ‘auction’ or paste the below code in Settings.py file
# Online_Auction > Online_Auction > settings.py import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '_igtoud8=l*xejhiwtfz$ce-fu*%80&^hybem91#g#)5j7td#z'
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True
ALLOWED_HOSTS = []
# Application definition INSTALLED_APPS = [
'auction' ,
'django.contrib.admin' ,
'django.contrib.auth' ,
'django.contrib.contenttypes' ,
'django.contrib.sessions' ,
'django.contrib.messages' ,
'django.contrib.staticfiles' ,
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware' ,
'django.contrib.sessions.middleware.SessionMiddleware' ,
'django.middleware.common.CommonMiddleware' ,
'django.middleware.csrf.CsrfViewMiddleware' ,
'django.contrib.auth.middleware.AuthenticationMiddleware' ,
'django.contrib.messages.middleware.MessageMiddleware' ,
'django.middleware.clickjacking.XFrameOptionsMiddleware' ,
] ROOT_URLCONF = 'Online_Auction.urls'
TEMPLATES = [
{
'BACKEND' : 'django.template.backends.django.DjangoTemplates' ,
'DIRS' : [],
'APP_DIRS' : True ,
'OPTIONS' : {
'context_processors' : [
'django.template.context_processors.debug' ,
'django.template.context_processors.request' ,
'django.contrib.auth.context_processors.auth' ,
'django.contrib.messages.context_processors.messages' ,
],
},
},
] WSGI_APPLICATION = 'Online_Auction.wsgi.application'
# Database DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.sqlite3' ,
'NAME' : os.path.join(BASE_DIR, 'db.sqlite3' ),
}
} # Password validation AUTH_PASSWORD_VALIDATORS = [
{
'NAME' : 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.MinimumLengthValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.CommonPasswordValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.NumericPasswordValidator' ,
},
] # Internationalization LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images) STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media' )
|
Step :6 Paste the Below code in urls.py file in Online_Auction.
# Online_Auction > Online_Auction > urls.py from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from auction.views import *
urlpatterns = [
path( 'admin/' , admin.site.urls),
path('',Home,name = "home" ),
path( 'user_home' ,Bidder_Home,name = "user_home" ),
path( 'trainer_home' ,Auction_User,name = "trainer_home" ),
path( 'login_user' ,Login_User,name = "login_user" ),
path( 'contact' ,Contact,name = "conRtact" ),
path( 'about' ,About,name = "about" ),
path( 'contact' ,Contact,name = "contact" ),
path( 'edit_profile' ,Edit_Profile,name = "edit_profile" ),
path( 'edit_profile1' ,Edit_Profile1,name = "edit_profile1" ),
path( 'logout' , Logout, name = "logout" ),
path( 'login_admin' ,Login_Admin,name = "login_admin" ),
path( 'signup' , Signup_User,name = "signup" ),
path( 'change_password' ,Change_Password,name = "change_password" ),
path( 'change_password1' ,Change_Password1,name = "change_password1" ),
path( 'admin_home' , Admin_Home,name = "admin_home" ),
path( 'add_product' , Add_Product,name = "add_product" ),
path( 'new_product' , New_product,name = "new_product" ),
path( 'bidder_user' , Bidder_User,name = "bidder_user" ),
path( 'user_delete/<int:id>' , user_delete,name = "user_delete" ),
path( 'seller_user' , Seller_User,name = "seller_user" ),
path( 'user_delete_seller/<int:id>' , user_delete_seller,name = "user_delete_seller" ),
path( 'all_product2' , All_product2,name = "all_product2" ),
path( 'profile' , profile, name = 'profile' ),
path( 'result' , result, name = 'result' ),
path( 'view_auction/<int:pid>' , view_auction, name = 'view_auction' ),
path( 'particpated_user(<int:pid>)' , Participated_user, name = 'particpated_user' ),
path( 'profile1' , Profile1, name = 'profile1' ),
path( 'status(<int:pid>)' , Change_status, name = 'status' ),
path( 'winner(<int:pid>)' , Winner,name = 'winner' ),
path( 'winner2(<int:pid>)' , Winner2,name = 'winner2' ),
path( 'winner1(<int:pid>)' , Winner1,name = 'winner1' ),
path( 'start_auction(<int:pid>)' , Start_Auction, name = 'start_auction' ),
path( 'view_category' , view_category, name = 'view_category' ),
path( 'view_subcategory' , view_subcategory, name = 'view_subcategory' ),
path( 'view_session_date' , view_session_date, name = 'view_session_date' ),
path( 'view_session_time' , view_session_time, name = 'view_session_time' ),
path( 'add_category' , Add_Category, name = 'add_category' ),
path( 'add_subcategory' , Add_SubCategory, name = 'add_subcategory' ),
path( 'add_session_date' , Add_Session_date, name = 'add_session_date' ),
path( 'add_session_time' , Add_Session_time, name = 'add_session_time' ),
path( 'bidding_status' , Bidding_Status, name = 'bidding_status' ),
path( 'bidding_status2' , Bidding_Status2, name = 'bidding_status2' ),
path( 'all_product' , All_product, name = 'all_product' ),
path( 'edit_category(<int:pid>)' , Edit_Category, name = 'edit_category' ),
path( 'product_detail(<int:pid>)' , product_detail, name = 'product_detail' ),
path( 'edit_subcategory(<int:pid>)' , Edit_SubCategory, name = 'edit_subcategory' ),
path( 'edit_session_date(<int:pid>)' , Edit_Session_date, name = 'edit_session_date' ),
path( 'edit_session_time(<int:pid>)' , Edit_Session_time, name = 'edit_session_time' ),
path( 'delete_category(<int:pid>)' , delete_category, name = 'delete_category' ),
path( 'delete_subcategory(<int:pid>)' , delete_subcategory, name = 'delete_subcategory' ),
path( 'delete_session_date(<int:pid>)' , delete_session_date, name = 'delete_session_date' ),
path( 'delete_session_time(<int:pid>)' , delete_session_time, name = 'delete_session_time' ),
path( 'load-courses/' , load_courses, name = 'ajax_load_courses' ),
path( 'load-courses1/' , load_courses1, name = 'ajax_load_courses1' ),
path( 'product_detail2(<int:pid>)' , product_detail2, name = 'product_detail2' ),
] + static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)
|
Step 7: Go to admin.py file and paste the below code.
#Online_Auction > auction > admin.py from django.contrib import admin
from .models import *
# Register your models here.' admin.site.register(Bidder) admin.site.register(Result) admin.site.register(Payment) admin.site.register(Member_fee) admin.site.register(Status) admin.site.register(Send_Feedback) admin.site.register(Auction_User) admin.site.register(Category) admin.site.register(Sub_Category) admin.site.register(Session_date) admin.site.register(Session_Time) admin.site.register(Product) admin.site.register(Aucted_Product) admin.site.register(Participant) |
Step 9: Create two folders in auction one is “templates” , second is “static”
Step 10: Open views.py file from auction_app and paste the below code.
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from auction_app.models import *
from datetime import date
today = date.today()
global_var = None # Initialize it with a default value
# Function to set the global variable to a dynamic value def set_global_variable(value):
global global_var
global_var = value
# Function to access the global variable def access_global_variable():
return global_var
def maxbid( id ):
li = []
global maximum
item = Item.objects.get( id = id )
print ( "item id-->" ,item. id )
user = User.objects. all ().values()
# item = Item.objects.all().values()
for i in user:
a = i[ 'bid_amt' ]
print ( "-->" ,a)
li.append(a)
maximum = max (li)
print (li)
print ( "maximum" ,maximum)
item.max_bid = maximum
item.save()
print ( "Item Saved" )
return maximum
# print(a)
# li.append(i)
# print("list-->",li)
# print(max(li))
# return a
def bid(request):
item = Item.objects. all ()
# user = User.objects.all()
maxbid()
# print(item.item_name.values)
return render(request, 'base.html' ,{ "item" :item})
def login(request):
if request.method = = 'POST' :
email = request.POST[ 'email' ]
print (email)
password = request.POST[ 'password' ]
print (password)
item = Item.objects. all ()
try :
user = User.objects.get(email = email)
print ( "userpass--->" ,user.password)
if user is not None :
if password = = user.password:
global mailid
# print("Mail id here--->",item.item_status)
set_global_variable(email)
mailid = email
mail = email
# print("Ye rhi dates-->",item.start_date)
# print("ye print ho gyi--->",mailid)
# print("outer funciton global --->",mail)
return render(request, 'base.html' ,{ "item" :item, "mailid" :mailid})
else :
print ( "Wrong pass" )
return HttpResponse( "Wrong Password" )
except :
return HttpResponse( "email id Not exist" )
print ( "email id Not exist" )
return render(request, 'login.html' )
def register(request):
if request.method = = 'POST' :
name = request.POST[ 'name' ]
print (name)
email = request.POST[ 'email' ]
print (email)
phone = request.POST[ 'phone' ]
print (phone)
password = request.POST[ 'password' ]
print (password)
user = User.objects. all ().values()
for i in user:
flag = 0
dataemail = i[ 'email' ]
if dataemail = = email:
flag = 1
return HttpResponse( "Email id Already Exist" )
if flag! = 1 :
new = User.objects.create(name = name,email = email,phone = phone,password = password )
new.save()
print (f "User Create with email {email}" )
return HttpResponse(f "User Created Successfully with email {email}" )
return render(request, 'register.html' )
def applybid(request, id ):
mail = access_global_variable()
print ( "Yaha pe ye mail ai h applybid mei -->" ,mail)
item = Item.objects.get( id = id )
user = User.objects.get(email = mail)
print ( "user--->" ,user.email)
# for i in user:
# # print("i-->",i)
# if i.email == mail:
# print("mail id-->",i.email)
if request.method = = "POST" :
maximum = request.POST[ 'max_bid' ]
item.max_bid = maximum
user.bid_amt = maximum
print ( "user.status--->" ,user.status)
user.status = "Applied"
print ( "user.status--->" ,user.status)
item.save()
user.save()
print ( "Hogya save" )
maxbid( id )
return redirect( '/' )
return render(request, 'applybid.html' ,{ "item" :item, "user" :user})
def home(request):
item = Item.objects. all ()
return render(request, 'home.html' ,{ "item" :item})
|
Step 11: Create the base.html file in templates folder and paste the below code.
<!DOCTYPE html> < html >
< head >
< style >
table { font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
} td, th { border: 1px solid #dddddd;
text-align: left;
padding: 8px;
} tr:nth-child(even) { background-color: #dddddd;
} a:link, a:visited { background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: right;
text-decoration: none;
display: inline-block;
} a:hover, a:active { background-color: Blue;
} </ style >
</ head >
< body >
< center >< h2 >Available Auction</ h2 ></ center >
< a href = "{% url 'home' %}" target = "_blank" >Logout</ a >
{{mailid}} < table >
< thread >
< tr >
< th >SNo.</ th >
< th >Product Name</ th >
< th > Bid Amount </ th >
< th >Description</ th >
< th >Start Date</ th >
< th >End Date</ th >
< th >Action </ th >
</ tr >
</ thread >
{% for i in item %} < tr >
< td >{{forloop.counter}}</ td >
< td > {{i.item_name}}</ td >
< td > {{i.basic_amount}}</ td >
< td > {{i.desc}}</ td >
< td > {{i.start_date}}</ td >
< td > {{i.end_date}}</ td >
< td >< a href = "{% url 'applybid' i.id %}" target = "_blank" >Apply</ a ></ td >
{% comment %} < td >< a href = "{% url 'applybid' i.id %}" >< button class = "btn btn-primary" > Apply</ button ></ a > </ td > {% endcomment %}
{% endfor %}
</ tr >
</ table >
</ body >
</ html >
|
Step 12: Create the home.html file in templates folder and paste the below code.
<!DOCTYPE html> < html >
< head >
< style >
table { font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
} td, th { border: 1px solid #dddddd;
text-align: left;
padding: 8px;
} tr:nth-child(even) { background-color: #dddddd;
} a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: right;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: Blue;
}
</ style >
</ head >
< body >
< center >< h2 >Available Auction</ h2 ></ center >
< a href = "{% url 'login' %}" target = "_blank" >Login</ a >
< table >
< thread >
< tr >
< th >SNo.</ th >
< th >Product Name</ th >
< th > Bid Amount </ th >
< th > Max Bid </ th >
< th >Results </ th >
</ tr >
</ thread >
{% for i in item %} < tr >
< td >{{forloop.counter}}</ td >
< td > {{i.item_name}}</ td >
< td > {{i.basic_amount}}</ td >
< td >{{i.max_bid}}</ td >
< td ></ td >
{% endfor %}
</ tr >
</ table >
</ body >
</ html >
|
Step 13: Create the login.html file in templates folder and paste the below code.
<!DOCTYPE html> < html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >Login Page</ title >
< style >
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
input[type="text"], input[type="password"] {
width: 90%;
padding: 7px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
background-color: #007BFF;
color: white;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
a {
text-decoration: none;
color: #007BFF;
}
</ style >
</ head >
< body >
< div class = "container" >
< center >< h2 >LOGIN PAGE </ h2 ></ center >
< form method = "post" >
{% csrf_token %}
< label for = "email" >Email:</ label >< br >
< input type = "text" id = "email" name = "email" required>< br >< br >
< label for = "password" >Password:</ label >< br >
< input type = "password" id = "password" name = "password" required>< br >< br >
< center >< button type = "submit" >Login</ button ></ center >
</ form >
< p >Don't have an account? < a href = "{% url 'register'%}" >Register here</ a ></ p >
</ div >
</ body >
</ html >
|
Step 14: Create the register.html file in templates folder and paste the below code.
<!DOCTYPE html> < html >
< head >
< title >User Registration</ title >
< style >
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f2f2f2;
}
.container {
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
margin: 0 auto;
max-width: 400px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
font-weight: bold;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"] {
width: 100%;
padding: 7px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 3px;
padding: 10px 20px;
cursor: pointer;
}
</ style >
</ head >
< body >
< div class = "container" >
< center >< h2 >User Registration</ h2 ></ center >
< form action = "" method = "POST" >
{% csrf_token %}
< div class = "form-group" >
< label for = "name" >Name:</ label >
< input type = "text" id = "name" name = "name" required>
</ div >
< div class = "form-group" >
< label for = "email" >Email:</ label >
< input type = "email" id = "email" name = "email" required>
</ div >
< div class = "form-group" >
< label for = "phone" >Phone:</ label >
< input type = "tel" id = "phone" name = "phone" required>
</ div >
< div class = "form-group" >
< label for = "password" >Password:</ label >
< input type = "password" id = "password" name = "password" required>
</ div >
< center >< input type = "submit" value = "Register" ></ center >
</ form >
</ div >
</ body >
</ html >
|
Step 15: Create the applybid.html file in templates folder and paste the below code.
<!DOCTYPE html> < html >
< head >
< title >Auction Item Form</ title >
< style >
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.form-container {
background-color: #ffffff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 100px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
.form-container h2 {
text-align: center;
}
.form-container label,
.form-container input,
.form-container textarea {
display: block;
margin-bottom: 15px;
}
.form-container input,
.form-container textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
.form-container input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 3px;
padding: 10px 20px;
cursor: pointer;
}
</ style >
</ head >
< body >
< div class = "form-container" >
< h2 >Auction Participation Form </ h2 >
< form method = "POST" >
{% csrf_token %}
< div >
< label for = "item_name" >Item Name:</ label >
< input type = "text" id = "item_name" name = "item_name" placeholder = "{{item.item_name}}" readonly>
</ div >
< div >
< label for = "description" >Description:</ label >
< textarea id = "description" name = "description" rows = "3" placeholder = "{{item.desc}}" readonly></ textarea >
</ div >
< div >
< label for = "basic_amount" >Basic Amount:</ label >
< input type = "number" id = "basic_amount" name = "basic_amount" placeholder = "{{item.basic_amount}}" readonly>
</ div >
< div >
< label for = "start_date" >Start Date:</ label >
< input type = "text" id = "start_date" name = "start_date" placeholder = "{{item.start_date}}" readonly>
</ div >
< div >
< label for = "end_date" >End Date:</ label >
< input type = "text" id = "end_date" name = "end_date" placeholder = "{{item.end_date}}" readonly>
</ div >
< div >
< label for = "max_bid" >Max Bid:</ label >
< input type = "number" id = "max_bid" name = "max_bid" min = "{{item.basic_amount}}" required>
</ div >
< div >
< input type = "submit" value = "Submit" >
</ div >
</ form >
</ div >
</ body >
</ html >
|
Step :16 Open the Shell and run the following commands
Python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Step: 17 Open the Browser and run the server.