with product

This commit is contained in:
Flatlogic Bot 2026-01-18 11:58:06 +00:00
parent b67358cf23
commit 1c815a62fb
17 changed files with 416 additions and 189 deletions

View File

@ -1,3 +1,8 @@
from django.contrib import admin
from .models import Product
# Register your models here.
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'category', 'sku', 'price', 'stock', 'minimum_stock_level')
search_fields = ('name', 'sku')
list_filter = ('category',)

View File

@ -0,0 +1,26 @@
# Generated by Django 5.2.7 on 2026-01-18 11:36
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('category', models.CharField(blank=True, max_length=100, null=True)),
('sku', models.CharField(max_length=100, unique=True)),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('stock', models.PositiveIntegerField()),
('minimum_stock_level', models.PositiveIntegerField(default=10)),
],
),
]

View File

@ -1,3 +1,16 @@
from django.db import models
from django.urls import reverse
# Create your models here.
class Product(models.Model):
name = models.CharField(max_length=200)
category = models.CharField(max_length=100, blank=True, null=True)
sku = models.CharField(max_length=100, unique=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.PositiveIntegerField()
minimum_stock_level = models.PositiveIntegerField(default=10)
def __str__(self):
return self.name
def is_below_minimum_stock(self):
return self.stock < self.minimum_stock_level

View File

@ -3,7 +3,8 @@
<head>
<meta charset="UTF-8">
<title>{% block title %}Knowledge Base{% endblock %}</title>
<title>{% block title %}Thai Shop Inventory{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if project_description %}
<meta name="description" content="{{ project_description }}">
<meta property="og:description" content="{{ project_description }}">
@ -13,13 +14,46 @@
<meta property="og:image" content="{{ project_image_url }}">
<meta property="twitter:image" content="{{ project_image_url }}">
{% endif %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Inter:wght@400;700&display=swap"
rel="stylesheet">
{% load static %}
<link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
<link rel="stylesheet" href="{% static 'css/custom.css' %}?v=1">
{% block head %}{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="{% url 'core:dashboard' %}">Thai Shop Inventory</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="{% url 'core:product-list' %}">Products</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/admin/">Admin</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container my-5">
{% block content %}{% endblock %}
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</body>
</html>
</html>

View File

@ -1,145 +1,57 @@
{% extends "base.html" %}
{% block title %}{{ project_name }}{% endblock %}
{% block head %}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
inset: 0;
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><path d='M-10 10L110 10M10 -10L10 110' stroke-width='1' stroke='rgba(255,255,255,0.05)'/></svg>");
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% {
background-position: 0% 0%;
}
100% {
background-position: 100% 100%;
}
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2.5rem 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
}
h1 {
font-size: clamp(2.2rem, 3vw + 1.2rem, 3.2rem);
font-weight: 700;
margin: 0 0 1.2rem;
letter-spacing: -0.02em;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
opacity: 0.92;
}
.loader {
margin: 1.5rem auto;
width: 56px;
height: 56px;
border: 4px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.runtime code {
background: rgba(0, 0, 0, 0.25);
padding: 0.15rem 0.45rem;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
footer {
position: absolute;
bottom: 1rem;
width: 100%;
text-align: center;
font-size: 0.85rem;
opacity: 0.75;
}
</style>
{% endblock %}
{% block title %}Dashboard - Thai Shop Inventory{% endblock %}
{% block content %}
<main>
<div class="card">
<h1>Analyzing your requirements and generating your app…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Product Dashboard</h1>
<a href="{% url 'core:product-add' %}" class="btn btn-primary">Add Product</a>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">All Products</h5>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Stock</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for product in products %}
<tr>
<td>{{ product.sku }}</td>
<td>{{ product.name }}</td>
<td>{{ product.category }}</td>
<td>฿{{ product.price|floatformat:2 }}</td>
<td>{{ product.stock }}</td>
<td>
{% if product.is_below_minimum_stock %}
<span class="badge bg-danger">Low Stock</span>
{% else %}
<span class="badge bg-success">In Stock</span>
{% endif %}
</td>
<td>
<a href="{% url 'core:product-edit' product.pk %}" class="btn btn-sm btn-secondary">Edit</a>
<a href="{% url 'core:product-delete' product.pk %}" class="btn btn-sm btn-danger">Delete</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="text-center">No products found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<p class="hint">AppWizzy AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will refresh automatically as the plan is implemented.</p>
<p class="runtime">
Runtime: Django <code>{{ django_version }}</code> · Python <code>{{ python_version }}</code>
— UTC <code>{{ current_time|date:"Y-m-d H:i:s" }}</code>
</p>
</div>
</main>
<footer>
Page updated: {{ current_time|date:"Y-m-d H:i:s" }} (UTC)
</footer>
{% endblock %}
</div>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block title %}Confirm Delete - Thai Shop Inventory{% endblock %}
{% block content %}
<h1>Confirm Delete</h1>
<div class="alert alert-danger" role="alert">
Are you sure you want to delete <strong>{{ object.name }}</strong>?
</div>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Confirm Delete</button>
<a href="{% url 'core:product-list' %}" class="btn btn-secondary">Cancel</a>
</form>
{% endblock %}

View File

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block title %}{% if object %}Edit{% else %}Add{% endif %} Product - Thai Shop Inventory{% endblock %}
{% block content %}
<h1>{% if object %}Edit{% else %}Add{% endif %} Product</h1>
<div class="card">
<div class="card-body">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Save</button>
<a href="{% url 'core:product-list' %}" class="btn btn-secondary">Cancel</a>
</form>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,81 @@
{% extends "base.html" %}
{% block title %}Products - Thai Shop Inventory{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Products</h1>
<a href="{% url 'core:product-add' %}" class="btn btn-primary">Add Product</a>
</div>
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Filter & Search</h5>
<form method="get">
<div class="row">
<div class="col-md-5">
<input type="text" name="name" class="form-control" placeholder="Product Name" value="{{ request.GET.name }}">
</div>
<div class="col-md-5">
<select name="category" class="form-control">
<option value="">All Categories</option>
{% for category in categories %}
<option value="{{ category }}" {% if request.GET.category == category %}selected{% endif %}>{{ category }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-secondary w-100">Filter</button>
</div>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Product List</h5>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Stock</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for product in products %}
<tr>
<td>{{ product.sku }}</td>
<td>{{ product.name }}</td>
<td>{{ product.category }}</td>
<td>฿{{ product.price|floatformat:2 }}</td>
<td>{{ product.stock }}</td>
<td>
{% if product.stock <= product.minimum_stock_level %}
<span class="badge bg-danger">Low Stock</span>
{% else %}
<span class="badge bg-success">In Stock</span>
{% endif %}
</td>
<td>
<a href="{% url 'core:product-edit' product.pk %}" class="btn btn-sm btn-secondary">Edit</a>
<a href="{% url 'core:product-delete' product.pk %}" class="btn btn-sm btn-danger">Delete</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="text-center">No products found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,7 +1,18 @@
from django.urls import path
from .views import (
DashboardView,
ProductListView,
ProductCreateView,
ProductUpdateView,
ProductDeleteView,
)
from .views import home
app_name = 'core'
urlpatterns = [
path("", home, name="home"),
]
path("", DashboardView.as_view(), name="dashboard"),
path("products/", ProductListView.as_view(), name="product-list"),
path("products/add/", ProductCreateView.as_view(), name="product-add"),
path("products/<int:pk>/edit/", ProductUpdateView.as_view(), name="product-edit"),
path("products/<int:pk>/delete/", ProductDeleteView.as_view(), name="product-delete"),
]

View File

@ -1,25 +1,52 @@
import os
import platform
from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy
from django.views.generic import ListView, CreateView, UpdateView, DeleteView
from .models import Product
from django import get_version as django_version
from django.shortcuts import render
from django.utils import timezone
class DashboardView(ListView):
model = Product
template_name = 'core/index.html'
context_object_name = 'products'
class ProductListView(ListView):
model = Product
template_name = 'core/product_list.html'
context_object_name = 'products'
def home(request):
"""Render the landing screen with loader and environment details."""
host_name = request.get_host().lower()
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
now = timezone.now()
def get_queryset(self):
queryset = super().get_queryset()
name = self.request.GET.get('name')
category = self.request.GET.get('category')
context = {
"project_name": "New Style",
"agent_brand": agent_brand,
"django_version": django_version(),
"python_version": platform.python_version(),
"current_time": now,
"host_name": host_name,
"project_description": os.getenv("PROJECT_DESCRIPTION", ""),
"project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
}
return render(request, "core/index.html", context)
if name:
queryset = queryset.filter(name__icontains=name)
if category:
queryset = queryset.filter(category__iexact=category)
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['categories'] = Product.objects.values_list('category', flat=True).distinct()
return context
class ProductCreateView(CreateView):
model = Product
template_name = 'core/product_form.html'
fields = ['name', 'category', 'sku', 'price', 'stock', 'minimum_stock_level']
success_url = reverse_lazy('core:product-list')
class ProductUpdateView(UpdateView):
model = Product
template_name = 'core/product_form.html'
fields = ['name', 'category', 'sku', 'price', 'stock', 'minimum_stock_level']
success_url = reverse_lazy('core:product-list')
class ProductDeleteView(DeleteView):
model = Product
template_name = 'core/product_confirm_delete.html'
success_url = reverse_lazy('core:product-list')
# The home view is now the product list view.
home = DashboardView.as_view()

View File

@ -1,4 +1,54 @@
/* Custom styles for the application */
body {
font-family: system-ui, -apple-system, sans-serif;
:root {
--primary-color: #4F46E5;
--secondary-color: #10B981;
--accent-color: #F59E0B;
--bg-color: #F3F4F6;
--text-color: #111827;
--font-family-headings: 'Poppins', sans-serif;
--font-family-body: 'Inter', sans-serif;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: var(--font-family-body);
}
h1, h2, h3, h4, h5, h6 {
font-family: var(--font-family-headings);
}
.bg-primary {
background-color: var(--primary-color) !important;
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-primary:hover {
opacity: 0.9;
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-secondary {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.btn-secondary:hover {
opacity: 0.9;
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.text-accent {
color: var(--accent-color);
}
.table {
--bs-table-bg: #fff;
--bs-table-striped-bg: #f9f9f9;
}

View File

@ -1,21 +1,54 @@
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
--primary-color: #4F46E5;
--secondary-color: #10B981;
--accent-color: #F59E0B;
--bg-color: #F3F4F6;
--text-color: #111827;
--font-family-headings: 'Poppins', sans-serif;
--font-family-body: 'Inter', sans-serif;
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
background-color: var(--bg-color);
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
font-family: var(--font-family-body);
}
h1, h2, h3, h4, h5, h6 {
font-family: var(--font-family-headings);
}
.bg-primary {
background-color: var(--primary-color) !important;
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-primary:hover {
opacity: 0.9;
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-secondary {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.btn-secondary:hover {
opacity: 0.9;
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.text-accent {
color: var(--accent-color);
}
.table {
--bs-table-bg: #fff;
--bs-table-striped-bg: #f9f9f9;
}