From 364a15acf8a2a9a34f02a2cb181351607a596e25 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 1 Nov 2025 08:46:00 +0330 Subject: [PATCH] fix soft-delete-manager --- .../migrations/0045_alter_user_username.py | 19 +++++++++++++++++++ apps/core/manager.py | 3 +++ logs/django_requests.log | 1 + 3 files changed, 23 insertions(+) create mode 100644 apps/authentication/migrations/0045_alter_user_username.py diff --git a/apps/authentication/migrations/0045_alter_user_username.py b/apps/authentication/migrations/0045_alter_user_username.py new file mode 100644 index 0000000..15a95c2 --- /dev/null +++ b/apps/authentication/migrations/0045_alter_user_username.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0 on 2025-11-01 05:12 + +import django.contrib.auth.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0044_remove_username_unique'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='username', + field=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'), + ), + ] diff --git a/apps/core/manager.py b/apps/core/manager.py index d7f6e13..f0b4acb 100644 --- a/apps/core/manager.py +++ b/apps/core/manager.py @@ -3,6 +3,7 @@ from django.db import models class SoftDeleteManager(models.Manager): """ manager for get all records with trash=False in whole project """ + def get_queryset(self): return super().get_queryset().filter(trash=False) @@ -10,3 +11,5 @@ class SoftDeleteManager(models.Manager): """ get all records, also deleted ones """ return super().get_queryset().all() + def get_by_natural_key(self, username): + return self.get_queryset().get(username=username) diff --git a/logs/django_requests.log b/logs/django_requests.log index 828019d..9178665 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -597,3 +597,4 @@ AssertionError: .validate() should return the validated data [2025-10-29 17:34:48,818] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-10-29 17:41:23,861] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\models.py changed, reloading. [2025-10-29 17:41:27,025] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-11-01 08:44:37,286] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader