Skip to content

Commit 5ea6bb8

Browse files
committed
Edit docstrings, add datetime_created to CustomUser, refactor Member and Mentor fields
1 parent a0ea1d9 commit 5ea6bb8

4 files changed

Lines changed: 100 additions & 26 deletions

File tree

users/admin.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class CustomUserAdmin(admin.ModelAdmin):
3636
{
3737
"fields": (
3838
"about_me",
39-
# "key_skills",
40-
# "useful_to_project",
4139
"status",
42-
# "speciality",
4340
"city",
4441
"region",
4542
"organization",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 4.1.2 on 2022-11-06 14:37
2+
3+
from django.db import migrations, models
4+
import django.utils.timezone
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("industries", "0001_initial"),
11+
("users", "0011_expert_additional_role_investor_additional_role_and_more"),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name="member",
17+
name="speciality",
18+
),
19+
migrations.RemoveField(
20+
model_name="mentor",
21+
name="job",
22+
),
23+
migrations.AddField(
24+
model_name="customuser",
25+
name="datetime_created",
26+
field=models.DateTimeField(
27+
auto_now_add=True, default=django.utils.timezone.now
28+
),
29+
preserve_default=False,
30+
),
31+
migrations.AddField(
32+
model_name="member",
33+
name="preferred_industries",
34+
field=models.ManyToManyField(
35+
blank=True, related_name="members", to="industries.industry"
36+
),
37+
),
38+
migrations.AlterField(
39+
model_name="member",
40+
name="key_skills",
41+
field=models.CharField(blank=True, max_length=512),
42+
),
43+
]

users/models.py

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.dispatch import receiver
55

66
from industries.models import Industry
7-
87
from users.managers import CustomUserManager
98

109

@@ -14,26 +13,27 @@ def get_default_user_type():
1413

1514
class CustomUser(AbstractUser):
1615
"""
17-
User model
16+
CustomUser model
17+
18+
This model is used to store the user common information.
1819
1920
Attributes:
2021
email: CharField instance of user's email.
2122
first_name: CharField instance of the user first name.
2223
last_name: CharField instance of the user last name.
23-
patronymic: CharField instance of the user patronymic.
2424
password: CharField instance of the user password.
2525
is_active: Boolean indicating if user confirmed email.
26-
birthday: DateField instance of the user's birthday.
26+
user_type: PositiveSmallIntegerField indicating the user's type according to VERBOSE_USER_TYPES.
27+
patronymic: CharField instance of the user patronymic.
2728
avatar: URLField instance of the user's avatar url.
28-
key_skills: CharField instance of user skills containing keys.
29-
useful_to_project: CharField instance of the something useful... TODO
29+
birthday: DateField instance of the user's birthday.
3030
about_me: TextField instance contains information about the user.
3131
status: CharField instance notifies about the user's status.
32-
speciality: CharField instance the user's specialty.
33-
city: CharField instance the user's name city.
3432
region: CharField instance the user's name region.
33+
city: CharField instance the user's name city.
3534
organization: CharField instance the user's place of study or work.
36-
tags: CharField instance tags. TODO
35+
datetime_updated: A DateTimeField indicating date of update.
36+
datetime_created: A DateTimeField indicating date of creation.
3737
"""
3838

3939
ADMIN = 0
@@ -56,14 +56,12 @@ class CustomUser(AbstractUser):
5656
last_name = models.CharField(max_length=255, blank=False)
5757
password = models.CharField(max_length=255, blank=False)
5858
is_active = models.BooleanField(default=False, editable=False)
59-
datetime_updated = models.DateTimeField(auto_now=True)
60-
6159
user_type = models.PositiveSmallIntegerField(
6260
choices=VERBOSE_USER_TYPES,
6361
default=get_default_user_type,
6462
)
6563

66-
patronymic = models.CharField(max_length=255, blank=True) # Отчество
64+
patronymic = models.CharField(max_length=255, blank=True)
6765
avatar = models.URLField(null=True, blank=True)
6866
birthday = models.DateField(null=True)
6967
about_me = models.TextField(blank=True)
@@ -72,6 +70,9 @@ class CustomUser(AbstractUser):
7270
city = models.CharField(max_length=255, blank=True)
7371
organization = models.CharField(max_length=255, blank=True)
7472

