summaryrefslogtreecommitdiff
path: root/workshop_app/models.py
blob: 03be064d1086ff86f0a433109f7523c9530f8acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from recurrence.fields import RecurrenceField

position_choices = (
	("coordinator", "Coordinator"),
	("instructor", "Instructor")
	)

status_choices = (
	("pending", "Pending"),
	("confirm", "Confirm")
	)

def has_profile(user):
	""" check if user has profile """
	return True if hasattr(user, 'profile') else False

class Profile(models.Model):
	"""Profile for users(instructors and coordinators)"""

	user = models.OneToOneField(User)
	institute = models.CharField(max_length=150)
	department = models.CharField(max_length=150)
	phone_number = models.CharField(
				max_length=15,
				validators=[RegexValidator(
									regex=r'^\+?1?\d{9,15}$', message=(
									"Phone number must be entered \
                                     in the format: '+999999999'.\
                                      Up to 15 digits allowed.")
							)])
	position = models.CharField(max_length=32, choices=position_choices)

	def __str__(self):
		return u"id: {0}| {1} {2} | {3} ".format(
											self.user.id,
											self.user.first_name, 
											self.user.last_name, 
											self.user.email
										    ) 


class Course(models.Model):
	""""Admin creates courses which can be used by the instructor 
		to create workshops.
	"""

	course_name = models.CharField(max_length=120)
	course_description = models.TextField()
	course_duration = models.CharField(max_length=32)

	def __str__(self):
		return u"{0} {1}".format(self.course_name, self.course_duration)



class Workshop(models.Model):
	"""Instructor Creates workshop based on
	Courses	available"""

	workshop_instructor = models.ForeignKey(User, on_delete=models.CASCADE)
	workshop_title = models.ForeignKey(
										Course, on_delete=models.CASCADE,\
		 								help_text='Select the course for which \
		 								you would like to create a workshop.'
		 							  )
	#For recurring workshops source: django-recurrence
	recurrences = RecurrenceField()

	def __str__(self):
		return u"{0} | {1} ".format(self.workshop_title, self.workshop_instructor)


class RequestedWorkshop(models.Model):
	"""
	Contains Data of Booked/Completed Workshops 
	"""

	requested_workshop_instructor = models.ForeignKey(
											 User,
											 on_delete=models.CASCADE
											 		)
	requested_workshop_coordinator = models.ForeignKey(
									User, 
									related_name="%(app_label)s_%(class)s_related"
													  )
	requested_workshop_date = models.DateField()
	status = models.CharField(
							max_length=32, default="Pending", 
							choices=status_choices
							)
	requested_workshop_title = models.ForeignKey(
									Course, 
									on_delete=models.CASCADE
												)