diff --git a/backend/backend_api/migrations/0056_presentationparticipation_password_and_more.py b/backend/backend_api/migrations/0056_presentationparticipation_password_and_more.py new file mode 100644 index 0000000..b644e0e --- /dev/null +++ b/backend/backend_api/migrations/0056_presentationparticipation_password_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.4 on 2023-12-05 19:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('backend_api', '0055_alter_discount_code'), + ] + + operations = [ + migrations.AddField( + model_name='presentationparticipation', + name='password', + field=models.CharField(default='KlWfmELW5ixsZmqh', max_length=255), + ), + migrations.AddField( + model_name='workshopregistration', + name='password', + field=models.CharField(default='g0WmA7rXbIxm5OVJ', max_length=255), + ), + migrations.AlterField( + model_name='discount', + name='code', + field=models.CharField(default='4Hjyva31c9rSMamSNQkqWz1lrMa0kr1E', max_length=32, unique=True), + ), + ] diff --git a/backend/backend_api/models.py b/backend/backend_api/models.py index 3b29ed5..d14ed6f 100644 --- a/backend/backend_api/models.py +++ b/backend/backend_api/models.py @@ -287,26 +287,38 @@ class StatusChoices(models.IntegerChoices): AWAITING_PAYMENT = 1, _('Waiting for payment') PURCHASED = 2, _('Purchase confirmed') + _PASSWORD_LENGTH = 16 workshop = models.ForeignKey(Workshop, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) status = models.IntegerField(choices=StatusChoices.choices, default=StatusChoices.AWAITING_PAYMENT) + password = models.CharField(max_length=SMALL_MAX_LENGTH, default=create_random_string(_PASSWORD_LENGTH)) class Meta: unique_together = ('workshop', 'user',) + @property + def username(self) -> str: + return f'{self.user.account.email.split("@")[0]}_workshop_{self.workshop.id}' + class PresentationParticipation(models.Model): class StatusChoices(models.IntegerChoices): AWAITING_PAYMENT = 1, _('Waiting for payment') PURCHASED = 2, _('Purchase confirmed') + _PASSWORD_LENGTH = 16 presentation = models.ForeignKey(Presentation, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) status = models.IntegerField(choices=StatusChoices.choices, default=StatusChoices.AWAITING_PAYMENT) + password = models.CharField(max_length=SMALL_MAX_LENGTH, default=create_random_string(_PASSWORD_LENGTH)) class Meta: unique_together = ('presentation', 'user',) + @property + def username(self) -> str: + return f'{self.user.account.email.split("@")[0]}_presentation_{self.presentation.id}' + class Misc(models.Model): name = models.CharField(max_length=SMALL_MAX_LENGTH, primary_key=True)