from django.db import models from django.contrib.auth.models import AbstractUser import datetime as DateTime from django.utils.html import mark_safe class Bhagat(AbstractUser): USER_TYPES = ( ('superadmin', 'Super Admin'), ('regionadmin', 'Region Admin'), ('monitor', 'Monitor'), ('user', 'User'), ) MEMBER_TYPES = ( ('ambrish', 'Ambrish'), ('sadbhav', 'Sadbhav'), ('vip', 'VIP'), ('youvak', 'Youvak'), ) user_type = models.CharField(max_length=20, choices=USER_TYPES, default="user") phone = models.CharField(max_length=15, null=True) member_type = models.CharField(max_length=20, choices=MEMBER_TYPES, default="youvak") region = models.ForeignKey('Region', on_delete=models.SET_NULL, null=True) birthday = models.DateField(default=DateTime.date.today, null=True) address = models.TextField(null=True) assigned_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_users') def __str__(self): return self.first_name + ' ' + self.last_name class Region(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name class Event(models.Model): COLOR_CHOICES = (("orange","Shabha"), ("green","Activity"), ("blue","Birthday"), ("red","Important"), ("purple","Gathering"), ("yellow","Festival"), ("pink","Special")) title = models.CharField(max_length=200) description = models.TextField() date = models.DateTimeField() time = models.TimeField(default='00:00') created_by = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='created_events',blank=True,null=True) region = models.ForeignKey(Region, on_delete=models.CASCADE, blank=True,null=True) is_approved = models.BooleanField(default=False) color = models.CharField(max_length=15, default='orange',choices=COLOR_CHOICES) def __str__(self): return self.title class Attendance(models.Model): user = models.ForeignKey(Bhagat, on_delete=models.CASCADE) event = models.ForeignKey(Event, on_delete=models.CASCADE) status = models.CharField(max_length=20, choices=(('attending', 'Attending'), ('not_attending', 'Not Attending'), ('maybe', 'Maybe'))) class Message(models.Model): sender = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='sent_messages') recipient = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='received_messages') content = models.TextField() timestamp = models.DateTimeField(auto_now_add=True) class Notification(models.Model): sender = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='sent_notifications') recipients = models.ManyToManyField(Bhagat, related_name='received_notifications') content = models.TextField() timestamp = models.DateTimeField(auto_now_add=True) notification_type = models.CharField(max_length=20, choices=(('event', 'Event'), ('birthday', 'Birthday'), ('custom', 'Custom'))) class BhajanCategory(models.Model): name = models.CharField(max_length=100) link = models.CharField(max_length=100) def __str__(self): return self.name class Bhajan(models.Model): bhajanId = models.IntegerField(blank=True,default=0) title = models.CharField(max_length=500,blank=True) title_guj = models.CharField(max_length=500,blank=True) category = models.ForeignKey(BhajanCategory, on_delete=models.CASCADE) lyrics = models.CharField(max_length=50, blank=True) audio_url = models.URLField(blank=True) isEng = models.BooleanField(default=False) isHnd = models.BooleanField(default=False) isGer = models.BooleanField(default=False) isAudio = models.BooleanField(default=False) def __str__(self): return self.title def musicPreivew(self): if self.isAudio: return mark_safe('' % self.audio_url) else: return 'No Audio Available' def lyricsBtn(self): # i have four languages in my bhajan so add them all as buttons and show them on click languages = [["","GUJ"]] if self.isEng: languages.append(['E','ENG']) if self.isHnd: languages.append(['H','HND']) if self.isGer: languages.append(['G','GER']) html = '