You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.1 KiB
80 lines
3.1 KiB
from django.db import models
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from apps.account.models import StudentUser, User
|
|
from apps.course.models import Course
|
|
from phonenumber_field.modelfields import PhoneNumberField
|
|
from utils.validators import validate_possible_number
|
|
|
|
|
|
|
|
|
|
|
|
class TransactionParticipant(models.Model):
|
|
|
|
|
|
class TransactionStatus(models.TextChoices):
|
|
PENDING = 'pending', _('Pending')
|
|
SUCCESS = 'success', _('Success')
|
|
FAILED = 'failed', _('Failed')
|
|
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='transactions')
|
|
course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='course_transactions')
|
|
# is_paid = models.BooleanField(default=False, verbose_name='Payment Status', help_text='Indicates whether the payment has been completed or not')
|
|
price = models.DecimalField(max_digits=10, decimal_places=2, default=0.00, verbose_name='Transaction Price')
|
|
status = models.CharField(max_length=20, choices=TransactionStatus.choices, default=TransactionStatus.PENDING, verbose_name=_('Transaction Status'))
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at"))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated at"))
|
|
is_deleted = models.BooleanField(default=False)
|
|
|
|
def __str__(self):
|
|
return f"{self.user.email} - {self.course.title} ({self.status})"
|
|
|
|
def is_participant_enrolled(self):
|
|
"""بررسی اینکه آیا کاربر در دوره ثبتنام شده یا نه"""
|
|
from apps.course.models import Participant
|
|
return Participant.objects.filter(
|
|
student=self.user,
|
|
course=self.course
|
|
).exists()
|
|
|
|
def get_participant(self):
|
|
"""دریافت شرکتکننده دوره اگر وجود داشته باشد"""
|
|
from apps.course.models import Participant
|
|
return Participant.objects.filter(
|
|
student=self.user,
|
|
course=self.course
|
|
).first()
|
|
|
|
|
|
|
|
|
|
class ParticipantInfo(models.Model):
|
|
class GenderChoices(models.TextChoices):
|
|
MALE = 'male', 'Male'
|
|
FEMALE = 'female', 'Female'
|
|
|
|
transaction_participant = models.ForeignKey(
|
|
TransactionParticipant,
|
|
on_delete=models.CASCADE,
|
|
related_name='participant_infos',
|
|
verbose_name="Transaction Participant"
|
|
)
|
|
fullname = models.CharField(max_length=255, verbose_name="Full Name", help_text="Enter the full name of the user.")
|
|
email = models.EmailField(verbose_name="Email Address", help_text="Enter the user's email address.")
|
|
phone_number = PhoneNumberField(validators=[validate_possible_number], null=True, blank=True, verbose_name=_('phone'))
|
|
gender = models.CharField(
|
|
max_length=20, choices=GenderChoices.choices, null=True, blank=True, verbose_name=_('Gender'), help_text="Select the user's gender."
|
|
)
|
|
birthdate = models.DateField(verbose_name=_('birthdate'), null=True, blank=True)
|
|
|
|
def __str__(self):
|
|
return f"{self.fullname} (Transaction: {self.transaction_participant.id}) - {self.email}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|