Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
RustamovAkrom committed Sep 19, 2024
1 parent e57d07f commit 506acec
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 111 deletions.
38 changes: 13 additions & 25 deletions apps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,22 @@
@admin.register(CustomUser)
class CustomUserAdmin(admin.ModelAdmin):
list_display = [
'username',
'first_name',
'last_name',
'email',
'phone_number',
'avatar',
'is_active',
]
list_filter = [
'username',
'first_name',
'last_name',
'email',
'phone_number'
]
search_fields = [
'username',
'first_name',
'last_name',
'email',
'phone_number'
"username",
"first_name",
"last_name",
"email",
"phone_number",
"avatar",
"is_active",
]
list_filter = ["username", "first_name", "last_name", "email", "phone_number"]
search_fields = ["username", "first_name", "last_name", "email", "phone_number"]


@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
list_display = [
'user',
'bio',
'date_of_birth',
]
"user",
"bio",
"date_of_birth",
]
4 changes: 2 additions & 2 deletions apps/account/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class AccountConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.account'
default_auto_field = "django.db.models.BigAutoField"
name = "apps.account"
165 changes: 137 additions & 28 deletions apps/account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,158 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.CreateModel(
name='CustomUser',
name="CustomUser",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('phone_number', models.CharField(blank=True, max_length=15, null=True)),
('avatar', models.ImageField(blank=True, null=True, upload_to='avatars/')),
('is_active', models.BooleanField(default=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"phone_number",
models.CharField(blank=True, max_length=15, null=True),
),
(
"avatar",
models.ImageField(blank=True, null=True, upload_to="avatars/"),
),
("is_active", models.BooleanField(default=True)),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.permission",
verbose_name="user permissions",
),
),
],
options={
'verbose_name': 'Custom User',
'verbose_name_plural': 'Custom Users',
"verbose_name": "Custom User",
"verbose_name_plural": "Custom Users",
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='UserProfile',
name="UserProfile",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bio', models.TextField(blank=True, null=True)),
('date_of_birth', models.DateField(blank=True, null=True)),
('gender', models.CharField(blank=True, choices=[('male', 'Male'), ('female', 'Female')], max_length=6)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("bio", models.TextField(blank=True, null=True)),
("date_of_birth", models.DateField(blank=True, null=True)),
(
"gender",
models.CharField(
blank=True,
choices=[("male", "Male"), ("female", "Female")],
max_length=6,
),
),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="profile",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
'verbose_name': 'User Profile',
'verbose_name_plural': 'User Profiles',
"verbose_name": "User Profile",
"verbose_name_plural": "User Profiles",
},
),
]
13 changes: 7 additions & 6 deletions apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class CustomUser(AbstractUser):
phone_number = models.CharField(max_length=15, blank=True, null=True)
avatar = models.ImageField(upload_to='avatars/', blank=True, null=True)
avatar = models.ImageField(upload_to="avatars/", blank=True, null=True)
is_active = models.BooleanField(default=True)

class Meta:
Expand All @@ -14,15 +14,17 @@ class Meta:

def __str__(self) -> str:
return self.username


class UserProfile(models.Model):
GENDER_CHOICE = [
('male', 'Male'),
('female', 'Female'),
("male", "Male"),
("female", "Female"),
]

user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, related_name='profile')
user = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, related_name="profile"
)
bio = models.TextField(blank=True, null=True)
date_of_birth = models.DateField(null=True, blank=True)
gender = models.CharField(max_length=6, choices=GENDER_CHOICE, blank=True)
Expand All @@ -33,4 +35,3 @@ class Meta:

def __str__(self) -> str:
return f"{self.user.username}`s Profile"

2 changes: 1 addition & 1 deletion apps/account/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
from django.test import TestCase # noqa

# Create your tests here.
9 changes: 3 additions & 6 deletions apps/account/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
text_type(user.pk) + text_type(timestamp) +
text_type(user.is_active)
)

return text_type(user.pk) + text_type(timestamp) + text_type(user.is_active)

account_activation_token = AccountActivationTokenGenerator()

account_activation_token = AccountActivationTokenGenerator()
2 changes: 1 addition & 1 deletion apps/account/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
from django.shortcuts import render # noqa

# Create your views here.
Loading

0 comments on commit 506acec

Please sign in to comment.