From 281e40bb92a6b9e4440dbcc921af57d483037052 Mon Sep 17 00:00:00 2001 From: matheuspdf Date: Mon, 25 Mar 2024 22:37:08 -0300 Subject: [PATCH] =?UTF-8?q?P=C3=A1gina=20de=20Admin=20criada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eventex/settings.py | 2 +- eventex/subscriptions/admin.py | 20 +++++++++++++++++++ eventex/subscriptions/apps.py | 6 ++++++ eventex/subscriptions/models.py | 18 ++++++++++++----- .../tests/test_model_subscription.py | 3 +++ 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 eventex/subscriptions/admin.py create mode 100644 eventex/subscriptions/apps.py diff --git a/eventex/settings.py b/eventex/settings.py index 54934f7..abd7372 100644 --- a/eventex/settings.py +++ b/eventex/settings.py @@ -43,7 +43,7 @@ "test_without_migrations", "django_extensions", "eventex.core", - "eventex.subscriptions", + "eventex.subscriptions.apps.SubscriptionsConfig", ] MIDDLEWARE = [ diff --git a/eventex/subscriptions/admin.py b/eventex/subscriptions/admin.py new file mode 100644 index 0000000..c80ba95 --- /dev/null +++ b/eventex/subscriptions/admin.py @@ -0,0 +1,20 @@ +from django.contrib import admin +from eventex.subscriptions.models import Subscription +from django.utils.timezone import now + + +class SubscriptionModelAdmin(admin.ModelAdmin): + list_display = ('name', 'email', 'phone', 'cpf', 'created_at', + 'subscribe_today') + date_hierarchy = 'created_at' + search_fields = ('name', 'email', 'phone', 'cpf', 'created_at') + list_filter = ('created_at',) + + def subscribe_today(self, obj): + return obj.created_at == now().date() + + subscribe_today.short_description = 'inscrito hoje?' + subscribe_today.boolean = True + + +admin.site.register(Subscription, SubscriptionModelAdmin) diff --git a/eventex/subscriptions/apps.py b/eventex/subscriptions/apps.py new file mode 100644 index 0000000..a8ab186 --- /dev/null +++ b/eventex/subscriptions/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SubscriptionsConfig(AppConfig): + name = 'eventex.subscriptions' + verbose_name = 'Controle de Participantes' diff --git a/eventex/subscriptions/models.py b/eventex/subscriptions/models.py index 5f395b5..f89cc28 100644 --- a/eventex/subscriptions/models.py +++ b/eventex/subscriptions/models.py @@ -2,8 +2,16 @@ class Subscription(models.Model): - name = models.CharField(max_length=100) - cpf = models.CharField(max_length=11) - email = models.EmailField() - phone = models.CharField(max_length=20) - created_at = models.DateTimeField(auto_now_add=True) + name = models.CharField('nome', max_length=100) + cpf = models.CharField('CPF', max_length=11) + email = models.EmailField('e-mail') + phone = models.CharField('telefone', max_length=20) + created_at = models.DateTimeField('criado em', auto_now_add=True) + + class Meta: + verbose_name_plural = 'inscrições' + verbose_name = 'inscrição' + ordering = ('-created_at',) + + def __str__(self): + return self.name diff --git a/eventex/subscriptions/tests/test_model_subscription.py b/eventex/subscriptions/tests/test_model_subscription.py index 8373280..ca1ffc2 100644 --- a/eventex/subscriptions/tests/test_model_subscription.py +++ b/eventex/subscriptions/tests/test_model_subscription.py @@ -20,3 +20,6 @@ def test_create(self): def test_created_at(self): """Subscription must have an auto created_at attr.""" self.assertIsInstance(self.obj.created_at, datetime) + + def test_str(self): + self.assertEqual('Matheus Lopes', str(self.obj))