Skip to content

Commit

Permalink
Merge pull request #13 from healthy-food-and-dietary-products/create_…
Browse files Browse the repository at this point in the history
…user_model

Restore back the correct settings, make migration file
  • Loading branch information
Govorlivyh authored Oct 19, 2023
2 parents 67bac95 + 37f8f00 commit 47f7deb
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 34 deletions.
26 changes: 17 additions & 9 deletions backend/good_food/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"products.apps.ProductsConfig",
"users.apps.UsersConfig",
"api.apps.ApiConfig",
"phonenumber_field",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -89,14 +90,14 @@

DATABASES = {
"default": {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
# "ENGINE": os.getenv("DB_ENGINE", default="django.db.backends.postgresql"),
# "NAME": os.getenv("DB_NAME", default="postgres"),
# "USER": os.getenv("POSTGRES_USER", default="postgres"),
# "PASSWORD": os.getenv("POSTGRES_PASSWORD", default="postgres"),
# "HOST": os.getenv("DB_HOST", default="db"),
# "PORT": os.getenv("DB_PORT", default="5432"),
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": BASE_DIR / "db.sqlite3",
"ENGINE": os.getenv("DB_ENGINE", default="django.db.backends.postgresql"),
"NAME": os.getenv("DB_NAME", default="postgres"),
"USER": os.getenv("POSTGRES_USER", default="postgres"),
"PASSWORD": os.getenv("POSTGRES_PASSWORD", default="postgres"),
"HOST": os.getenv("DB_HOST", default="db"),
"PORT": os.getenv("DB_PORT", default="5432"),
}
}

Expand Down Expand Up @@ -125,7 +126,7 @@

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"
TIME_ZONE = "Europe/Moscow"

USE_I18N = True

Expand All @@ -141,3 +142,10 @@
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# User model
AUTH_USER_MODEL = 'users.User'

# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
213 changes: 213 additions & 0 deletions backend/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Generated by Django 4.2.6 on 2023-10-19 04:01

import django.contrib.auth.models
import django.core.validators
from django.db import migrations, models
import django.utils.timezone
import phonenumber_field.modelfields
import users.models


class Migration(migrations.Migration):
initial = True

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

operations = [
migrations.CreateModel(
name="User",
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",
),
),
(
"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"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"username",
models.CharField(
max_length=150, unique=True, verbose_name="Username"
),
),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="E-mail address"
),
),
(
"role",
models.CharField(
choices=[
("user", "Аутентифицированный пользователь"),
("moderator", "Модератор"),
("admin", "Администратор"),
],
default="user",
max_length=9,
),
),
(
"city",
models.CharField(blank=True, max_length=30, verbose_name="City"),
),
(
"birth_date",
models.DateField(blank=True, null=True, verbose_name="Birth_date"),
),
(
"address_quantity",
models.IntegerField(
default=0,
validators=[django.core.validators.MaxValueValidator(5)],
verbose_name="number_of_cities",
),
),
(
"phone_number",
phonenumber_field.modelfields.PhoneNumberField(
blank=True,
max_length=128,
region=None,
verbose_name="Phone_number",
),
),
(
"photo",
models.ImageField(
blank=True,
default="default.jpg",
upload_to=users.models.User.user_directory_path,
verbose_name="Photo",
),
),
],
options={
"ordering": ("id",),
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name="Address",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("country", models.CharField(max_length=100, verbose_name="Country")),
("city", models.CharField(max_length=100, verbose_name="City")),
("street", models.CharField(max_length=100, verbose_name="Street")),
("house", models.IntegerField(verbose_name="House_number")),
(
"building",
models.IntegerField(
blank=True, null=True, verbose_name="Buiding_number"
),
),
("apartment", models.IntegerField(verbose_name="Apartment_number")),
],
options={
"verbose_name": "Address",
"verbose_name_plural": "Addresses",
},
),
migrations.AddConstraint(
model_name="address",
constraint=models.UniqueConstraint(
fields=("city", "street", "house", "building", "apartment"),
name="unique address",
),
),
migrations.AddField(
model_name="user",
name="address",
field=models.ManyToManyField(
related_name="users", to="users.address", verbose_name="Addresses"
),
),
migrations.AddField(
model_name="user",
name="groups",
field=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",
),
),
migrations.AddField(
model_name="user",
name="user_permissions",
field=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",
),
),
]
44 changes: 20 additions & 24 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pep8-naming = "^0.13.3"
flake8-broken-line = "^1.0.0"
flake8-return = "^1.2.0"
flake8-isort = "^6.1.0"
black = "^23.9.1"
isort = "^5.12.0"
pytest = "^7.4.2"
black = "^23.10.0"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 47f7deb

Please sign in to comment.