feat: add basic notifications
This commit is contained in:
parent
91fe53400e
commit
7c8dcaf171
@ -0,0 +1,66 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-08-02 17:11
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("fellchensammlung", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="BaseNotification",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||||
|
("title", models.CharField(max_length=100)),
|
||||||
|
("text", models.TextField(verbose_name="Inhalt")),
|
||||||
|
("read", models.BooleanField(default=False)),
|
||||||
|
(
|
||||||
|
"user",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to=settings.AUTH_USER_MODEL,
|
||||||
|
verbose_name="Nutzer*in",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="CommentNotification",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"basenotification_ptr",
|
||||||
|
models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="fellchensammlung.basenotification",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"comment",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="fellchensammlung.comment",
|
||||||
|
verbose_name="Antwort",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
bases=("fellchensammlung.basenotification",),
|
||||||
|
),
|
||||||
|
]
|
@ -68,6 +68,9 @@ class User(AbstractUser):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("user-detail", args=[str(self.pk)])
|
return reverse("user-detail", args=[str(self.pk)])
|
||||||
|
|
||||||
|
def get_notifications_url(self):
|
||||||
|
return self.get_absolute_url()
|
||||||
|
|
||||||
|
|
||||||
class Image(models.Model):
|
class Image(models.Model):
|
||||||
image = models.ImageField(upload_to='images')
|
image = models.ImageField(upload_to='images')
|
||||||
@ -531,3 +534,21 @@ class Comment(models.Model):
|
|||||||
@property
|
@property
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return self.adoption_notice.get_absolute_url()
|
return self.adoption_notice.get_absolute_url()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNotification(models.Model):
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
title = models.CharField(max_length=100)
|
||||||
|
text = models.TextField(verbose_name="Inhalt")
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in'))
|
||||||
|
read = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"[{self.user}] {self.title} ({self.created_at})"
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
self.user.get_notifications_url()
|
||||||
|
|
||||||
|
|
||||||
|
class CommentNotification(BaseNotification):
|
||||||
|
comment = models.ForeignKey(Comment, on_delete=models.CASCADE, verbose_name=_('Antwort'))
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<div class="profile-card">
|
<div class="profile-card">
|
||||||
{% include "fellchensammlung/forms/change_language.html" %}
|
{% include "fellchensammlung/forms/change_language.html" %}
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
<a class="btn2" href="{{ user.get_notifications_url }}"><i class="fa fa-bell" aria-hidden="true"></i></a>
|
||||||
<a class="btn2" href="{{ user.get_absolute_url }}"><i aria-hidden="true" class="fas fa-user"></i></a>
|
<a class="btn2" href="{{ user.get_absolute_url }}"><i aria-hidden="true" class="fas fa-user"></i></a>
|
||||||
<form class="btn2 button_darken" action="{% url 'logout' %}" method="post">
|
<form class="btn2 button_darken" action="{% url 'logout' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
Loading…
Reference in New Issue
Block a user