"""Junior model """ """Import django""" from django.db import models """Import get_user_model function""" from django.contrib.auth import get_user_model """Import ArrayField""" from django.contrib.postgres.fields import ArrayField """Import django app""" from base.constants import GENDERS, SIGNUP_METHODS, RELATIONSHIP, GUARDIAN_CODE_STATUS, ARTICLE_STATUS # Import guardian's model from guardian.models import Guardian # Import web admin's model from web_admin.models import SurveyOption, ArticleSurvey, Article, ArticleCard """Define User model""" User = get_user_model() # Create your models here. # Define junior model with # various fields like # phone, country code, # country name, # gender, # date of birth, # profile image, # relationship type of the guardian # signup method, # guardian code, # junior code, # referral code, # referral code that used by the junior # is invited junior # profile is active or not # profile is complete or not # passcode # junior is verified or not """Define junior points model""" # points of the junior # position of the junior # define junior guardian relation model class Junior(models.Model): """Junior model""" auth = models.ForeignKey(User, on_delete=models.CASCADE, related_name='junior_profile', verbose_name='Email') # Contact details""" phone = models.CharField(max_length=31, null=True, blank=True, default=None) country_code = models.IntegerField(blank=True, null=True) # country name of the guardian""" country_name = models.CharField(max_length=100, null=True, blank=True, default=None) # Personal info""" gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None) # Date of birth""" dob = models.DateField(max_length=15, null=True, blank=True, default=None) # Image of the junior""" image = models.URLField(null=True, blank=True, default=None) # Sign up method""" signup_method = models.CharField(max_length=31, choices=SIGNUP_METHODS, default='1') # Codes""" junior_code = models.CharField(max_length=10, null=True, blank=True, default=None) # Guardian Codes""" guardian_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True) # Referral code""" referral_code = models.CharField(max_length=10, null=True, blank=True, default=None) # Referral code that is used by junior while signup""" referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None) # invited junior""" is_invited = models.BooleanField(default=False) # Profile activity""" is_active = models.BooleanField(default=True) # check password is set or not is_password_set = models.BooleanField(default=True) # junior profile is complete or not""" is_complete_profile = models.BooleanField(default=False) # passcode of the junior profile""" passcode = models.IntegerField(null=True, blank=True, default=None) # junior is verified or not""" is_verified = models.BooleanField(default=False) """guardian code is approved or not""" guardian_code_approved = models.BooleanField(default=False) # guardian code status""" guardian_code_status = models.CharField(max_length=31, choices=GUARDIAN_CODE_STATUS, default='1', null=True, blank=True) # Profile created and updated time""" created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ db_table = 'junior' verbose_name = 'Junior' # another name of the model""" verbose_name_plural = 'Junior' def __str__(self): """Return email id""" return f'{self.auth}' class JuniorPoints(models.Model): """Junior model""" junior = models.OneToOneField(Junior, on_delete=models.CASCADE, related_name='junior_points') # Total earned points""" total_points = models.IntegerField(blank=True, null=True, default=0) # referral points""" referral_points = models.IntegerField(blank=True, null=True, default=0) # position of the junior""" position = models.IntegerField(blank=True, null=True, default=99999) # Profile created and updated time""" created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ db_table = 'junior_task_points' verbose_name = 'Junior Task Points' # another name of the model""" verbose_name_plural = 'Junior Task Points' def __str__(self): """Return email id""" return f'{self.junior.auth}' class JuniorGuardianRelationship(models.Model): """Junior Guardian relationship model""" guardian = models.ForeignKey(Guardian, on_delete=models.CASCADE, related_name='guardian_relation', verbose_name='Guardian') # associated junior with the task junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='junior_relation', verbose_name='Junior') # relation between guardian and junior""" relationship = models.CharField(max_length=31, choices=RELATIONSHIP, null=True, blank=True, default='1') """Profile created and updated time""" created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ db_table = 'junior_guardian_relation' """verbose name of the model""" verbose_name = 'Junior Guardian Relation' verbose_name_plural = 'Junior Guardian Relation' def __str__(self): """Return email id""" return f'{self.guardian.user}' class JuniorArticlePoints(models.Model): """ Survey Options model """ # associated junior with the task junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='juniors_details', verbose_name='Junior') article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='junior_articles') question = models.ForeignKey(ArticleSurvey, on_delete=models.CASCADE, related_name='questions') submitted_answer = models.ForeignKey(SurveyOption, on_delete=models.SET_NULL, null=True, related_name='submitted_answer') # earn points""" earn_points = models.IntegerField(blank=True, null=True, default=5) is_attempt = models.BooleanField(default=False) is_answer_correct = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ verbose_name = 'Junior Article Points' # another name of the model""" verbose_name_plural = 'Junior Article Points' def __str__(self): """Return title""" return f'{self.id} | {self.question}' class JuniorArticle(models.Model): """ Survey Options model """ # associated junior with the task junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='juniors_article', verbose_name='Junior') article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='junior_articles_details') # article completed""" is_completed = models.BooleanField(default=False) status = models.CharField(max_length=10, choices=ARTICLE_STATUS, null=True, blank=True, default='1') current_card_page = models.IntegerField(blank=True, null=True, default=0) current_que_page = models.IntegerField(blank=True, null=True, default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ verbose_name = 'Junior Article' # another name of the model""" verbose_name_plural = 'Junior Article' def __str__(self): """Return title""" return f'{self.id} | {self.article}' class JuniorArticleCard(models.Model): """ Survey Options model """ # associated junior with the task junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='juniors_article_card', verbose_name='Junior') article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='junior_articles_detail') article_card = models.ForeignKey(ArticleCard, on_delete=models.CASCADE, related_name='junior_article_card') # article card read""" is_read = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ verbose_name = 'Junior Article Card' # another name of the model""" verbose_name_plural = 'Junior Article Card' def __str__(self): """Return title""" return f'{self.id} | {self.article}' class FAQ(models.Model): """FAQ model""" # questions""" question = models.CharField(max_length=100) # answer""" description = models.CharField(max_length=500) # status status = models.IntegerField(default=1, null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta(object): """ Meta class """ verbose_name = 'FAQ' # another name of the model""" verbose_name_plural = 'FAQ' def __str__(self): """Return email id""" return f'{self.question}'