-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Ecommerce Website
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Ecommerce Website:- | ||
|
||
Ecommerce Website using Python Django,HTML,CSS,Javascript. | ||
|
||
This website allows you to purchase dresses and shoes online. | ||
|
||
Used Technologies: | ||
Python Django,HTML,CSS,Javascript | ||
|
||
Steps to use: | ||
1.Download python and IDE | ||
2.Clone the repository by running command | ||
git clone https://github.com/Ayushparikh-code/Web-dev-mini-projects.git | ||
in your git bash. | ||
3.Run command cd Ecommerce Website | ||
|
||
Screenshots: | ||
<img src="C:\Users\user\Pictures\Screenshots\Screenshot (261).png"> | ||
<img src="C:\Users\user\Pictures\Screenshots\Screenshot (260).png"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CartConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'cart' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.1.5 on 2023-07-11 06:24 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('shop', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Cart', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('cart_id', models.CharField(blank=True, max_length=250)), | ||
('date_added', models.DateField(auto_now_add=True)), | ||
], | ||
options={ | ||
'db_table': 'Cart', | ||
'ordering': ['date_added'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='CartItem', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('quantity', models.IntegerField()), | ||
('active', models.BooleanField(default=True)), | ||
('cart', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cart.cart')), | ||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='shop.product')), | ||
], | ||
options={ | ||
'db_table': 'CartItem', | ||
}, | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.db import models | ||
from shop.models import Product | ||
# Create your models here. | ||
class Cart(models.Model): | ||
cart_id=models.CharField(max_length=250,blank=True) | ||
date_added=models.DateField(auto_now_add=True) | ||
|
||
class Meta: | ||
db_table='Cart' | ||
ordering=['date_added'] | ||
def __str__(self): | ||
return '{}'.format(self.cart_id) | ||
|
||
class CartItem(models.Model): | ||
product=models.ForeignKey(Product,on_delete=models.CASCADE) | ||
cart=models.ForeignKey(Cart,on_delete=models.CASCADE) | ||
quantity=models.IntegerField() | ||
active=models.BooleanField(default=True) | ||
|
||
class Meta: | ||
db_table='CartItem' | ||
def sub_total(self): | ||
return self.product.price*self.quantity | ||
def __str__(self): | ||
return '{}'.format(self.product) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
app_name='cart' | ||
|
||
urlpatterns=[ | ||
path('add/<int:product_id>/',views.add_cart,name='add_cart'), | ||
path('',views.cart_detail,name='cart_detail'), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
from django.shortcuts import render, redirect | ||
from shop.models import Product | ||
from .models import Cart,CartItem | ||
from django.core.exceptions import ObjectDoesNotExist | ||
|
||
def _cart_id(request): | ||
cart=request.session.session_key | ||
if not cart: | ||
cart=request.session.create() | ||
return cart | ||
|
||
def add_cart(request,product_id): | ||
product=Product.objects.get(id=product_id) | ||
try: | ||
cart=Cart.objects.get(cart_id=_cart_id(request)) | ||
except Cart.DoesNotExist: | ||
cart=Cart.objects.create( | ||
cart_id=_cart_id(request) | ||
) | ||
cart.save(), | ||
try: | ||
cart_item=CartItem.objects.get(product=product,cart=cart) | ||
cart_item.quantity +=1 | ||
cart_item.save() | ||
except CartItem.DoesNotExist: | ||
cart_item=CartItem.objects.create( | ||
product=product, | ||
quantity=1, | ||
cart=cart | ||
) | ||
cart_item.save() | ||
return redirect('cart:cart_detail') | ||
def cart_detail(request,total=0,counter=0,cart_items=None): | ||
try: | ||
cart=Cart.objects.get(cart_id=_cart_id(request)) | ||
cart_items=CartItem.objects.filter(cart=cart,active=True) | ||
for cart_item in cart_items: | ||
total+=(cart_item.product.price * cart_item.quantity) | ||
counter +=cart_item.quantity | ||
except ObjectDoesNotExist: | ||
pass | ||
return render(request,'cart.html',dict(cart_items=cart_items,total=total,counter=counter)) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for ecommerceproject project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerceproject.settings') | ||
|
||
application = get_asgi_application() |