From e7b93a54d82e542be6bcdac218c7b9bf0a96ea98 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 4 Nov 2021 00:55:43 +1100 Subject: [PATCH] Add new model "NotificationEntry" - Keep track of past notifications --- .../migrations/0012_notificationentry.py | 25 +++++++++++++++ InvenTree/common/models.py | 31 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 InvenTree/common/migrations/0012_notificationentry.py diff --git a/InvenTree/common/migrations/0012_notificationentry.py b/InvenTree/common/migrations/0012_notificationentry.py new file mode 100644 index 0000000000..77439c9f8c --- /dev/null +++ b/InvenTree/common/migrations/0012_notificationentry.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.5 on 2021-11-03 13:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0011_auto_20210722_2114'), + ] + + operations = [ + migrations.CreateModel( + name='NotificationEntry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('key', models.CharField(max_length=250)), + ('uid', models.IntegerField()), + ('updated', models.DateTimeField(auto_now=True)), + ], + options={ + 'unique_together': {('key', 'uid')}, + }, + ), + ] diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index bbc8a6721a..559a8dc003 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1226,3 +1226,34 @@ class ColorTheme(models.Model): return True return False + + +class NotificationEntry(models.Model): + """ + A NotificationEntry records the last time a particular notifaction was sent out. + + It is recorded to ensure that notifications are not sent out "too often" to users. + + Attributes: + - key: A text entry describing the notification e.g. 'part.notify_low_stock' + - uid: An (optional) numerical ID for a particular instance + - date: The last time this notification was sent + """ + + class Meta: + unique_together = [ + ('key', 'uid'), + ] + + key = models.CharField( + max_length=250, + blank=False, + ) + + uid = models.IntegerField( + ) + + updated = models.DateTimeField( + auto_now=True, + null=False, + )