Modified products and orders model

parent 7f32af26
......@@ -4,9 +4,11 @@ from .models import Order, OrderItem
# Register your models here.
class OrderAdmin(admin.ModelAdmin):
model = Order
list_display = ('order_no', 'order_date', 'amount_due', )
class OrderItemAdmin(admin.ModelAdmin):
model = OrderItem
list_display = ('order_no', 'item_id', 'color', 'quantity', 'sub_total', 'is_successful')
admin.site.register(Order, OrderAdmin)
......
# Generated by Django 3.2.12 on 2022-11-20 02:03
# Generated by Django 3.2.12 on 2022-11-22 03:24
import django.core.validators
from django.db import migrations, models
......@@ -10,8 +10,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('users', '0001_initial'),
('products', '0001_initial'),
('users', '0001_initial'),
]
operations = [
......@@ -22,9 +22,9 @@ class Migration(migrations.Migration):
('order_date', models.DateField(auto_now_add=True)),
('delivery_schedule', models.DateTimeField()),
('delivery_address', models.CharField(max_length=254)),
('gift', models.BooleanField()),
('recipient', models.CharField(max_length=50)),
('amount_due', models.IntegerField(default=0, editable=False)),
('as_gift', models.BooleanField(help_text='Is this order intended as a Gift?')),
('recipient', models.CharField(help_text='Type your name if order is not intended as a gift.', max_length=50)),
('amount_due', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12)),
('customer_id', models.ForeignKey(db_column='customer_id', on_delete=django.db.models.deletion.CASCADE, to='users.customer')),
],
options={
......@@ -39,7 +39,9 @@ class Migration(migrations.Migration):
('quantity', models.IntegerField(default=1, validators=[django.core.validators.MaxValueValidator(99), django.core.validators.MinValueValidator(0)])),
('personalization', models.CharField(max_length=254)),
('discount', models.IntegerField(default=0, editable=False)),
('discount_price', models.IntegerField(default=0, editable=False)),
('discount_price', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12)),
('sub_total', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12)),
('is_successful', models.BooleanField(default=True, editable=False)),
('item_id', models.ForeignKey(db_column='item_id', on_delete=django.db.models.deletion.CASCADE, to='products.product')),
('order_no', models.ForeignKey(db_column='order_no', on_delete=django.db.models.deletion.CASCADE, to='orders.order')),
],
......
......@@ -2,6 +2,8 @@ from django.db import models
from products.models import Product
from users.models import Customer
from django.core.validators import MaxValueValidator, MinValueValidator
from datetime import date
from decimal import *
# Create your models here.
class Order(models.Model):
......@@ -11,9 +13,9 @@ class Order(models.Model):
items = models.ManyToManyField(Product, through='OrderItem', through_fields=('order_no', 'item_id'))
delivery_schedule = models.DateTimeField()
delivery_address = models.CharField(max_length=254)
gift = models.BooleanField()
recipient = models.CharField(max_length=50)
amount_due = models.IntegerField(default=0, editable=False)
as_gift = models.BooleanField(help_text='Is this order intended as a Gift?')
recipient = models.CharField(max_length=50, help_text='Type your name if order is not intended as a gift.')
amount_due = models.DecimalField(default=0, editable=False, decimal_places=2, max_digits=12)
def __str__(self):
return str(self.order_no)
class Meta:
......@@ -27,8 +29,31 @@ class OrderItem(models.Model):
quantity = models.IntegerField(default=1, validators=[MaxValueValidator(99), MinValueValidator(0)])
personalization = models.CharField(max_length=254)
discount = models.IntegerField(default=0, editable=False)
discount_price = models.IntegerField(default=0, editable=False)
discount_price = models.DecimalField(default=0, editable=False, decimal_places=2, max_digits=12)
sub_total = models.DecimalField(default=0, editable=False, decimal_places=2, max_digits=12)
is_successful = models.BooleanField(default=True, editable=False)
def save(self, *args, **kwargs):
import products.models as product_model
inventory = product_model.Inventory.objects.all()
for prod in inventory:
if(prod.item_id == self.item_id and prod.color == self.color):
if(prod.quantity < self.quantity):
self.is_successful = False
else:
prod.quantity -= self.quantity
prod.save()
if(self.is_successful):
discounts = product_model.Discount.objects.all()
for discount in discounts:
if(self.item_id == discount.item_id and discount.start_date <= date.today() and
discount.end_date >= date.today()):
self.discount = discount.discount_percent
self.discount_price = self.item_id.price * (1 - (self.discount/100))
self.sub_total= self.discount_price * self.quantity
self.order_no.amount_due += Decimal(self.sub_total)
self.order_no.save()
return super().save(*args, **kwargs)
def __str__(self):
return str(self.quantity) + " pcs. of " + str(self.item_id) + " added to order #" + str(self.order_no)
return str(self.quantity) + " pcs. of " + str(self.item_id) + " of variant " + self.color.lower() + " added to order #" + str(self.order_no)
class Meta:
db_table = "order_item"
\ No newline at end of file
......@@ -58,7 +58,7 @@ ROOT_URLCONF = 'pixie_dust.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'DIRS': [os.path.join(BASE_DIR, 'pixie_dust', 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -124,6 +124,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'pixie_dust/static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
const header = document.querySelector(".header")
const bg = document.querySelector(".hero")
const folder_bt = document.getElementById("folder")
const pen_organizer_bt = document.getElementById("#pen_organizer")
const planner_bt = document.getElementById("#planner")
var i = 0
var isSmoothScrollSupported = 'scrollBehavior' in document.documentElement.style;
const nav = document.querySelector("#nav")
window.addEventListener("scroll", fixNav)
function fixNav() {
console.log("scroll")
if (window.scrollY > nav.offsetHeight + 150) {
nav.classList.add("active")
} else {
nav.classList.remove("active")
}
}
const int = setInterval(changeBG, 3000)
function changeBG() {
if (i === 0) {
bg.style.background =
'url("https://images.unsplash.com/photo-1516383607781-913a19294fd1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1474&q=80")'
bg.style.backgroundRepeat = "no-repeat"
bg.style.backgroundSize = "cover"
bg.style.transition = "all 0.3s ease-in-out"
i++
} else if (i === 1) {
bg.style.background =
'url("https://images.unsplash.com/photo-1654931800100-2ecf6eee7c64?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80")'
bg.style.backgroundRepeat = "no-repeat"
bg.style.backgroundSize = "cover"
bg.style.transition = "all 0.3s ease-in-out"
i++
} else if (i === 2) {
bg.style.background =
'url("https://images.unsplash.com/photo-1509043990151-c2ea135dfd26?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80")'
bg.style.backgroundRepeat = "no-repeat"
bg.style.backgroundSize = "cover"
bg.style.transition = "all 0.3s ease-in-out"
i = 0
}
}
if (isSmoothScrollSupported) {
} else {
let viewportHeight = window.innerHeight * 0.12
var z = 0
$(document).ready(function(){
$("a").on('click', function(event) {
if (this.hash !== "" && z === 0) {
z += 1
event.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top -viewportHeight
}, 800, function(){
window.location.hash = hash;
});
}
else {
event.preventDefault();
$('html, body').animate({
scrollTop: 0
}, 800,
z-=1
)}
})
});
}
@import url("https://fonts.googleapis.com/css?family=Capriola");
@import url("https://fonts.googleapis.com/css?family=Open+Sans");
html,
body {
/* width: 100%; */
/* height: 100%; */
margin: 0px;
padding: 0px;
overflow-x: hidden;
scroll-behavior: smooth;
}
body {
font-family: "Capriola", sans-serif;
color: #2aabe4;
padding-bottom: 50px;
margin: 0;
padding: 0;
overflow-x: hidden;
justify-content: center;
text-align: center;
position: relative;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
h2 {
margin: 10px;
}
a {
color: #fff;
text-decoration: none;
padding: 5px 15px;
transition: all 0.3s ease-in-out;
}
ul {
list-style-type: none;
margin: 0 20px;
align-items: center;
justify-content: center;
text-decoration: none;
list-style:none;
}
.hero-user {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
.card {
/* display: flex; */
height: 78vh;
width: 23vw;
/* background-color: lightblue; */
background-color: #2aabe4;
color: #fff;
font-family: "Open Sans";
border-radius: 10px;
text-align: center;
/* border: darkcyan solid 0.4rem; */
align-items: center;
justify-content: center;
margin: 2vh 5vh 5vh 5vh;
box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px, rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;
overflow: hidden;
}
.card .img_wrapper {
width: 100%;
height: 60%;
display: flex;
/* align-items: center; */
justify-content: center;
overflow: hidden;
}
.card img {
/* border-radius: 5%; */
object-fit: cover;
height: 100%;
width: 100%;
transition: transform .5s ease;
}
.card img:hover {
transform: scale(1.1)
}
.card-content-main{
display: flex;
padding: 15px 35px;
}
.item_name{
font-family: Helvetica;
font-size: 22px;
text-align: left;
width: 50%;
font-weight: bold;
}
.price{
font-size: 20px;
text-align: right;
width: 50%;
}
.card-content li, .card-content ul{
align-items: left;
text-align: left;
text-decoration: none;
font-size: 14px;
list-style:none;
}
.wrapper {
display: flex;
height: 100%;
width: 100%;
justify-content: center;
}
.wrapper p {
font-size: 24px;
text-align: left;
margin-top: auto;
margin-bottom: auto;
height: auto;
width: 100%;
height: fit-content;
padding: auto;
}
.hero a:hover {
font-size: 20px;
font-weight: bolder;
transition: all 0.3s ease-in-out;
}
.hero h3:hover {
font-size: 20px;
font-weight: bolder;
transition: all 0.3s ease-in-out;
}
.hero ul {
margin: 0;
list-style-position: inside;
padding: 0;
}
header {
position: fixed;
background-color: #2aabe4;
top: 0;
left: 0;
right: 0;
transition: all 0.3s ease-in-out;
padding: 0;
margin: 0;
z-index: 10;
height: 10vh;
}
header .container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
transition: all 0.3s ease-in-out;
}
header ul {
display: flex;
list-style-type: none;
margin: 0 20px;
align-items: center;
justify-content: center;
}
header a {
color: #fff;
text-decoration: none;
padding: 5px 15px;
transition: all 0.3s ease-in-out;
}
.header.active {
background-color: #fff;
box-shadow: 0 2px 20px rgba(0, 0, 0, 1.3);
z-index: 100;
height: 8vh;
}
.header.active a {
color: #000;
}
.header.active .container {
padding: 5px 0;
}
header a .current,
header a:hover {
color: #c0392b;
font-weight: bold;
}
.hero {
background-image: url("https://images.unsplash.com/photo-1516383607781-913a19294fd1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=874&q=80");
height: 100vh;
background-repeat: no-repeat;
background-size: cover;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
margin-bottom: 0;
z-index: 5;
width: 100vw;
transition: all 0.3s ease-in-out;
}
.hero::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: -1;
}
.hero h1 {
font-size: 60px;
margin: -20px 0 20px;
}
.hero p {
font-size: 20px;
letter-spacing: 1px;
}
.bg {
z-index: -10;
height: 70vh;
background-repeat: no-repeat;
background-size: cover;
background-position: bottom center;
visibility: hidden;
}
.content {
display: flex;
grid-column: 1/7;
padding: 0 20px;
text-align: justify;
}
.collection {
scroll-margin-top: 80px;
height: 90vh;
}
footer {
font-family: "Open Sans", sans-serif;
background: #2aabe4;
height: 5vh;
color: #fff;
align-items: center;
position: relative;
justify-content: center;
margin: 0;
text-align: end;
}
.footer-container {
position: absolute;
max-width: 1200px;
left: 50%;
transform: translateX(-50%);
width: 100%;
padding: 5px;
}
footer a {
text-align: end;
margin: 0;
padding: 0 20px;
width: 100%;
}
@media (max-width: 1200px) {
header a {
padding: 5px 10px;
}
header ul {
display: flex;
margin: 0 15px;
}
}
@media (max-width: 600px) {
header a {
padding: 5px 5px;
}
header ul {
display: flex;
margin: 0 10px;
}
h2 {
font-size: 24px;
}
}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}" />
<title>Pixie Dust</title>
</head>
<body>
<header class="header" id="nav">
<div class="container">
<h2 class="logo"><a href="/">Pixie Dust</a></h2>
<ul>
{% block content-header %} {% endblock %}
</ul>
</div>
</header>
<div class="parent"> </div>
{% block content %} {% endblock %}
<footer>
<div class="footer-container">
<a href="/admin-pd">©Last Minute Surplus</a>
</div>
</footer>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="{% static 'script.js' %}"></script>
</html>
......@@ -18,8 +18,9 @@ from django.urls import path, include
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('users.urls_main')),
path('admin-pd/', include('users.urls')),
path('admin-pd/products', include('products.urls')),
path('admin-pd/orders', include('orders.urls')),
path('admin/', admin.site.urls),
]
from django.contrib import admin
from django.db.models.functions import Lower
from .models import Product, Feature, Folder, PenOrganizer, Planner, Description, Inventory
from .models import Product, Feature, Folder, PenOrganizer, Planner, Description, Inventory, Discount
# Register your models here.
class ProductAdmin(admin.ModelAdmin):
......@@ -23,10 +23,15 @@ class DescriptionAdmin(admin.ModelAdmin):
class InventoryAdmin(admin.ModelAdmin):
model = Inventory
list_display = ('quantity', 'item_id', 'color', )
class DiscountAdmin(admin.ModelAdmin):
model = Discount
admin.site.register(Feature, FeatureAdmin)
admin.site.register(Folder, FolderAdmin)
admin.site.register(PenOrganizer, PenOrganizerAdmin)
admin.site.register(Planner, PlannerAdmin)
admin.site.register(Description, DescriptionAdmin)
admin.site.register(Inventory, InventoryAdmin)
\ No newline at end of file
admin.site.register(Inventory, InventoryAdmin)
admin.site.register(Discount, DiscountAdmin)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-11-20 02:02
# Generated by Django 3.2.12 on 2022-11-22 02:10
import django.core.validators
from django.db import migrations, models
......@@ -168,6 +168,19 @@ class Migration(migrations.Migration):
'db_table': 'feature',
},
),
migrations.CreateModel(
name='Discount',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('discount_percent', models.PositiveIntegerField(default=0, validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)])),
('start_date', models.DateField()),
('end_date', models.DateField()),
('item_id', models.ForeignKey(db_column='item_id', on_delete=django.db.models.deletion.CASCADE, to='products.product')),
],
options={
'db_table': 'Discount',
},
),
migrations.AddField(
model_name='description',
name='feature_id',
......
......@@ -62,3 +62,12 @@ class Inventory(models.Model):
class Meta:
db_table = "Inventory"
class Discount(models.Model):
item_id = models.ForeignKey(Product, on_delete=models.CASCADE, db_column='item_id')
discount_percent = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(100), MinValueValidator(0)])
start_date = models.DateField()
end_date = models.DateField()
def __str__(self):
return str(self.discount_percent) + "% discount applied on item " + str(self.item_id) + " valid from " + str(self.start_date) + " till " + str(self.end_date)
class Meta:
db_table = "Discount"
{% extends 'base.html' %} {% block content-header %}
<li><a href="#folder" id="folder_bt">Folders</a></li>
<li><a href="#pen_organizer" id="pen_organizer_bt">Pen Organizers</a></li>
<li><a href="#planner" id="planner_bt">Planner</a></li>
{% endblock %} {% block content %}
<section class="hero" id="hr">
<div class="container">
<h1>Welcome!</h1>
<br />
<h4>Each of our prodcuts is carfeully crafted just for you!</h4>
<h5>Start at ₱95</h5>
</div>
</section>
<br /><br />
<section>
<div class="collection" id="folder">
<h2>Folders</h2>
<div class="wrapper">
{% for folder in folder_list %}
<div class="card">
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ folder.item_name }}</div>
<div class="price">₱{{ folder.price }}</div>
</div>
<ul>
{% for description in description_list %}
{% if folder.item_id == description.item_id.item_id%}
<li>{{ description.feature_id.feature }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="collection" id="pen_organizer">
<h2>Pen Organizers</h2>
<div class="wrapper">
{% for pen_organizer in pen_organizer_list %}
<div class="card">
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ pen_organizer.item_name }}</div>
<div class="price">₱{{ pen_organizer.price }}</div>
</div>
<ul>
{% for description in description_list %}
{% if pen_organizer.item_id == description.item_id.item_id%}
<li>{{ description.feature_id.feature }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="collection" id="planner">
<h2>Planners</h2>
<div class="wrapper">
{% for planner in planner_list %}
<div class="card">
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ planner.item_name }}</div>
<div class="price">₱{{ planner.price }}</div>
</div>
<ul>
{% for description in description_list %}
{% if planner.item_id == description.item_id.item_id%}
<li>{{ description.feature_id.feature }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
<br><br><br><br>
{% endblock %}
<h1>This is the users html</h1>
{% extends 'base.html' %} {% block content-header %}
<li><a href="/admin-pd/agents">Agents</a></li>
<li><a href="/admin-pd/products">Products</a></li>
<li><a href="/admin-pd/order">Orders</a></li>
<li><a href="/admin-pd/invertory">Inventory</a></li>
{% endblock %} {% block content %}
<section class="hero">
<div class="container">
<h1>Pixie Dust Admin</h1>
</div>
</section>
{% endblock %}
from django.urls import path
from . import views
appname = "homepage"
urlpatterns = [
path('', views.homepage, name="homepage"),
]
\ No newline at end of file
from django.shortcuts import render
from products.models import Product, Folder, PenOrganizer, Planner, Description
# Create your views here.
def index(request):
return render(request, "users/users.html")
def homepage(request):
product_list = Product.objects.all()
folder_list = Folder.objects.all()
pen_organizer_list = PenOrganizer.objects.all()
planner_list = Planner.objects.all()
description_list = Description.objects.all()
return render(request, "users/homepage.html", {"product_list":product_list, "folder_list":folder_list,
"pen_organizer_list":pen_organizer_list, "planner_list":planner_list,
"description_list":description_list})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment