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:
2025-01-20 20:59:16 +05:00
parent 4d0eb86478
commit f6f77bb0e5
19 changed files with 513 additions and 108 deletions

View File

@ -7,6 +7,7 @@ from django.db import models
from .managers import CustomUserManager
from django.utils import timezone
class User(AbstractUser):
email = models.EmailField(unique=True, blank=True, null=True)
address = models.CharField(max_length=255, blank=True)
@ -20,8 +21,13 @@ class User(AbstractUser):
policy_accepted = models.BooleanField(default=False)
wallet_balance = models.FloatField(default=0.0)
ninja_user_id = models.CharField(max_length=255, blank=True)
atoll = models.ForeignKey('Atoll', on_delete=models.SET_NULL, null=True, blank=True, related_name='users')
island = models.ForeignKey('Island', on_delete=models.SET_NULL, null=True, blank=True, related_name='users')
atoll = models.ForeignKey(
"Atoll", on_delete=models.SET_NULL, null=True, blank=True, related_name="users"
)
island = models.ForeignKey(
"Island", on_delete=models.SET_NULL, null=True, blank=True, related_name="users"
)
def get_all_fields(self, instance):
return [field.name for field in instance.get_fields()]
@ -29,16 +35,17 @@ class User(AbstractUser):
class Atoll(models.Model):
name = models.CharField(max_length=255)
name = models.CharField(max_length=255, unique=True)
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
class Island(models.Model):
atoll = models.ForeignKey(Atoll, on_delete=models.CASCADE, related_name='islands')
name = models.CharField(max_length=255)
atoll = models.ForeignKey(Atoll, on_delete=models.CASCADE, related_name="islands")
name = models.CharField(max_length=255, unique=True)
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)