Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop models #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djangoProject/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
Original file line number Diff line number Diff line change
@@ -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)]),
),
]
4 changes: 2 additions & 2 deletions templates/apple.html → myfirstproject/templates/apple.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'product.html' %}
{% extends 'product/product-detail.html' %}

{% block title %}
apple
Expand All @@ -11,7 +11,7 @@ <h2>Page product apple</h2>
{% block content %}
<ul>
<li>
<a href="homepage.html">homepage</a>
<a href="../../templates/homepage.html">homepage</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай через url

</li>
<li>
<a href="profile">profile user</a>
Expand Down
4 changes: 2 additions & 2 deletions templates/fish.html → myfirstproject/templates/fish.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'product.html' %}
{% extends 'product/product-detail.html' %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай через url


{% block title %}
fish
Expand All @@ -11,7 +11,7 @@ <h2>Page product fish</h2>
{% block content %}
<ul>
<li>
<a href="homepage.html">homepage</a>
<a href="../../templates/homepage.html">homepage</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай через url

</li>
<li>
<a href="profile">profile user</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/milk.html → myfirstproject/templates/milk.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'product.html' %}
{% extends 'product/product-detail.html' %}

{% block title %}
milk
Expand All @@ -10,10 +10,10 @@ <h2>Page product milk</h2>
{% block content %}
<ul>
<li>
<a href="homepage.html">homepage</a>
<a href="../../templates/homepage.html">homepage</a>
</li>
<li>
<a href="profile.html">profile user</a>
<a href="../../templates/profile.html">profile user</a>
</li>
</ul>
{% endblock %}
File renamed without changes.
16 changes: 16 additions & 0 deletions myfirstproject/templates/product/product-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Homepage</h1>
<ul>
{% for object in object_list %}
<li><a href="product-list.html" slug=object.slug></a>Product{{ object.product_n}}</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<li><a href="product-list.html" slug=object.slug></a>Product{{ object.product_n}}</li>
<li><a href="{ % url "product-list.html" slug=object.slug %}"></a>Product{{ object.product_n}}</li>

Таке треба робити з використанням тегів

{% endfor %}

</ul>
</body>
</html>
9 changes: 6 additions & 3 deletions myfirstproject/urls.py
Original file line number Diff line number Diff line change
@@ -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('<slug:slug>/', product_detail_views, name='product-detail.html')
}
17 changes: 16 additions & 1 deletion myfirstproject/views.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)