Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ap-11_django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
Давид Ли
ap-11_django
Commits
db6fb61e
Commit
db6fb61e
authored
Aug 21, 2023
by
Давид Ли
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web
parent
59608255
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
3 deletions
+56
-3
models.py
accounts/models.py
+14
-1
settings.py
core/settings.py
+4
-0
article.py
web/models/article.py
+38
-2
No files found.
accounts/models.py
View file @
db6fb61e
...
@@ -2,8 +2,21 @@ from django.contrib.auth.models import AbstractUser
...
@@ -2,8 +2,21 @@ from django.contrib.auth.models import AbstractUser
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
class
UserManager
(
models
.
Manager
):
def
all
(
self
):
return
super
()
.
all
()
.
filter
(
is_active
=
True
)
def
restore
(
self
):
return
self
.
get_queryset
()
.
update
(
is_active
=
True
)
def
delete
(
self
):
# Article.objects.delete()
return
self
.
get_queryset
()
.
update
(
is_active
=
False
)
class
User
(
AbstractUser
):
class
User
(
AbstractUser
):
pass
objects
=
UserManager
()
class
Profile
(
models
.
Model
):
class
Profile
(
models
.
Model
):
...
...
core/settings.py
View file @
db6fb61e
...
@@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
...
@@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
import
os
import
os
from
pathlib
import
Path
from
pathlib
import
Path
from
faker
import
Faker
# Build paths inside the project like this: BASE_DIR / 'subdir'.
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR
=
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
BASE_DIR
=
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
...
@@ -145,3 +147,5 @@ AUTH_USER_MODEL = 'accounts.User'
...
@@ -145,3 +147,5 @@ AUTH_USER_MODEL = 'accounts.User'
LOGIN_URL
=
'login'
LOGIN_URL
=
'login'
# LOGIN_REDIRECT_URL = 'main_page'
# LOGIN_REDIRECT_URL = 'main_page'
# LOGOUT_REDIRECT_URL = 'main_page'
# LOGOUT_REDIRECT_URL = 'main_page'
faker
=
Faker
()
web/models/article.py
View file @
db6fb61e
import
random
from
django.db
import
models
from
django.db
import
models
from
django.db.models
import
TextChoices
from
django.db.models
import
TextChoices
from
django.core.validators
import
MinLengthValidator
from
django.core.validators
import
MinLengthValidator
from
core.settings
import
faker
class
StatusChoices
(
TextChoices
):
class
StatusChoices
(
TextChoices
):
ACCEPTED
=
'accepted'
,
'Разрешено'
ACCEPTED
=
'accepted'
,
'Разрешено'
...
@@ -9,9 +13,41 @@ class StatusChoices(TextChoices):
...
@@ -9,9 +13,41 @@ class StatusChoices(TextChoices):
CHECK
=
'check'
,
'На проверке'
CHECK
=
'check'
,
'На проверке'
class
ArticlesManager
(
models
.
Manager
):
def
all
(
self
,
*
args
,
**
kwargs
):
# Article.objects.all() -> Article.objects.filter(status='accepted')
return
super
()
.
all
()
.
filter
(
status
=
'accepted'
)
# Article.objects.all().filter(status='accepted')
def
create_random_tags
(
self
):
from
web.models
import
Tag
random_count
=
random
.
randint
(
5
,
15
)
for
obj
in
self
.
get_queryset
():
obj
.
tags
.
add
(
*
(
Tag
(
name
=
faker
.
company
())
.
save
()
for
_
in
range
(
random_count
)
)
)
def
create_random_comments
(
self
):
from
web.models
import
Comment
random_count
=
random
.
randint
(
5
,
15
)
for
obj
in
self
.
get_queryset
():
obj
.
comments
.
bulk_create
(
(
Comment
(
text
=
faker
.
text
(),
article_id
=
obj
.
id
)
for
_
in
range
(
random_count
)
)
)
class
Article
(
models
.
Model
):
class
Article
(
models
.
Model
):
# CharField = varchar
objects
=
ArticlesManager
()
# title varchar(200) not null
title
=
models
.
CharField
(
title
=
models
.
CharField
(
max_length
=
200
,
max_length
=
200
,
null
=
False
,
# <null>
null
=
False
,
# <null>
...
...
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