Skip to content

Commit

Permalink
Authentication - part 01 - created custom user and also renamed store…
Browse files Browse the repository at this point in the history
…_custom app to core app
  • Loading branch information
Storefront committed Mar 18, 2023
1 parent 469d113 commit 92cd64b
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions store_custome/admin.py → core/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from store.admin import ProductAdmin
from store.models import Product
from core.models import User
from tags.models import TaggedItem

# Register your models here.
@admin.register(User)
class UserAdmin(BaseUserAdmin):
pass

class TagInline(GenericTabularInline):
model = TaggedItem
autocomplete_fields = ['tag']
Expand Down
4 changes: 2 additions & 2 deletions store_custome/apps.py → core/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class StoreCustomeConfig(AppConfig):
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'store_custome'
name = 'core'
44 changes: 44 additions & 0 deletions core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.1.7 on 2023-03-18 13:31

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone


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')),
('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')),
('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')),
('email', models.EmailField(max_length=254, unique=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': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
File renamed without changes.
6 changes: 6 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
class User(AbstractUser):
email = models.EmailField(unique=True)
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion likes/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey

# Create your models here.

class LikedItem(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
19 changes: 19 additions & 0 deletions store/migrations/0009_alter_cartitem_quantity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.7 on 2023-03-18 13:31

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('store', '0008_alter_cartitem_cart_alter_cartitem_unique_together'),
]

operations = [
migrations.AlterField(
model_name='cartitem',
name='quantity',
field=models.PositiveIntegerField(validators=[django.core.validators.MinValueValidator(1)]),
),
]
3 changes: 0 additions & 3 deletions store_custome/models.py

This file was deleted.

8 changes: 5 additions & 3 deletions storefront/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
'django.contrib.staticfiles',
'django_filters',
'rest_framework',
'playground',
'debug_toolbar',
'playground',
'store',
'store_custome',
'tags',
'likes',
'core'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -143,4 +143,6 @@
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
# 'PAGE_SIZE': 10

}
}

AUTH_USER_MODEL = 'core.User'

0 comments on commit 92cd64b

Please sign in to comment.