mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 05:26:07 +00:00
Add wallet balance to User model and implement Atoll/Island management
- 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.
This commit is contained in:
@ -1,35 +1,37 @@
|
||||
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'),
|
||||
("WALLET", "Wallet"),
|
||||
("TRANSFER", "Transfer"),
|
||||
]
|
||||
|
||||
id = models.CharField(primary_key=True, max_length=255)
|
||||
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')
|
||||
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')
|
||||
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')
|
||||
devices = models.ManyToManyField(Device, related_name="payments")
|
||||
|
||||
def __str__(self):
|
||||
return f"Payment by {self.user}"
|
||||
|
||||
|
||||
class BillFormula(models.Model):
|
||||
id = models.CharField(primary_key=True, max_length=255)
|
||||
formula = models.CharField(max_length=255)
|
||||
base_amount = models.FloatField()
|
||||
discount_percentage = models.FloatField()
|
||||
@ -39,10 +41,11 @@ class BillFormula(models.Model):
|
||||
def __str__(self):
|
||||
return self.formula
|
||||
|
||||
|
||||
class Topup(models.Model):
|
||||
id = models.CharField(primary_key=True, max_length=255)
|
||||
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')
|
||||
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)
|
||||
|
Reference in New Issue
Block a user