Spaces:
Running
Running
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'), | |
('karyakarta', 'Karyakarta'), | |
('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=20, 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) | |
streetName = models.TextField(null=True) | |
city = models.CharField(max_length=100, null=True) | |
state = models.CharField(max_length=100, null=True) | |
country = models.CharField(max_length=100, null=True) | |
pincode = models.CharField(max_length=10, null=True) | |
assigned_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_users') | |
profile_image = models.URLField(blank=True) | |
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 Notification(models.Model): | |
sender = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='sent_notifications') | |
recipients = models.ManyToManyField(Bhagat, related_name='received_notifications') | |
title = models.CharField(max_length=200, blank=True, null=True) | |
content = models.TextField() | |
timestamp = models.DateTimeField(auto_now_add=True) | |
notification_type = models.CharField(max_length=20, choices=(("orange", "Shabha"), ("green", "Activity"), ("blue", "Birthday"), ("red", "Important"), ("purple", "Gathering"), ("yellow", "Festival"), ("pink", "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('<audio controls><source src="https://huggingface.co/spaces/thejagstudio/MusicStore/resolve/main/Bhajan Audio/%s" type="audio/mpeg"></audio>' % 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 = '<ul class="object-tools" style="margin-top:0">' | |
for lang in languages: | |
html += '<li style="padding-bottom:12px"><a href="https://huggingface.co/spaces/thejagstudio/MusicStore/raw/main/HTML Files/'+lang[0] + self.lyrics+'" target="_blank" class="import_link">'+(lang[1])+'</a></li>' | |
html += '</ul>' | |
return mark_safe(html) |