Skip to content

Commit

Permalink
Merge pull request #498 from Fathi7ma/feature
Browse files Browse the repository at this point in the history
Ecommerce Website
  • Loading branch information
Ayushparikh-code authored Sep 20, 2024
2 parents d1752f7 + 5b2d797 commit ec021c9
Show file tree
Hide file tree
Showing 96 changed files with 1,191 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Ecommerce Website/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Ecommerce Website/.idea/Ecommerce Website.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions Ecommerce Website/.idea/inspectionProfiles/Project_Default.xml

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.

7 changes: 7 additions & 0 deletions Ecommerce Website/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Ecommerce Website/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Ecommerce Website/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Ecommerce Website/README.md
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">
Empty file added Ecommerce Website/__init__.py
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Ecommerce Website/cart/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions Ecommerce Website/cart/apps.py
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'
41 changes: 41 additions & 0 deletions Ecommerce Website/cart/migrations/0001_initial.py
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',
},
),
]
Empty file.
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions Ecommerce Website/cart/models.py
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)



3 changes: 3 additions & 0 deletions Ecommerce Website/cart/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions Ecommerce Website/cart/urls.py
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'),
]
46 changes: 46 additions & 0 deletions Ecommerce Website/cart/views.py
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))



Binary file added Ecommerce Website/category/2piece.jfif
Binary file not shown.
Binary file added Ecommerce Website/category/pink_casual_shoe.jfif
Binary file not shown.
Binary file added Ecommerce Website/db.sqlite3
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions Ecommerce Website/ecommerceproject/asgi.py
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()
Loading

0 comments on commit ec021c9

Please sign in to comment.