0% found this document useful (0 votes)
8 views7 pages

Django Bidding Project Report

The Django Bidding Application project report outlines its components, including user registration with email OTP verification, item listing, bidding, and winner determination. Key functionalities are implemented through various Django files such as models, forms, views, and admin configurations. The application allows users to register, log in, place bids, and view the highest bidder for items.

Uploaded by

Kumar Nandan
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)
8 views7 pages

Django Bidding Project Report

The Django Bidding Application project report outlines its components, including user registration with email OTP verification, item listing, bidding, and winner determination. Key functionalities are implemented through various Django files such as models, forms, views, and admin configurations. The application allows users to register, log in, place bids, and view the highest bidder for items.

Uploaded by

Kumar Nandan
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/ 7

Django Bidding Application - Project Report

This report describes the components of the Django-based Bidding Application project.

It includes functionalities for user registration with email OTP verification, item listing,

bidding, and determining the highest bidder (winner).

Admin Configuration (admin.py)


from django.contrib import admin
from app.models import Image
from app.models import Item
from app.models import Bid
admin.site.site_header = "Bid Application | Admin"
class ImageAdmin(admin.ModelAdmin):
list_display = ['id','name','descriptons','is_approved']

class ItemAdmin(admin.ModelAdmin):
list_display = ['id',]

class BidAdmin(admin.ModelAdmin):
list_display = ['id','name','Prize']

admin.site.register(Image)
admin.site.register(Item)
admin.site.register(Bid)

App Configuration (apps.py)


from django.apps import AppConfig

class HomeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app'

Forms (forms.py)
from django import forms
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm,
UsernameField
from django.contrib.auth.models import User
from django.utils.translation import gettext, gettext_lazy as _
from django.contrib.auth.forms import UserChangeForm
class SignUpForm(UserCreationForm):
password1 = forms.CharField(label='Password',
widget=forms.PasswordInput(attrs={'class':'form-control'}))
password2 = forms.CharField(label='Confirm Password (again)',
widget=forms.PasswordInput(attrs={'class':'form-control'}))
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email']
labels = {'first_name': 'First Name', 'last_name': 'Last Name', 'email': 'Email'}
widgets = {'username':forms.TextInput(attrs={'class':'form-control'}),
'first_name':forms.TextInput(attrs={'class':'form-control'}),
'last_name':forms.TextInput(attrs={'class':'form-control'}),
'email':forms.EmailInput(attrs={'class':'form-control'}),
}

class LoginForm(AuthenticationForm):
username = UsernameField(widget=forms.TextInput(attrs={'autofocus': True,
'class':'form-control'}))
password = forms.CharField(label=_("Password"), strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'current-password',
'class':'form-control'}))

class InputForm(forms.Form):
productid = forms.CharField(label="Product ID", max_length=255)
maxamount = forms.DecimalField(label="Maximum Bid Amount", max_digits=10,
decimal_places=2)

Models (models.py)
from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone

class Image(models.Model):
photo = models.ImageField(upload_to='mypic/')
name = models.CharField(max_length=100,null=True)
descriptions=models.CharField(max_length=100,null=True)
Bidprze=models.IntegerField(max_length=89,null=True)

def __str__(self):

return str(self.name)

class Item(models.Model):
photo=models.ImageField(upload_to="pic")
time=models.TimeField()
productid=models.IntegerField(max_length=20)
description=models.TextField(null=True)
def __str__(self):

return str(self.productid)
class Bid(models.Model):
Bidder=models.CharField(max_length=20)
maxamount=models.IntegerField(max_length=24)
productid=models.IntegerField(max_length=30 ,null=True)
def __str__(self):

return str(self.Bidder)

