-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathmodels.py
More file actions
26 lines (23 loc) · 1.09 KB
/
models.py
File metadata and controls
26 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
class Subscription(models.Model):
user = models.ForeignKey(User,
related_name='subscription',
db_index=True,
on_delete=models.CASCADE)
subscribe = models.BooleanField(default=True)
target_ct = models.ForeignKey(ContentType,
blank=True,
null=True,
related_name='target_obj',
on_delete=models.CASCADE
)
target_id = models.PositiveIntegerField(null=True,
blank=True,
db_index=True)
target = GenericForeignKey('target_ct', 'target_id')
created = models.DateTimeField(auto_now_add=True, db_index=True)
class Meta:
ordering = ('-created', )