Skip to content

Commit 276bfdc

Browse files
committed
Adicionando last_notification e updated_at
1 parent 76a46b2 commit 276bfdc

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

backend/apps/user_notifications/admin.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77

88
class TableUpdateSubscriptionAdmin(admin.ModelAdmin):
99
# Campos que serão exibidos na lista de objetos
10-
list_display = ("id", "table", "user", "created_at", "deleted_at", "status")
10+
list_display = (
11+
"id",
12+
"table",
13+
"user",
14+
"created_at",
15+
"deactivate_at",
16+
"last_notification",
17+
"updated_at",
18+
"status",
19+
)
1120

1221
# Filtros laterais para facilitar a busca
1322
list_filter = ("status", "table", "user")
@@ -27,14 +36,14 @@ class TableUpdateSubscriptionAdmin(admin.ModelAdmin):
2736
(
2837
"Datas",
2938
{
30-
"fields": ("created_at", "deleted_at"),
39+
"fields": ("created_at", "deactivate_at", "last_notification", "updated_at"),
3140
"classes": ("collapse",),
3241
},
3342
),
3443
)
3544

3645
# Campos que não serão mostrados no formulário de edição
37-
readonly_fields = ("created_at", "deleted_at")
46+
readonly_fields = ("created_at", "deactivate_at")
3847

3948
# Exibir os campos na ordem desejada no formulário de edição
4049
ordering = ("-created_at",)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 4.2.10 on 2025-12-02 18:48
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("user_notifications", "0001_initial"),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name="tableupdatesubscription",
15+
old_name="deleted_at",
16+
new_name="deactivate_at",
17+
),
18+
migrations.AddField(
19+
model_name="tableupdatesubscription",
20+
name="last_notification",
21+
field=models.DateTimeField(blank=True, null=True),
22+
),
23+
migrations.AddField(
24+
model_name="tableupdatesubscription",
25+
name="updated_at",
26+
field=models.DateTimeField(blank=True, null=True),
27+
),
28+
]

backend/apps/user_notifications/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313

1414
class TableUpdateSubscription(models.Model):
15-
# Chave primária será gerada automaticamente pelo Django
1615
table = models.ForeignKey(Table, on_delete=models.CASCADE)
1716
user = models.ForeignKey(Account, on_delete=models.CASCADE)
1817
created_at = models.DateTimeField(auto_now_add=True)
19-
deleted_at = models.DateTimeField(null=True, blank=True)
18+
deactivate_at = models.DateTimeField(null=True, blank=True)
19+
last_notification = models.DateTimeField(null=True, blank=True)
20+
updated_at = models.DateTimeField(null=True, blank=True)
2021
status = models.BooleanField(default=True) # True = Ativa, False = Inativa
2122

2223
def __str__(self):

backend/apps/user_notifications/views.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
@csrf_exempt
1515
def add_subscription(request):
1616
if request.method == "POST":
17-
# Coletando os dados que serão enviados pela requisição
1817
table_id = request.POST.get("table_id")
1918
user_id = request.POST.get("user_id")
2019

@@ -37,9 +36,7 @@ def add_subscription(request):
3736
)
3837

3938
# Criando a nova assinatura
40-
subscription = TableUpdateSubscription.objects.create(
41-
table=table, user=user, status=True
42-
)
39+
TableUpdateSubscription.objects.create(table=table, user=user, status=True)
4340

4441
# Respondendo com sucesso
4542
return JsonResponse(
@@ -60,7 +57,6 @@ def add_subscription(request):
6057
@csrf_exempt
6158
def remove_subscription(request):
6259
if request.method == "POST":
63-
# Coletando os dados que serão enviados pela requisição
6460
table_id = request.POST.get("table_id")
6561
user_id = request.POST.get("user_id")
6662

0 commit comments

Comments
 (0)