Skip to content

Commit

Permalink
Changes some migration
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Feb 15, 2024
1 parent cefd519 commit 73344af
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
"--line-length",//how long to be each line our code,well know we limited our code length each line when formatting code using black
"120",//length each line
],
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
}
}
9 changes: 9 additions & 0 deletions backend/abstract/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ class AppName(Enum):

# !Genders
Genders = [("MALE", _("male")), ("FEMALE", _("female"))]

# !Genders Pet
GendersPet = [
("MALE", _("male")),
("FEMALE", _("female")),
("Neutered ", _("neutered ")),
("Spayed", _("spayed")),
("Other", _("other")),
]
120 changes: 120 additions & 0 deletions backend/apps/user_profile/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Generated by Django 5.0.1 on 2024-02-15 05:18

import django_extensions.db.fields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Profile",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"slug",
models.SlugField(
blank=True, editable=False, unique=True, verbose_name="Slug"
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, null=True, verbose_name="First name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, null=True, verbose_name="Last name"
),
),
(
"full_name",
models.CharField(
blank=True, max_length=150, verbose_name="Full name"
),
),
(
"profile_key",
django_extensions.db.fields.RandomCharField(
blank=True,
editable=False,
length=12,
unique=True,
verbose_name="Profile key",
),
),
(
"country",
models.CharField(blank=True, max_length=50, verbose_name="Country"),
),
(
"city",
models.CharField(
blank=True, max_length=50, null=True, verbose_name="City"
),
),
(
"adress",
models.CharField(
blank=True, max_length=50, null=True, verbose_name="Adress"
),
),
(
"additional_information",
models.TextField(blank=True, verbose_name="Additional Information"),
),
(
"is_active",
models.BooleanField(default=False, verbose_name="Is active"),
),
(
"account_type",
models.CharField(
choices=[("ADMIN", "admin"), ("GENERAL", "general")],
default="GENERAL",
max_length=20,
null=True,
verbose_name="Account type",
),
),
(
"status",
models.CharField(
choices=[("ACTIVE", "active"), ("INACTIVE", "inactive")],
default="INACTIVE",
max_length=20,
null=True,
verbose_name="Status",
),
),
(
"gender",
models.CharField(
blank=True,
choices=[("MALE", "male"), ("FEMALE", "female")],
max_length=20,
null=True,
verbose_name="Gender",
),
),
],
options={
"verbose_name": "Profile",
"verbose_name_plural": "Profiles",
},
),
]
28 changes: 28 additions & 0 deletions backend/apps/user_profile/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.1 on 2024-02-15 05:18

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
("user_profile", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name="profile",
name="user",
field=models.OneToOneField(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
verbose_name="User",
),
),
]
File renamed without changes.
6 changes: 5 additions & 1 deletion backend/apps/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
list_display_links = ["id", "email", "wallet_address"]
list_display = (
"id",
"email",
"wallet_address",
"is_staff",
"is_active",
)
list_filter = (
"email",
"wallet_address",
"is_staff",
"is_active",
)
fieldsets = (
(None, {"fields": ("email", "password")}),
(None, {"fields": ("email", "wallet_address", "password")}),
(
"Permissions",
{"fields": ("is_staff", "is_active", "groups", "user_permissions")},
Expand Down
106 changes: 106 additions & 0 deletions backend/apps/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Generated by Django 5.0.1 on 2024-02-15 05:29

import django.utils.timezone
from django.db import migrations, models

import config.helpers


class Migration(migrations.Migration):

initial = True

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

operations = [
migrations.CreateModel(
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",
),
),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="Email address"
),
),
(
"wallet_address",
models.CharField(
blank=True,
db_index=True,
max_length=100,
null=True,
unique=True,
validators=[config.helpers.is_valid_wallet_address],
verbose_name="Wallet address",
),
),
(
"is_staff",
models.BooleanField(default=False, verbose_name="Is staff"),
),
(
"is_active",
models.BooleanField(default=True, verbose_name="Is active"),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="Date joined"
),
),
(
"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",
"ordering": ["-date_joined"],
},
),
]
Empty file.
25 changes: 21 additions & 4 deletions backend/apps/users/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.core.validators import RegexValidator
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from config.helpers import is_valid_wallet_address

from .managers import CustomUserManager

# Create your models here.
Expand All @@ -11,15 +14,29 @@
# !CustomUser
class CustomUser(AbstractBaseUser, PermissionsMixin):
username = None
email = models.EmailField(_("email address"), unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
email = models.EmailField(_("Email address"), unique=True)
wallet_address = models.CharField(
_("Wallet address"),
unique=True,
db_index=True,
max_length=100,
blank=True,
null=True,
validators=[is_valid_wallet_address],
)
is_staff = models.BooleanField(_("Is staff"), default=False)
is_active = models.BooleanField(_("Is active"), default=True)
date_joined = models.DateTimeField(_("Date joined"), default=timezone.now)

USERNAME_FIELD = "email"
REQUIRED_FIELDS = []

objects = CustomUserManager()

class Meta:
verbose_name = _("Custom user")
verbose_name_plural = _("Custom users")
ordering = ["-date_joined"]

def __str__(self):
return self.email
16 changes: 15 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ feedparser = "^6.0.11"
pre-commit = "^3.6.0"
pytest-factoryboy = "^2.6.0"
pytest-django = "^4.8.0"
django-colorfield = "^0.11.0"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Backend
- `poetry run pytest --cov=./ --cov-report=html`
- Check code formatting is needed or not:
- `poetry run black . --check`
- Sort imports using isort with Black profile:
- Sor t imports using isort with Black profile:
- `poetry run isort . --profile black`
- Check code style with Flake8:
- `poetry run flake8 .`
Expand Down

0 comments on commit 73344af

Please sign in to comment.