Skip to content

Commit

Permalink
Página de Admin criada
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspdf committed Mar 26, 2024
1 parent 1970319 commit 281e40b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion eventex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"test_without_migrations",
"django_extensions",
"eventex.core",
"eventex.subscriptions",
"eventex.subscriptions.apps.SubscriptionsConfig",
]

MIDDLEWARE = [
Expand Down
20 changes: 20 additions & 0 deletions eventex/subscriptions/admin.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions eventex/subscriptions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class SubscriptionsConfig(AppConfig):
name = 'eventex.subscriptions'
verbose_name = 'Controle de Participantes'
18 changes: 13 additions & 5 deletions eventex/subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions eventex/subscriptions/tests/test_model_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 281e40b

Please sign in to comment.