diff --git a/djangoProject/views.py b/djangoProject/views.py
index a804068..130cc3c 100644
--- a/djangoProject/views.py
+++ b/djangoProject/views.py
@@ -11,7 +11,7 @@ def profile1(request: HttpRequest):
def product1(request: HttpRequest):
- return render(request, "product.html", {
+ return render(request, "product/product-detail.html", {
"quantity_null": True
})
diff --git a/myfirstproject/migrations/0005_product_in_stock_alter_product_amount_product_and_more.py b/myfirstproject/migrations/0005_product_in_stock_alter_product_amount_product_and_more.py
new file mode 100644
index 0000000..58a0e5c
--- /dev/null
+++ b/myfirstproject/migrations/0005_product_in_stock_alter_product_amount_product_and_more.py
@@ -0,0 +1,29 @@
+# Generated by Django 4.0.6 on 2022-08-16 12:07
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('myfirstproject', '0004_product'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='product',
+ name='in_stock',
+ field=models.BooleanField(blank=True, null=True),
+ ),
+ migrations.AlterField(
+ model_name='product',
+ name='amount_product',
+ field=models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)]),
+ ),
+ migrations.AlterField(
+ model_name='product',
+ name='price_product',
+ field=models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)]),
+ ),
+ ]
diff --git a/templates/apple.html b/myfirstproject/templates/apple.html
similarity index 71%
rename from templates/apple.html
rename to myfirstproject/templates/apple.html
index 9904227..f546b3a 100644
--- a/templates/apple.html
+++ b/myfirstproject/templates/apple.html
@@ -1,4 +1,4 @@
-{% extends 'product.html' %}
+{% extends 'product/product-detail.html' %}
{% block title %}
apple
@@ -11,7 +11,7 @@
Page product apple
{% block content %}
-
- homepage
+ homepage
-
profile user
diff --git a/templates/fish.html b/myfirstproject/templates/fish.html
similarity index 70%
rename from templates/fish.html
rename to myfirstproject/templates/fish.html
index 80379e6..4199724 100644
--- a/templates/fish.html
+++ b/myfirstproject/templates/fish.html
@@ -1,4 +1,4 @@
-{% extends 'product.html' %}
+{% extends 'product/product-detail.html' %}
{% block title %}
fish
@@ -11,7 +11,7 @@
Page product fish
{% block content %}
-
- homepage
+ homepage
-
profile user
diff --git a/templates/milk.html b/myfirstproject/templates/milk.html
similarity index 55%
rename from templates/milk.html
rename to myfirstproject/templates/milk.html
index 413af53..93196e1 100644
--- a/templates/milk.html
+++ b/myfirstproject/templates/milk.html
@@ -1,4 +1,4 @@
-{% extends 'product.html' %}
+{% extends 'product/product-detail.html' %}
{% block title %}
milk
@@ -10,10 +10,10 @@
Page product milk
{% block content %}
{% endblock %}
diff --git a/templates/product.html b/myfirstproject/templates/product/product-detail.html
similarity index 100%
rename from templates/product.html
rename to myfirstproject/templates/product/product-detail.html
diff --git a/myfirstproject/templates/product/product-list.html b/myfirstproject/templates/product/product-list.html
new file mode 100644
index 0000000..dc8a861
--- /dev/null
+++ b/myfirstproject/templates/product/product-list.html
@@ -0,0 +1,16 @@
+
+
+
+
+ Title
+
+
+Homepage
+
+ {% for object in object_list %}
+ - Product{{ object.product_n}}
+ {% endfor %}
+
+
+
+
\ No newline at end of file
diff --git a/myfirstproject/urls.py b/myfirstproject/urls.py
index 0a86315..8703ed2 100644
--- a/myfirstproject/urls.py
+++ b/myfirstproject/urls.py
@@ -1,12 +1,15 @@
from django.urls import path
from djangoProject.views import *
+from myfirstproject.views import *
-urlpatterns = [
+urlpatterns = {
path('profile', profile1, name='profile1'),
path('product', product1, name='product1'),
path('apple', apple1, name='apple1'),
path('milk', milk1, name='milk1'),
path('fish', fish1, name='fish1'),
- path('homepage', homepage1, name='homepage1')
-]
+ path('homepage', homepage1, name='homepage1'),
+ path('', product_list_views, name='product-list.html'),
+ path('/', product_detail_views, name='product-detail.html')
+}
diff --git a/myfirstproject/views.py b/myfirstproject/views.py
index 8be973b..b36f05c 100644
--- a/myfirstproject/views.py
+++ b/myfirstproject/views.py
@@ -1,6 +1,8 @@
from django.shortcuts import render
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpRequest
import random
+from myfirstproject.models import *
+
def main(request):
@@ -33,3 +35,16 @@ def generate_password(request, length):
number = random.randint(0, 9)
password_list = password_list + str(number)
return HttpResponse(f"Your random password {password_list}")
+
+
+def product_detail_views(request: HttpRequest, slug) -> HttpResponse:
+ context = {
+ }
+ return render(request, "product/product-detail.html", context)
+
+
+def product_list_views(request: HttpRequest) -> HttpResponse:
+ context = {
+ 'object_list': Product.objects.filter(in_stock=True)
+ }
+ return render(request, "product/product-list.html", context)