комит
This commit is contained in:
@@ -332,6 +332,8 @@ class SubscriptionAdmin(admin.ModelAdmin):
|
||||
|
||||
def days_left_display(self, obj):
|
||||
"""Отображение оставшихся дней"""
|
||||
if not obj or not obj.expires_at:
|
||||
return "—"
|
||||
days = obj.days_left()
|
||||
if days == 0:
|
||||
return format_html('<span style="color: red;">Истекла</span>')
|
||||
@@ -344,6 +346,8 @@ class SubscriptionAdmin(admin.ModelAdmin):
|
||||
|
||||
def is_expired_display(self, obj):
|
||||
"""Отображение статуса истечения"""
|
||||
if not obj or not obj.expires_at:
|
||||
return "—"
|
||||
if obj.is_expired():
|
||||
return format_html('<span style="color: red;">Да</span>')
|
||||
else:
|
||||
|
||||
@@ -262,14 +262,18 @@ class Subscription(models.Model):
|
||||
|
||||
def is_expired(self):
|
||||
"""Проверка истечения подписки"""
|
||||
if not self.expires_at:
|
||||
return False
|
||||
return timezone.now() > self.expires_at
|
||||
|
||||
def days_left(self):
|
||||
"""Количество дней до окончания подписки"""
|
||||
if not self.expires_at:
|
||||
return 0
|
||||
if self.is_expired():
|
||||
return 0
|
||||
delta = self.expires_at - timezone.now()
|
||||
return delta.days
|
||||
return max(delta.days, 0)
|
||||
|
||||
@staticmethod
|
||||
def create_trial(client):
|
||||
|
||||
Reference in New Issue
Block a user