Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python_django_2025
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
python_django_2025
Commits
f7275052
Commit
f7275052
authored
May 16, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wypełnienie aplikacji sklep zawartością
parent
201bb0a4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
0 deletions
+95
-0
admin.py
sklep/admin.py
+5
-0
0001_initial.py
sklep/migrations/0001_initial.py
+32
-0
models.py
sklep/models.py
+10
-0
towary.html
sklep/templates/towary.html
+24
-0
views.py
sklep/views.py
+19
-0
urls.py
webowy/urls.py
+5
-0
No files found.
sklep/admin.py
View file @
f7275052
from
django.contrib
import
admin
from
django.contrib
import
admin
# Register your models here.
# Register your models here.
# from sklep.models import Product
from
.models
import
*
admin
.
site
.
register
(
Product
)
sklep/migrations/0001_initial.py
0 → 100644
View file @
f7275052
# Generated by Django 5.2.1 on 2025-05-16 08:24
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
=
100
)),
(
"price"
,
models
.
DecimalField
(
decimal_places
=
2
,
max_digits
=
10
)),
(
"vat"
,
models
.
DecimalField
(
decimal_places
=
2
,
max_digits
=
2
)),
(
"valid_to"
,
models
.
DateField
(
blank
=
True
,
null
=
True
)),
(
"available"
,
models
.
BooleanField
(
default
=
True
)),
],
),
]
sklep/models.py
View file @
f7275052
from
django.db
import
models
from
django.db
import
models
# Create your models here.
# Create your models here.
class
Product
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
price
=
models
.
DecimalField
(
max_digits
=
10
,
decimal_places
=
2
)
vat
=
models
.
DecimalField
(
max_digits
=
2
,
decimal_places
=
2
)
valid_to
=
models
.
DateField
(
blank
=
True
,
null
=
True
)
available
=
models
.
BooleanField
(
default
=
True
)
def
vat_jako_calkowita
(
self
):
return
int
(
100
*
self
.
vat
)
sklep/templates/towary.html
0 → 100644
View file @
f7275052
<!DOCTYPE html>
<html
lang=
"pl"
>
<head>
<meta
charset=
"utf-8"
>
<title>
Produkty naszego sklepu
</title>
</head>
<body>
<h1>
Lista towarów
</h1>
<ul>
{% for p in products %}
<li>
towar: {{ p.name }} - cena {{ p.price }} zł, {{ p.vat_jako_calkowita }}% VAT
{% if p.valid_to %}
<br/>
(termin ważności {{p.valid_to}})
{% endif %}
{% if not p.available %}
<br/><strong>
Produkt niedostępny
</strong>
{% endif %}
</li>
{% endfor %}
</ul>
</body>
</html>
sklep/views.py
View file @
f7275052
from
django.http
import
HttpRequest
,
HttpResponse
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
.models
import
*
# Create your views here.
# Create your views here.
def
lista_produktow
(
request
:
HttpRequest
)
->
HttpResponse
:
produkty
=
Product
.
objects
.
all
()
return
HttpResponse
(
str
(
produkty
),
content_type
=
'text/plain'
)
def
lista_produktow_txt
(
request
:
HttpRequest
)
->
HttpResponse
:
products
=
Product
.
objects
.
all
()
wynik
=
'Produkty naszego sklepu:'
for
product
in
products
:
wynik
+=
f
'
\n
- {product.name} za {product.price} zł'
return
HttpResponse
(
wynik
,
content_type
=
'text/plain;charset=utf-8'
)
def
lista_produktow_html
(
request
:
HttpRequest
)
->
HttpResponse
:
products
=
Product
.
objects
.
all
()
return
render
(
request
,
'towary.html'
,
context
=
{
'products'
:
products
})
webowy/urls.py
View file @
f7275052
...
@@ -19,6 +19,7 @@ from django.contrib import admin
...
@@ -19,6 +19,7 @@ from django.contrib import admin
from
django.urls
import
path
from
django.urls
import
path
from
aplikacja.views
import
*
from
aplikacja.views
import
*
import
sklep.views
urlpatterns
=
[
urlpatterns
=
[
path
(
"admin/"
,
admin
.
site
.
urls
),
path
(
"admin/"
,
admin
.
site
.
urls
),
...
@@ -31,4 +32,8 @@ urlpatterns = [
...
@@ -31,4 +32,8 @@ urlpatterns = [
path
(
"kalkulator"
,
kalkulator
),
path
(
"kalkulator"
,
kalkulator
),
path
(
"kalkulator_post"
,
kalkulator_post
),
path
(
"kalkulator_post"
,
kalkulator_post
),
path
(
"formularz"
,
formularz
),
path
(
"formularz"
,
formularz
),
path
(
"sklep"
,
sklep
.
views
.
lista_produktow
),
path
(
"sklep.txt"
,
sklep
.
views
.
lista_produktow_txt
),
path
(
"sklep.html"
,
sklep
.
views
.
lista_produktow_html
),
]
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment