-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85b4d25
commit 12ae2fc
Showing
28 changed files
with
295 additions
and
53 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
products/migrations/0002_alter_product_created_at_alter_product_updated_at_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
38 changes: 38 additions & 0 deletions
38
products/migrations/0003_remove_productmetainformation_product_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+937 Bytes
...pycache__/0002_alter_product_created_at_alter_product_updated_at_and_more.cpython-310.pyc
Binary file not shown.
Binary file added
BIN
+1015 Bytes
...igrations/__pycache__/0003_remove_productmetainformation_product_and_more.cpython-310.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.