Skip to content

Commit

Permalink
basic display (front end)
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna-shah-07 committed Jan 2, 2025
1 parent 85b4d25 commit 12ae2fc
Show file tree
Hide file tree
Showing 28 changed files with 295 additions and 53 deletions.
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified foodordering/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified foodordering/__pycache__/urls.cpython-310.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions foodordering/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@

STATIC_URL = "static/"

import os
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

Expand Down
9 changes: 7 additions & 2 deletions foodordering/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path("admin/", admin.site.urls),
path("products/", include("products.urls")),
path('admin/', admin.site.urls),
path('products/', include('products.urls')),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Binary file added media/product_images/IMG-20250101-WA0106.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/product_images/soup.webp
Binary file not shown.
Binary file added media/product_images/veg-gravey.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified products/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added products/__pycache__/forms.cpython-310.pyc
Binary file not shown.
Binary file modified products/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified products/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified products/__pycache__/views.cpython-310.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion products/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import admin
from .models import Product

# Register your models here.
admin.site.register(Product)
8 changes: 7 additions & 1 deletion products/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = ["name", "slug", "price", "description", "quantity"]
fields = ["name", "slug", "price", "description", "quantity", "category", "image", "available"]
widgets = {
"name": forms.TextInput(attrs={"class": "form-control", "placeholder": "Enter product name"}),
"slug": forms.TextInput(attrs={"class": "form-control", "placeholder": "Enter product slug"}),
"price": forms.NumberInput(attrs={"class": "form-control", "placeholder": "Enter product price"}),
"description": forms.Textarea(attrs={"class": "form-control", "placeholder": "Enter product description"}),
"quantity": forms.NumberInput(attrs={"class": "form-control", "placeholder": "Enter product quantity"}),
"category": forms.TextInput(attrs={"class": "form-control", "placeholder": "Enter product category"}),
"image": forms.ClearableFileInput(attrs={"class": "form-control"}),
"available": forms.CheckboxInput(attrs={"class": "form-check-input"}),
}
help_texts = {
"name": "The name of the product.",
"slug": "A unique identifier for the product, used in URLs.",
"price": "The price of the product in USD.",
"description": "A detailed description of the product.",
"quantity": "The available quantity of the product.",
"category": "The category of the product.",
"image": "An image of the product.",
"available": "Is the product available for ordering?",
}

def clean_price(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 5.1.4 on 2025-01-02 12:09

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("products", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="product",
name="created_at",
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name="product",
name="updated_at",
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name="productimage",
name="created_at",
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name="productimage",
name="updated_at",
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name="productmetainformation",
name="created_at",
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name="productmetainformation",
name="updated_at",
field=models.DateTimeField(auto_now=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.1.4 on 2025-01-02 12:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("products", "0002_alter_product_created_at_alter_product_updated_at_and_more"),
]

operations = [
migrations.RemoveField(
model_name="productmetainformation",
name="product",
),
migrations.AddField(
model_name="product",
name="available",
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name="product",
name="category",
field=models.CharField(default="Uncategorized", max_length=255),
),
migrations.AddField(
model_name="product",
name="image",
field=models.ImageField(blank=True, null=True, upload_to="product_images/"),
),
migrations.DeleteModel(
name="ProductImage",
),
migrations.DeleteModel(
name="ProductMetaInformation",
),
]
Binary file not shown.
Binary file not shown.
33 changes: 8 additions & 25 deletions products/models.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
from django.db import models

# Create your models here.

from django.utils import timezone
import uuid

class Basemodels(models.Model):
uid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created_at = models.DateField(auto_created=True)
updated_at = models.DateField(auto_created=True)
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
abstract = True # This will not create a table for this model
abstract = True

class Product(Basemodels):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)
price = models.DecimalField(max_digits=5, decimal_places=2)
description = models.TextField()
quantity = models.IntegerField(null=True, blank=True)
category = models.CharField(max_length=255, default="Uncategorized")
image = models.ImageField(upload_to='product_images/', null=True, blank=True)
available = models.BooleanField(default=True)

def __str__(self):
return self.name

class ProductImage(Basemodels):
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name="images")
image = models.ImageField(upload_to="products/images/")

def __str__(self):
return self.product.name

class ProductMetaInformation(Basemodels):
product = models.OneToOneField(Product, on_delete=models.CASCADE, related_name="meta_info")
quantity = models.IntegerField(null=True, blank=True)
is_restrict = models.BooleanField(default=False)
restrict_quantity = models.IntegerField(null=True, blank=True)
key = models.CharField(max_length=255)
value = models.TextField()

def __str__(self):
return self.product.name
return self.name
21 changes: 21 additions & 0 deletions products/templates/products/product_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Delete Product</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 class="my-4">Delete Product</h1>
<p>Are you sure you want to delete "{{ product.name }}"?</p>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Confirm</button>
<a href="{% url 'product_list' %}" class="btn btn-secondary">Cancel</a>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions products/templates/products/product_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ product.name }}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 class="my-4">{{ product.name }}</h1>
<div class="row">
<div class="col-md-6">
{% if product.image %}
<img src="{{ product.image.url }}" class="img-fluid" alt="{{ product.name }}">
{% else %}
<img src="https://via.placeholder.com/400" class="img-fluid" alt="{{ product.name }}">
{% endif %}
</div>
<div class="col-md-6">
<p><strong>Description:</strong> {{ product.description }}</p>
<p><strong>Price:</strong> ${{ product.price }}</p>
<p><strong>Quantity:</strong> {{ product.quantity }}</p>
<p><strong>Category:</strong> {{ product.category }}</p>
<p><strong>Available:</strong> {{ product.available|yesno:"Yes,No" }}</p>
<form method="post" action="{% url 'place_order' product.uid %}">
{% csrf_token %}
<div class="form-group">
<label for="quantity">Order Quantity:</label>
<input type="number" name="quantity" id="quantity" class="form-control" min="1" max="{{ product.quantity }}" required>
</div>
<button type="submit" class="btn btn-success">Place Order</button>
</form>
<a href="{% url 'product_edit' product.uid %}" class="btn btn-warning mt-3">Edit</a>
<a href="{% url 'product_delete' product.uid %}" class="btn btn-danger mt-3">Delete</a>
<a href="{% url 'product_list' %}" class="btn btn-secondary mt-3">Back to Product List</a>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
12 changes: 0 additions & 12 deletions products/templates/products/product_details.html

This file was deleted.

21 changes: 21 additions & 0 deletions products/templates/products/product_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>{% if form.instance.pk %}Edit{% else %}Add{% endif %} Product</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 class="my-4">{% if form.instance.pk %}Edit{% else %}Add{% endif %} Product</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">{% if form.instance.pk %}Update{% else %}Add{% endif %} Product</button>
</form>
<a href="{% url 'product_list' %}" class="btn btn-secondary mt-4">Back to Product List</a>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
60 changes: 51 additions & 9 deletions products/templates/products/product_list.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>Product List</title>
<title>Food List</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.card-img-top {
width: 100%;
height: 200px;
object-fit: cover;
}
.card {
height: 100%;
}
.card-body {
display: flex;
flex-direction: column;
justify-content: space-between;
}
</style>
</head>
<body>
<h1>Product List</h1>
<ul>
{% for product in products %}
<li>
<a href="{% url 'product_detail' product.pk %}">{{ product.name }}</a>
</li>
{% endfor %}
</ul>
<div class="container">
<h1 class="my-4">Food List</h1>
<a href="{% url 'product_add' %}" class="btn btn-primary mb-4">Add New Food Item</a>
<div class="row">
{% for product in products %}
<div class="col-md-4">
<div class="card mb-4">
{% if product.image %}
<img src="{{ product.image.url }}" class="card-img-top" alt="{{ product.name }}">
{% else %}
<img src="https://via.placeholder.com/400" class="card-img-top" alt="{{ product.name }}">
{% endif %}
<div class="card-body">
<h5 class="card-title">
<a href="{% url 'product_detail' product.uid %}">{{ product.name }}</a>
</h5>
<p class="card-text">{{ product.description }}</p>
<p class="card-text"><strong>Price:</strong> ${{ product.price }}</p>
<p class="card-text"><strong>Quantity:</strong> {{ product.quantity }}</p>
<p class="card-text"><strong>Category:</strong> {{ product.category }}</p>
<p class="card-text"><strong>Available:</strong> {{ product.available|yesno:"Yes,No" }}</p>
<div class="mt-auto">
<a href="{% url 'product_edit' product.uid %}" class="btn btn-warning">Edit</a>
<a href="{% url 'product_delete' product.uid %}" class="btn btn-danger">Delete</a>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
6 changes: 5 additions & 1 deletion products/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

urlpatterns = [
path("", views.product_list, name="product_list"),
path("<int:pk>/", views.product_detail, name="product_detail"),
path("<uuid:pk>/", views.product_detail, name="product_detail"),
path("add/", views.product_add, name="product_add"),
path("<uuid:pk>/edit/", views.product_edit, name="product_edit"),
path("<uuid:pk>/delete/", views.product_delete, name="product_delete"),
path("<uuid:pk>/order/", views.place_order, name="place_order"),
]
Loading

0 comments on commit 12ae2fc

Please sign in to comment.