class EmailOTP(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
otp = models.CharField(max_length=6)
created_at = models.DateTimeField(auto_now_add=True)
expiry_time = models.DateTimeField(null=True)

def __str__(self):
return f"{self.user.username} - {self.otp}"

Tests (tests.py)
from django.test import TestCase

# Create your tests here.

Utility Functions (utils.py)


import random

def generate_otp():
return str(random.randint(100000, 999999))

Views / Core Logic (views.py)

from urllib import response


from django.shortcuts import render, HttpResponseRedirect,redirect
from .forms import SignUpForm, LoginForm,InputForm
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from .models import Image
from .models import Item
from .models import Image
from .models import Bid
from django.contrib.auth.models import User
import random
from django.core.mail import send_mail
from django.conf import settings
from .models import EmailOTP
from django.shortcuts import render, redirect
from django.contrib import messages
from .models import EmailOTP
from datetime import timedelta
from django.utils import timezone
from django.utils import timezone
from datetime import timedelta
from django.core.mail import send_mail
from django.contrib import messages
from django.shortcuts import render, redirect
from django.conf import settings
from .models import EmailOTP
from .forms import SignUpForm
from .utils import generate_otp # assume you have a function to generate random 6-digit
OTP

def home(request):
img=Image.objects.all()
instance=Image.objects.first()
return render(request, 'blog/home.html',{'img':img,'instance':instance})
def image_detail(request, pk):
img = Image.objects.get(pk=pk)

return render(request, 'blog/image_detail.html', {'image': img})

def dashboard(request):
if request.user.is_authenticated:
it=Item.objects.all()

user = request.user
full_name = user.get_full_name()

return render(request, 'blog/dashboard.html', { 'full_name':full_name,'it':it })


else:
return HttpResponseRedirect('/login/')
def user_logout(request):
logout(request)
return HttpResponseRedirect('/')

def generate_otp():
return str(random.randint(100000, 999999))

def user_signup(request):
if request.method == "POST":
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.is_active = False
user.save()

otp = generate_otp()
expiry = timezone.now() + timedelta(minutes=1)
EmailOTP.objects.create(user=user, otp=otp, expiry_time=expiry)

send_mail(
"Your OTP Code",
f"Hi {user.username}, your OTP is {otp}. It will expire in 10 minutes.",
settings.EMAIL_HOST_USER,
[user.email],
)

request.session['uid'] = user.id
messages.success(request, "An OTP has been sent to your email.")
return redirect('verify_otp')
else:
form = SignUpForm()
return render(request, 'blog/signup.html', {'form': form})

def verify_otp(request):
if request.method == "POST":
input_otp = request.POST.get('otp')
user_id = request.session.get('uid')

if not user_id:
messages.error(request, "Session expired. Please sign up again.")
return redirect('signup')

user = User.objects.get(id=user_id)
otp_record = EmailOTP.objects.filter(user=user).order_by('-id').first()

if not otp_record:
messages.error(request, "No OTP record found. Please try again.")
return redirect('signup')

if timezone.now() > otp_record.expiry_time:


messages.error(request, "OTP has expired. Please sign up again.")
return redirect('signup')

if input_otp != otp_record.otp:
messages.error(request, "Incorrect OTP. Please try again.")
return render(request, 'blog/verify_otp.html')

# OTP is correct and not expired


user.is_active = True
user.save()
messages.success(request, "Account activated! You can now log in.")
return redirect('login')

return render(request, 'blog/verify_otp.html')

def user_login(request):
form=""
if not request.user.is_authenticated:
if request.method == "POST":
form = LoginForm(request=request, data=request.POST)
if form.is_valid():
uname = form.cleaned_data['username']
upass = form.cleaned_data['password']
user = authenticate(username=uname, password=upass)
if user is not None:
if user.is_superuser:
return redirect('/admin/')

else:
login(request,user)
messages.success(request, 'Logged in Successfully !!')
return HttpResponseRedirect('/dashboard/')

else:
form = LoginForm()
return render(request, 'blog/login.html', {'form':form})
else:
return HttpResponseRedirect('/dashboard/')

def bid(request):
if request.method == "POST":
form = InputForm(request.POST)
if form.is_valid():

product_id = form.cleaned_data['productid']
max_amount = form.cleaned_data['maxamount']
username = request.user.username

bid_exist = Bid.objects.filter(Bidder=username,
productid=product_id).first()
if bid_exist:

bid_exist.maxamount = max_amount
bid_exist.save()
messages.success(request, 'Your bid has been updated successfully.')
else:

new_bid = Bid(Bidder=username, productid=product_id,


maxamount=max_amount)
new_bid.save()
messages.success(request, 'Congratulations! Your bid has been placed
successfully.')

return redirect('/dashboard/')
else:

form = InputForm()

return render(request, 'blog/bid.html', {'form': form})

def winner(request):
bids=Bid.objects.all()
it=Item.objects.all()
if bids:
winner=max(bids,key=lambda bid:bid.maxamount)
return render(request,'blog/winner.html',{'winner':winner,'it':it })

You might also like