parent
f69321becf
commit
8adbfdada8
@ -1,6 +1,8 @@ |
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class TournamentsConfig(AppConfig): |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
name = 'tournaments' |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
|
||||
def ready(self): |
||||
import tournaments.signals # This will ensure the signals are registered |
||||
|
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 4.2.11 on 2024-06-04 11:11 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('tournaments', '0064_failedapicall_user'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='club', |
||||
name='broadcast_code', |
||||
field=models.CharField(blank=True, max_length=10, null=True), |
||||
), |
||||
] |
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 4.2.11 on 2024-06-04 11:36 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('tournaments', '0065_club_broadcast_code'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AlterField( |
||||
model_name='club', |
||||
name='broadcast_code', |
||||
field=models.CharField(blank=True, max_length=10, null=True, unique=True), |
||||
), |
||||
] |
||||
@ -0,0 +1,19 @@ |
||||
import random |
||||
import string |
||||
from django.db.models.signals import post_save |
||||
from django.dispatch import receiver |
||||
from .models import Club |
||||
|
||||
def generate_unique_code(): |
||||
characters = string.ascii_letters + string.digits |
||||
while True: |
||||
code = ''.join(random.sample(characters, 3)) |
||||
print(code) |
||||
if not Club.objects.filter(broadcast_code=code).exists(): |
||||
return code |
||||
|
||||
@receiver(post_save, sender=Club) |
||||
def assign_unique_code(sender, instance, created, **kwargs): |
||||
if created and not instance.broadcast_code: |
||||
instance.broadcast_code = generate_unique_code() |
||||
instance.save() |
||||
Loading…
Reference in new issue