73+
datetime_updated = models.DateTimeField(null=False, auto_now=True)
74+
datetime_created = models.DateTimeField(null=False, auto_now_add=True)
75+
7576
USERNAME_FIELD = "email"
7677
REQUIRED_FIELDS = []
7778

@@ -87,6 +88,17 @@ def __str__(self):
8788

8889

8990
class AbstractUserWithRole(models.Model):
91+
"""
92+
AbstractUserWithRole abstract model
93+
94+
This model adds additional role field to the user model.
95+
96+
Attributes:
97+
additional_role: PositiveSmallIntegerField indicating the user's additional role
98+
according to VERBOSE_ROLE_TYPES.
99+
100+
"""
101+
90102
MENTOR = 2
91103
EXPERT = 3
92104
INVESTOR = 4
@@ -107,13 +119,28 @@ class Meta:
107119

108120

109121
class Member(models.Model):
122+
"""
123+
Member model
124+
125+
Represents the CustomUser with the MEMBER user type.
126+
127+
Attributes:
128+
user: ForeignKey instance of the CustomUser model.
129+
key_skills: CharField instance indicating member key skills.
130+
useful_to_project: TextField instance indicates actions useful
131+
for the development and maintenance of the project.
132+
preferred_industries: ManyToManyField indicating user industries preferred for work.
133+
"""
134+
110135
user = models.OneToOneField(
111136
CustomUser, on_delete=models.CASCADE, related_name="member"
112137
)
113138

114-
key_skills = models.CharField(max_length=255, blank=True) # TODO
139+
key_skills = models.CharField(max_length=512, blank=True)
115140
useful_to_project = models.TextField(blank=True)
116-
speciality = models.CharField(max_length=255, blank=True)
141+
preferred_industries = models.ManyToManyField(
142+
Industry, blank=True, related_name="members"
143+
)
117144

118145
def __str__(self):
119146
return f"Member<{self.id}> - {self.user.first_name} {self.user.last_name}"
@@ -123,16 +150,19 @@ class Mentor(AbstractUserWithRole):
123150
"""
124151
Mentor model
125152
153+
Represents the CustomUser with the MENTOR user type.
154+
126155
Attributes:
127-
job: CharField instance current user job.
128-
useful_to_project: CharField instance some text.
156+
user: ForeignKey instance of the CustomUser model.
157+
useful_to_project: TextField instance indicates actions useful
158+
for the development and maintenance of the project.
129159
"""
130160

131161
user = models.OneToOneField(
132162
CustomUser, on_delete=models.CASCADE, related_name="mentor"
133163
)
134-
135-
job = models.CharField(max_length=255, blank=True)
164+
# CustomUser already has a field called "organization"
165+
# job = models.CharField(max_length=255, blank=True)
136166
useful_to_project = models.TextField(blank=True)
137167

138168
def __str__(self):
@@ -143,9 +173,12 @@ class Expert(AbstractUserWithRole):
143173
"""
144174
Expert model
145175
176+
Represents the CustomUser with the EXPERT user type.
177+
146178
Attributes:
147-
preferred_industries: CharField instance TODO
148-
useful_to_project: CharField instance TODO
179+
preferred_industries: ManyToManyField indicating user industries preferred for work.
180+
useful_to_project: TextField instance indicates actions useful
181+
for the development and maintenance of the project.
149182
"""
150183

151184
user = models.OneToOneField(
@@ -167,8 +200,10 @@ class Investor(AbstractUserWithRole):
167200
"""
168201
Investor model
169202
203+
Represents the CustomUser with the INVESTOR user type.
204+
170205
Attributes:
171-
preferred_industries: CharField instance TODO
206+
preferred_industries: ManyToManyField indicating user industries preferred for work.
172207
interaction_process_description: CharField describes the interaction process.
173208
174209
"""

users/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ class Meta:
1010
fields = [
1111
"key_skills",
1212
"useful_to_project",
13-
"speciality",
13+
"preferred_industries",
1414
]
1515

1616

1717
class MentorSerializer(serializers.ModelSerializer):
1818
class Meta:
1919
model = Mentor
2020
fields = [
21-
"job",
2221
"useful_to_project",
2322
"additional_role",
2423
]

0 commit comments

Comments
 (0)