From 87a4d7233945c744e9b168b3e4310adcd7eb9019 Mon Sep 17 00:00:00 2001 From: matheuspdf Date: Tue, 9 Apr 2024 18:22:43 -0300 Subject: [PATCH] Adiciona campo paid --- eventex/subscriptions/admin.py | 4 +- ...tion_options_subscription_paid_and_more.py | 51 +++++++++++++++++++ .../0003_alter_subscription_paid.py | 18 +++++++ eventex/subscriptions/models.py | 1 + .../tests/test_model_subscription.py | 4 ++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 eventex/subscriptions/migrations/0002_alter_subscription_options_subscription_paid_and_more.py create mode 100644 eventex/subscriptions/migrations/0003_alter_subscription_paid.py diff --git a/eventex/subscriptions/admin.py b/eventex/subscriptions/admin.py index c80ba95..0a3321f 100644 --- a/eventex/subscriptions/admin.py +++ b/eventex/subscriptions/admin.py @@ -5,10 +5,10 @@ class SubscriptionModelAdmin(admin.ModelAdmin): list_display = ('name', 'email', 'phone', 'cpf', 'created_at', - 'subscribe_today') + 'subscribe_today', 'paid') date_hierarchy = 'created_at' search_fields = ('name', 'email', 'phone', 'cpf', 'created_at') - list_filter = ('created_at',) + list_filter = ('paid', 'created_at') def subscribe_today(self, obj): return obj.created_at == now().date() diff --git a/eventex/subscriptions/migrations/0002_alter_subscription_options_subscription_paid_and_more.py b/eventex/subscriptions/migrations/0002_alter_subscription_options_subscription_paid_and_more.py new file mode 100644 index 0000000..d9c80ce --- /dev/null +++ b/eventex/subscriptions/migrations/0002_alter_subscription_options_subscription_paid_and_more.py @@ -0,0 +1,51 @@ +# Generated by Django 5.0.3 on 2024-04-09 21:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("subscriptions", "0001_initial"), + ] + + operations = [ + migrations.AlterModelOptions( + name="subscription", + options={ + "ordering": ("-created_at",), + "verbose_name": "inscrição", + "verbose_name_plural": "inscrições", + }, + ), + migrations.AddField( + model_name="subscription", + name="paid", + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name="subscription", + name="cpf", + field=models.CharField(max_length=11, verbose_name="CPF"), + ), + migrations.AlterField( + model_name="subscription", + name="created_at", + field=models.DateTimeField(auto_now_add=True, verbose_name="criado em"), + ), + migrations.AlterField( + model_name="subscription", + name="email", + field=models.EmailField(max_length=254, verbose_name="e-mail"), + ), + migrations.AlterField( + model_name="subscription", + name="name", + field=models.CharField(max_length=100, verbose_name="nome"), + ), + migrations.AlterField( + model_name="subscription", + name="phone", + field=models.CharField(max_length=20, verbose_name="telefone"), + ), + ] diff --git a/eventex/subscriptions/migrations/0003_alter_subscription_paid.py b/eventex/subscriptions/migrations/0003_alter_subscription_paid.py new file mode 100644 index 0000000..32f8eb9 --- /dev/null +++ b/eventex/subscriptions/migrations/0003_alter_subscription_paid.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.3 on 2024-04-09 21:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("subscriptions", "0002_alter_subscription_options_subscription_paid_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="subscription", + name="paid", + field=models.BooleanField(default=False, verbose_name="pago"), + ), + ] diff --git a/eventex/subscriptions/models.py b/eventex/subscriptions/models.py index f89cc28..a3a0332 100644 --- a/eventex/subscriptions/models.py +++ b/eventex/subscriptions/models.py @@ -7,6 +7,7 @@ class Subscription(models.Model): email = models.EmailField('e-mail') phone = models.CharField('telefone', max_length=20) created_at = models.DateTimeField('criado em', auto_now_add=True) + paid = models.BooleanField('pago', default=False) class Meta: verbose_name_plural = 'inscrições' diff --git a/eventex/subscriptions/tests/test_model_subscription.py b/eventex/subscriptions/tests/test_model_subscription.py index ca1ffc2..ce3298a 100644 --- a/eventex/subscriptions/tests/test_model_subscription.py +++ b/eventex/subscriptions/tests/test_model_subscription.py @@ -23,3 +23,7 @@ def test_created_at(self): def test_str(self): self.assertEqual('Matheus Lopes', str(self.obj)) + + def test_paid_default_to_False(self): + """By default paid must be False.""" + self.assertEqual(False, self.obj.paid) \ No newline at end of file