mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-02-21 18:51:59 +00:00
- Added `wallet_balance` field to the User model. - Updated UserAdmin to include `wallet_balance` in the admin interface. - Created serializers and views for Atoll and Island management. - Implemented endpoints for listing, creating, and updating Atolls and Islands. - Enhanced payment processing with UUIDs for Payment and Topup models. - Added migration files for new fields and constraints. - Improved error handling and validation in various views. - Updated email templates for better responsiveness and SEO.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from django.db import models
|
|
from django.utils import timezone
|
|
from api.models import User
|
|
import uuid
|
|
|
|
# Create your models here.
|
|
|
|
from devices.models import Device
|
|
|
|
# Create your models here.
|
|
|
|
|
|
class Payment(models.Model):
|
|
PAYMENT_TYPES = [
|
|
("WALLET", "Wallet"),
|
|
("TRANSFER", "Transfer"),
|
|
]
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
number_of_months = models.IntegerField()
|
|
amount = models.FloatField()
|
|
paid = models.BooleanField(default=False)
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="payments")
|
|
paid_at = models.DateTimeField(null=True, blank=True)
|
|
method = models.CharField(max_length=255, choices=PAYMENT_TYPES, default="TRANSFER")
|
|
expires_at = models.DateTimeField(null=True, blank=True)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
devices = models.ManyToManyField(Device, related_name="payments")
|
|
|
|
def __str__(self):
|
|
return f"Payment by {self.user}"
|
|
|
|
|
|
class BillFormula(models.Model):
|
|
formula = models.CharField(max_length=255)
|
|
base_amount = models.FloatField()
|
|
discount_percentage = models.FloatField()
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return self.formula
|
|
|
|
|
|
class Topup(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
amount = models.FloatField()
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="topups")
|
|
paid = models.BooleanField(default=False)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return f"Topup for {self.user}"
|