Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lesson_34
Project
Project
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
Владислав Андреев
lesson_34
Commits
b39c8159
Commit
b39c8159
authored
Jul 01, 2021
by
Владислав Андреев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a2c7d15c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
43 deletions
+42
-43
genre_form.py
article/forms/genre_form.py
+15
-4
0005_genre_description.py
article/migrations/0005_genre_description.py
+2
-2
0006_alter_genre_description.py
article/migrations/0006_alter_genre_description.py
+0
-18
models.py
article/models.py
+2
-2
genre_view.py
article/views/genre_view.py
+16
-5
create.html
templates/genre/create.html
+7
-12
No files found.
article/forms/genre_form.py
View file @
b39c8159
from
django
import
forms
from
django
import
forms
from
article.models
import
Genre
class
GenreForm
(
forms
.
Form
):
class
GenreForm
(
forms
.
Form
):
title
=
forms
.
CharField
(
title
=
forms
.
CharField
(
required
=
True
,
required
=
True
,
max_length
=
50
,
max_length
=
50
,
min_length
=
3
,
min_length
=
3
,
label
=
"Название жанра"
)
label
=
"Название жанра"
,
description
=
forms
.
CharField
(
required
=
False
,
max_length
=
500
,
label
=
"Описание"
,
widget
=
forms
.
Textarea
(
attrs
=
{
'style'
:
'border: 2px solid red'
}))
widget
=
forms
.
TextInput
(
attrs
=
{
"class"
:
'form-control'
,
"placeholder"
:
"Название"
})
)
description
=
forms
.
CharField
(
required
=
False
,
max_length
=
500
,
label
=
"Описание"
,
widget
=
forms
.
Textarea
(
attrs
=
{
"class"
:
'form-control'
,
"rows"
:
'3'
}),
)
class
Meta
:
class
Meta
:
fields
=
[
'title'
,
'description'
]
fields
=
[
'title'
,
'description'
]
...
...
article/migrations/0005_genre_description.py
View file @
b39c8159
# Generated by Django 3.2.4 on 2021-06-
28 15:08
# Generated by Django 3.2.4 on 2021-06-
30 14:34
from
django.db
import
migrations
,
models
from
django.db
import
migrations
,
models
...
@@ -13,6 +13,6 @@ class Migration(migrations.Migration):
...
@@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations
.
AddField
(
migrations
.
AddField
(
model_name
=
'genre'
,
model_name
=
'genre'
,
name
=
'description'
,
name
=
'description'
,
field
=
models
.
CharField
(
default
=
'
описание
'
,
max_length
=
100
,
verbose_name
=
'Описание'
),
field
=
models
.
CharField
(
default
=
'
Название не указано
'
,
max_length
=
100
,
verbose_name
=
'Описание'
),
),
),
]
]
article/migrations/0006_alter_genre_description.py
deleted
100644 → 0
View file @
a2c7d15c
# Generated by Django 3.2.4 on 2021-06-30 08:02
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'article'
,
'0005_genre_description'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'genre'
,
name
=
'description'
,
field
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
'Описание'
),
),
]
article/models.py
View file @
b39c8159
...
@@ -10,8 +10,8 @@ class Author(models.Model):
...
@@ -10,8 +10,8 @@ class Author(models.Model):
class
Genre
(
models
.
Model
):
class
Genre
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
,
null
=
False
,
blank
=
False
,
verbose_name
=
'Название'
,
)
title
=
models
.
CharField
(
max_length
=
50
,
null
=
False
,
blank
=
False
,
verbose_name
=
'Название'
)
description
=
models
.
CharField
(
max_length
=
100
,
null
=
False
,
blank
=
False
,
verbose_name
=
'Описание'
)
description
=
models
.
CharField
(
max_length
=
100
,
null
=
False
,
blank
=
False
,
verbose_name
=
'Описание'
,
default
=
"Название не указано"
)
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"{self.pk}. {self.title}"
return
f
"{self.pk}. {self.title}"
...
...
article/views/genre_view.py
View file @
b39c8159
...
@@ -9,17 +9,28 @@ def genre_create_view(request):
...
@@ -9,17 +9,28 @@ def genre_create_view(request):
return
render
(
request
,
'genre/create.html'
,
context
=
{
'form'
:
form
})
return
render
(
request
,
'genre/create.html'
,
context
=
{
'form'
:
form
})
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
form
=
GenreForm
(
request
.
POST
)
form
=
GenreForm
(
request
.
POST
)
if
form
.
is_valid
():
if
form
.
is_valid
():
genre
=
Genre
.
objects
.
create
(
genre
=
Genre
.
objects
.
create
(
title
=
form
.
cleaned_data
[
'title'
]
,
title
=
form
.
cleaned_data
.
get
(
'title'
)
,
description
=
form
.
cleaned_data
[
'description'
]
description
=
form
.
cleaned_data
.
get
(
'description'
)
)
)
genre
.
save
()
genre
.
save
()
return
redirect
(
'list_genre'
)
return
redirect
(
'list_genre'
)
else
:
return
render
(
request
,
'genre/create.html'
,
context
=
{
'form'
:
form
})
return
render
(
request
,
'genre/create.html'
,
context
=
{
'form'
:
form
})
# if request.method == 'POST':
# form = GenreForm(request.POST)
#
# if form.is_valid():
# genre = Genre.objects.create(
# title=form.cleaned_data['title'],
# description=form.cleaned_data['description']
# )
# genre.save()
# return redirect('list_genre')
#
# return render(request, 'genre/create.html', context={'form': form})
def
genre_list_view
(
request
):
def
genre_list_view
(
request
):
...
...
templates/genre/create.html
View file @
b39c8159
{% extends 'base.html' %}
{% extends 'base.html' %}
{% block content %}
{% block content %}
{{ form.error.non_field_errors }}
<form
action=
"{% url 'add_genre' %}"
method=
"POST"
>
<form
action=
"{% url 'add_genre' %}"
method=
"POST"
>
{% csrf_token %}
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.errors.title }}
<div
class=
"form-group"
>
<label
class=
"form-label"
for=
"{{ form.title.id_for_label }}"
>
{{ form.title.label }}
</label>
{{ form.messages.title }}
<label
for=
"{{ form.title.id_for_label }}"
>
{{ form.title.label }}
</label>
{{ form.title }}
{{ form.title }}
</div>
<div
class=
"form-group"
>
{{ form.messages.description }}
{{ form.messages.description }}
<label
for=
"{{ form.description.id_for_label }}"
>
{{ form.description.label }}
</label>
<label
class=
"form-label"
for=
"{{ form.description.id_for_label }}"
>
{{ form.description.label }}
</label>
{{ form.description }}
{{ form.description }}
</div>
<input
type=
"submit"
value=
"Создать"
>
<input
type=
"submit"
value=
"Создать"
>
</form>
</form>
{% endblock %}
{% endblock %}
\ No newline at end of file
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