Skip to content

Commit b158ce2

Browse files
committed
feat: Support targets which don't use integers as their primary keys (closes #18)
1 parent d84235d commit b158ce2

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ uv run .
2525
# Linting and formatting
2626
uv run ruff check .
2727
uv run ruff format .
28+
29+
# Creating migrations
30+
uv run django-admin makemigrations generic_notifications --settings=tests.settings
2831
```
2932

3033
## Architecture Overview
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 5.2.5 on 2025-10-20 09:35
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("contenttypes", "0002_remove_content_type_name"),
10+
("generic_notifications", "0004_rename_emailfrequency_notificationfrequency"),
11+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12+
]
13+
14+
operations = [
15+
migrations.AlterModelOptions(
16+
name="notificationfrequency",
17+
options={"verbose_name_plural": "Notification frequencies"},
18+
),
19+
migrations.AlterField(
20+
model_name="notification",
21+
name="object_id",
22+
field=models.CharField(blank=True, max_length=36, null=True),
23+
),
24+
migrations.AddIndex(
25+
model_name="notification",
26+
index=models.Index(fields=["content_type", "object_id"], name="notification_target_idx"),
27+
),
28+
]

generic_notifications/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Notification(models.Model):
4949

5050
# Generic relation to link to any object (article, comment, etc)
5151
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True, blank=True)
52-
object_id = models.PositiveIntegerField(null=True, blank=True)
52+
object_id = models.CharField(max_length=36, null=True, blank=True)
5353
target = GenericForeignKey("content_type", "object_id")
5454

5555
# Flexible metadata for any extra data
@@ -61,6 +61,7 @@ class Meta:
6161
indexes = [
6262
models.Index(fields=["recipient", "read"], name="notification_unread_idx"),
6363
models.Index(fields=["recipient", "added"], name="notification_recipient_idx"),
64+
models.Index(fields=["content_type", "object_id"], name="notification_target_idx"),
6465
]
6566
ordering = ["-added"]
6667

0 commit comments

Comments
 (0)