Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
from datetime import timedelta

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -37,7 +38,9 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core'
'rest_framework',
'rest_framework_simplejwt.token_blacklist',
'core',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -74,13 +77,64 @@
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'test_db',
'USER': 'postgres',
'PASSWORD': 'seismic25',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,
'UPDATE_LAST_LOGIN': False,

'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUDIENCE': None,
'ISSUER': None,
'JWK_URL': None,
'LEEWAY': 0,

'AUTH_HEADER_TYPES': ('Bearer',),
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',

'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',

'JTI_CLAIM': 'jti',

'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=60),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}

# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
Expand Down
3 changes: 2 additions & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('core.urls')),
]
27 changes: 24 additions & 3 deletions app/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
"""Manage admin page for main app."""
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User, Product, Category, Order

# from django.contrib import admin
class UserAdmin(BaseUserAdmin):
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),

# Register your models here.
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'username', 'first_name', 'last_name', 'password1', 'password2'),
}),
)
list_display = ('email', 'first_name', 'last_name', 'is_staff')
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)

admin.site.register(User, UserAdmin)
admin.site.register(Product)
admin.site.register(Category)
admin.site.register(Order)
7 changes: 5 additions & 2 deletions app/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.0.1 on 2022-02-19 10:18
# Generated by Django 4.0.1 on 2024-07-19 22:13

from django.db import migrations, models

Expand All @@ -20,9 +20,12 @@ class Migration(migrations.Migration):
('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=255, unique=True)),
('name', models.CharField(max_length=255)),
('username', models.CharField(max_length=255, unique=True)),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('is_active', models.BooleanField(default=True)),
('is_staff', models.BooleanField(default=False)),
('is_verified', models.BooleanField(default=False)),
('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')),
],
Expand Down
26 changes: 26 additions & 0 deletions app/core/migrations/0002_user_date_joined_user_last_modified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.0.1 on 2024-07-20 09:22

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


class Migration(migrations.Migration):

dependencies = [
('core', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='user',
name='date_joined',
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2024, 7, 20, 9, 22, 33, 982024, tzinfo=utc)),
preserve_default=False,
),
migrations.AddField(
model_name='user',
name='last_modified',
field=models.DateTimeField(auto_now=True),
),
]
19 changes: 19 additions & 0 deletions app/core/migrations/0003_alter_user_date_joined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.1 on 2024-07-20 09:29

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


class Migration(migrations.Migration):

dependencies = [
('core', '0002_user_date_joined_user_last_modified'),
]

operations = [
migrations.AlterField(
model_name='user',
name='date_joined',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
44 changes: 44 additions & 0 deletions app/core/migrations/0004_category_product_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.0.1 on 2024-07-20 11:04

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


class Migration(migrations.Migration):

dependencies = [
('core', '0003_alter_user_date_joined'),
]

operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='core.category')),
],
),
migrations.CreateModel(
name='Order',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=1)),
('date', models.DateTimeField(default=django.utils.timezone.now)),
('products', models.ManyToManyField(to='core.Product')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 18 additions & 0 deletions app/core/migrations/0005_alter_user_last_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.1 on 2024-07-20 12:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0004_category_product_order'),
]

operations = [
migrations.AlterField(
model_name='user',
name='last_login',
field=models.DateTimeField(blank=True, null=True),
),
]
23 changes: 23 additions & 0 deletions app/core/migrations/0006_rename_name_category_cat_name_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.0.1 on 2024-07-20 12:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0005_alter_user_last_login'),
]

operations = [
migrations.RenameField(
model_name='category',
old_name='name',
new_name='cat_name',
),
migrations.RenameField(
model_name='product',
old_name='name',
new_name='product_name',
),
]
18 changes: 18 additions & 0 deletions app/core/migrations/0007_rename_cat_name_category_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.1 on 2024-07-20 12:30

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0006_rename_name_category_cat_name_and_more'),
]

operations = [
migrations.RenameField(
model_name='category',
old_name='cat_name',
new_name='name',
),
]
Loading