init commit
This commit is contained in:
0
users/__init__.py
Normal file
0
users/__init__.py
Normal file
BIN
users/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
users/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/admin.cpython-311.pyc
Normal file
BIN
users/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/apps.cpython-311.pyc
Normal file
BIN
users/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/models.cpython-311.pyc
Normal file
BIN
users/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/urls.cpython-311.pyc
Normal file
BIN
users/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
15
users/admin.py
Normal file
15
users/admin.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
from .models import User, UserConfirmation
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(admin.ModelAdmin):
|
||||
list_display = ('username', 'telegram_id', 'chat_id', 'role', 'confirmed')
|
||||
search_fields = ('username', 'telegram_id', 'chat_id')
|
||||
list_filter = ('role', 'confirmed')
|
||||
ordering = ('-id',)
|
||||
|
||||
@admin.register(UserConfirmation)
|
||||
class UserConfirmationAdmin(admin.ModelAdmin):
|
||||
list_display = ('user', 'confirmation_code', 'created_at')
|
||||
search_fields = ('user__username', 'confirmation_code')
|
||||
list_filter = ('created_at',)
|
||||
6
users/apps.py
Normal file
6
users/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'users'
|
||||
59
users/migrations/0001_initial.py
Normal file
59
users/migrations/0001_initial.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-05 23:39
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import uuid
|
||||
from django.db import migrations, 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')),
|
||||
('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')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('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')),
|
||||
('telegram_id', models.BigIntegerField(blank=True, null=True, unique=True, verbose_name='Telegram ID')),
|
||||
('chat_id', models.BigIntegerField(blank=True, null=True, unique=True, verbose_name='Chat ID')),
|
||||
('role', models.CharField(choices=[('admin', 'Administrator'), ('hotel_user', 'Hotel User')], default='hotel_user', max_length=20, verbose_name='Role')),
|
||||
('confirmed', models.BooleanField(default=False, verbose_name='Confirmed')),
|
||||
('groups', models.ManyToManyField(blank=True, related_name='custom_user_set', to='auth.group')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, related_name='custom_user_set', to='auth.permission')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='UserConfirmation',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('confirmation_code', models.UUIDField(default=uuid.uuid4, verbose_name='Confirmation Code')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.user', verbose_name='User')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
users/migrations/__init__.py
Normal file
0
users/migrations/__init__.py
Normal file
BIN
users/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
users/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
BIN
users/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
users/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
51
users/models.py
Normal file
51
users/models.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
import uuid
|
||||
|
||||
class User(AbstractUser):
|
||||
TELEGRAM_ROLES = [
|
||||
('admin', 'Administrator'),
|
||||
('hotel_user', 'Hotel User'),
|
||||
]
|
||||
|
||||
telegram_id = models.BigIntegerField(
|
||||
unique=True,
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name="Telegram ID"
|
||||
)
|
||||
chat_id = models.BigIntegerField(
|
||||
unique=True,
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name="Chat ID"
|
||||
)
|
||||
role = models.CharField(
|
||||
max_length=20,
|
||||
choices=TELEGRAM_ROLES,
|
||||
default='hotel_user',
|
||||
verbose_name="Role"
|
||||
)
|
||||
confirmed = models.BooleanField(default=False, verbose_name="Confirmed")
|
||||
|
||||
groups = models.ManyToManyField(
|
||||
'auth.Group',
|
||||
related_name='custom_user_set', # Уникальное имя для обратной связи
|
||||
blank=True
|
||||
)
|
||||
user_permissions = models.ManyToManyField(
|
||||
'auth.Permission',
|
||||
related_name='custom_user_set', # Уникальное имя для обратной связи
|
||||
blank=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.username or f"Telegram User {self.telegram_id}"
|
||||
|
||||
class UserConfirmation(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="User")
|
||||
confirmation_code = models.UUIDField(default=uuid.uuid4, verbose_name="Confirmation Code")
|
||||
created_at = models.DateTimeField(auto_now_add=True, verbose_name="Created At")
|
||||
|
||||
def __str__(self):
|
||||
return f"Confirmation for {self.user.username} - {self.confirmation_code}"
|
||||
3
users/tests.py
Normal file
3
users/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
0
users/urls.py
Normal file
0
users/urls.py
Normal file
3
users/views.py
Normal file
3
users/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user