mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 14:59:36 +02:00
Enhance adventure management: add error handling for category fetch, implement unique email constraint in user model, and update adventure save logic to ensure category assignment
This commit is contained in:
parent
86d213bb8b
commit
736ede2417
15 changed files with 216 additions and 60 deletions
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 5.0.8 on 2024-11-18 14:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
def check_duplicate_email(apps, schema_editor):
|
||||
# sets an email to null if there are duplicates
|
||||
CustomUser = apps.get_model('users', 'CustomUser')
|
||||
duplicates = CustomUser.objects.values('email').annotate(email_count=models.Count('email')).filter(email_count__gt=1)
|
||||
for duplicate in duplicates:
|
||||
CustomUser.objects.filter(email=duplicate['email']).update(email=None)
|
||||
print(f"Duplicate email: {duplicate['email']}")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0002_customuser_public_profile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(check_duplicate_email),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='email',
|
||||
field=models.EmailField(max_length=254, unique=True),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue