Added last subscribe/unsubscribe dates
This commit is contained in:
parent
d3c723eb43
commit
a8f053a646
|
|
@ -1,10 +1,12 @@
|
||||||
"""Notification app models."""
|
"""Notification app models."""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from account.models import User
|
from account.models import User
|
||||||
from utils.methods import generate_string_code
|
from utils.methods import generate_string_code
|
||||||
from utils.models import ProjectBaseMixin, TranslatedFieldsMixin, TJSONField
|
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
|
class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
|
|
@ -109,6 +111,9 @@ class Subscriber(ProjectBaseMixin):
|
||||||
|
|
||||||
subscription_type = models.ForeignKey(SubscriptionType, on_delete=models.CASCADE, null=True, default=None)
|
subscription_type = models.ForeignKey(SubscriptionType, on_delete=models.CASCADE, null=True, default=None)
|
||||||
|
|
||||||
|
subscribe_date = models.DateTimeField(_('Last subscribe date', blank=True, null=True, default=now))
|
||||||
|
unsubscribe_date = models.DateTimeField(_('Last unsubscribe date'), blank=True, null=True, default=None)
|
||||||
|
|
||||||
objects = SubscriberManager.from_queryset(SubscriberQuerySet)()
|
objects = SubscriberManager.from_queryset(SubscriberQuerySet)()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -125,6 +130,7 @@ class Subscriber(ProjectBaseMixin):
|
||||||
|
|
||||||
def unsubscribe(self):
|
def unsubscribe(self):
|
||||||
"""Unsubscribe user."""
|
"""Unsubscribe user."""
|
||||||
|
self.unsubscribe_date = now()
|
||||||
self.state = self.UNUSABLE
|
self.state = self.UNUSABLE
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ class SubscribeSerializer(serializers.ModelSerializer):
|
||||||
'email',
|
'email',
|
||||||
'subscription_type',
|
'subscription_type',
|
||||||
'state',
|
'state',
|
||||||
|
'subscribe_date',
|
||||||
|
'unsubscribe_date'
|
||||||
)
|
)
|
||||||
read_only_fields = ('state',)
|
read_only_fields = ('state',)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user