ankpan18 commited on
Commit
e7d383c
Β·
1 Parent(s): e0beb5a

added NewUserModel in users app

Browse files
other/admin.py DELETED
@@ -1,3 +0,0 @@
1
- from django.contrib import admin
2
-
3
- # Register your models here.
 
 
 
 
other/models.py DELETED
@@ -1,3 +0,0 @@
1
- from django.db import models
2
-
3
- # Create your models here.
 
 
 
 
other/urls.py DELETED
@@ -1,6 +0,0 @@
1
- from django.urls import path
2
- from . import views
3
-
4
- urlpatterns = [
5
- path("",views.index,name="index"),
6
- ]
 
 
 
 
 
 
 
polls/migrations/0001_initial.py CHANGED
@@ -1,5 +1,6 @@
1
- # Generated by Django 4.2.3 on 2023-07-18 00:56
2
 
 
3
  from django.db import migrations, models
4
  import django.db.models.deletion
5
 
@@ -17,7 +18,7 @@ class Migration(migrations.Migration):
17
  fields=[
18
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19
  ('question_text', models.CharField(max_length=300)),
20
- ('pub_date', models.DateTimeField(verbose_name='date published')),
21
  ],
22
  ),
23
  migrations.CreateModel(
 
1
+ # Generated by Django 4.2.3 on 2023-07-24 17:19
2
 
3
+ import datetime
4
  from django.db import migrations, models
5
  import django.db.models.deletion
6
 
 
18
  fields=[
19
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
  ('question_text', models.CharField(max_length=300)),
21
+ ('pub_date', models.DateTimeField(default=datetime.datetime.now, verbose_name='date published')),
22
  ],
23
  ),
24
  migrations.CreateModel(
templator/settings.py CHANGED
@@ -37,7 +37,8 @@ INSTALLED_APPS = [
37
  'django.contrib.sessions',
38
  'django.contrib.messages',
39
  'django.contrib.staticfiles',
40
- 'polls'
 
41
  ]
42
 
43
  MIDDLEWARE = [
@@ -123,3 +124,6 @@ STATIC_URL = 'static/'
123
  # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
124
 
125
  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
 
 
 
37
  'django.contrib.sessions',
38
  'django.contrib.messages',
39
  'django.contrib.staticfiles',
40
+ 'polls',
41
+ 'users'
42
  ]
43
 
44
  MIDDLEWARE = [
 
124
  # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
125
 
126
  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
127
+
128
+
129
+ AUTH_USER_MODEL = 'users.NewUserModel'
templator/urls.py CHANGED
@@ -20,5 +20,4 @@ from django.urls import path, include
20
  urlpatterns = [
21
  path('admin/', admin.site.urls),
22
  path('polls/',include('polls.urls')),
23
- path('other/',include('other.urls')),
24
  ]
 
20
  urlpatterns = [
21
  path('admin/', admin.site.urls),
22
  path('polls/',include('polls.urls')),
 
23
  ]
{other β†’ users}/__init__.py RENAMED
File without changes
users/admin.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from django.contrib import admin
2
+ from .models import NewUserModel
3
+ from django.contrib.auth.admin import UserAdmin
4
+ # Register your models here.
5
+
6
+ class MyUserAdmin(UserAdmin):
7
+ list_display = ('email','username','is_active','is_staff','is_superuser')
8
+
9
+ admin.site.register(NewUserModel,MyUserAdmin)
{other β†’ users}/apps.py RENAMED
@@ -1,6 +1,6 @@
1
  from django.apps import AppConfig
2
 
3
 
4
- class OtherConfig(AppConfig):
5
  default_auto_field = 'django.db.models.BigAutoField'
6
- name = 'other'
 
1
  from django.apps import AppConfig
2
 
3
 
4
+ class UsersConfig(AppConfig):
5
  default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'users'
users/migrations/0001_initial.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.2.3 on 2023-07-24 17:19
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ('auth', '0012_alter_user_first_name_max_length'),
12
+ ]
13
+
14
+ operations = [
15
+ migrations.CreateModel(
16
+ name='NewUserModel',
17
+ fields=[
18
+ ('password', models.CharField(max_length=128, verbose_name='password')),
19
+ ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
20
+ ('email', models.EmailField(max_length=255, primary_key=True, serialize=False, unique=True, verbose_name='Email Address')),
21
+ ('username', models.CharField(max_length=150, verbose_name='Name')),
22
+ ('is_staff', models.BooleanField(default=False)),
23
+ ('is_superuser', models.BooleanField(default=False)),
24
+ ('is_active', models.BooleanField(default=False)),
25
+ ('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')),
26
+ ('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')),
27
+ ],
28
+ options={
29
+ 'abstract': False,
30
+ },
31
+ ),
32
+ ]
{other β†’ users}/migrations/__init__.py RENAMED
File without changes
users/models.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.db import models
2
+ from django.contrib.auth.models import AbstractBaseUser,PermissionsMixin,BaseUserManager
3
+
4
+
5
+ # Create your models here.
6
+
7
+
8
+ class CustomAccountManager(BaseUserManager):
9
+ def create_user(self,email,username,password,**kwargs):
10
+
11
+ if not email:
12
+ raise ValueError("You must provide an email")
13
+ if not username:
14
+ raise ValueError("You must provide an name")
15
+ if not password:
16
+ raise ValueError("You must provide an password")
17
+
18
+
19
+ email = self.normalize_email(email)
20
+ user = self.model(email=email,username=username,**kwargs)
21
+ user.set_password(password)
22
+ user.save()
23
+ return user
24
+
25
+ def create_superuser(self,email,username,password,**kwargs):
26
+ kwargs.setdefault("is_staff",True)
27
+ kwargs.setdefault("is_superuser",True)
28
+ kwargs.setdefault("is_active",True)
29
+
30
+ if kwargs['is_staff'] is not True:
31
+ raise ValueError("SuperUser must have is_staff=True.")
32
+ if kwargs['is_superuser'] is not True:
33
+ raise ValueError("SuperUser must have is_superuser=True.")
34
+
35
+ return self.create_user(email=email,username=username,password=password,**kwargs)
36
+
37
+ class NewUserModel(AbstractBaseUser,PermissionsMixin):
38
+
39
+ email = models.EmailField(verbose_name="Email Address",primary_key=True,max_length=255,unique=True)
40
+ username = models.CharField("Name",max_length=150,unique=False)
41
+ is_staff = models.BooleanField(default=False)
42
+ is_superuser = models.BooleanField(default=False)
43
+ is_active = models.BooleanField(default=False)
44
+
45
+ USERNAME_FIELD = "email"
46
+ REQUIRED_FIELDS = ["username"]
47
+
48
+ objects = CustomAccountManager()
49
+
50
+ def __str__(self):
51
+ return self.username
52
+
53
+
{other β†’ users}/tests.py RENAMED
File without changes
{other β†’ users}/views.py RENAMED
@@ -1,6 +1,3 @@
1
  from django.shortcuts import render
2
- from django.http import HttpResponse
3
 
4
  # Create your views here.
5
- def index(request):
6
- return HttpResponse("other response")
 
1
  from django.shortcuts import render
 
2
 
3
  # Create your views here.