migration(billing): Add expires_at field and is_expired property to Topup model for expiration management 🔧

This commit is contained in:
2025-07-04 16:32:21 +05:00
parent d4b26074e6
commit 6568504f5b
3 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# Generated by Django 5.2 on 2025-07-04 06:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("billing", "0007_topup_paid_at"),
]
operations = [
migrations.AlterModelOptions(
name="topup",
options={"ordering": ["-created_at"]},
),
migrations.AddField(
model_name="topup",
name="expired",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="topup",
name="expires_at",
field=models.DateTimeField(blank=True, null=True),
),
]

View File

@ -0,0 +1,16 @@
# Generated by Django 5.2 on 2025-07-04 11:13
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("billing", "0008_alter_topup_options_topup_expired_topup_expires_at"),
]
operations = [
migrations.RemoveField(
model_name="topup",
name="expired",
),
]

View File

@ -53,9 +53,16 @@ class Topup(models.Model):
paid = models.BooleanField(default=False) paid = models.BooleanField(default=False)
paid_at = models.DateTimeField(null=True, blank=True) paid_at = models.DateTimeField(null=True, blank=True)
mib_reference = models.CharField(default="", null=True, blank=True) mib_reference = models.CharField(default="", null=True, blank=True)
expires_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(default=timezone.now) created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
@property
def is_expired(self):
if self.expires_at is None:
return False
return timezone.now() > self.expires_at
def __str__(self): def __str__(self):
return f"Topup for {self.user}" return f"Topup for {self.user}"