Skip to content

Commit

Permalink
Update models __str__ (#105)
Browse files Browse the repository at this point in the history
update __str__ methods
  • Loading branch information
kunnapool authored Jul 19, 2022
1 parent 43b4d39 commit ba6fe6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Meta:
managed = True #auto creates tables
db_table = 'Courses'

def __str__(self):
return self.course_title + ' - ' + self.course_title


#Algorithm Specific Models

Expand Down
4 changes: 4 additions & 0 deletions preferences/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class SabbaticalLength(models.TextChoices):
preferred_non_teaching_semester = models.CharField(max_length=10, blank=True, default='')
preferred_courses_per_semester = models.JSONField(default=dict)
preferred_course_day_spreads = ArrayField(models.CharField(max_length=5, blank=False), default=list)

def __str__(self):
return self.professor.first_name + ' ' + self.professor.last_name


class Meta:
managed = True #auto creates tables
Expand Down
12 changes: 7 additions & 5 deletions schedule/Schedule_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class A_CourseSection(models.Model):
capacity = models.PositiveIntegerField(default=0)
timeSlots = models.ManyToManyField(A_TimeSlot, related_name='courseSections') #to associate multiple TimeSlot objects

'''def __str__(self):
def __str__(self):
related_timeSlots = [str(slot) for slot in self.timeSlots.all()]
prof = str(self.professor['name']) if not None else 'null'
return 'Professor: ' + prof + ', Capacity: ' + str(self.capacity) + ', TimeSlots: ' + f'{" ".join(related_timeSlots)}'
'''
id_str = '#' + str(self.id) + ') '
if self.professor is not None and len(related_timeSlots) != 0:
return id_str + 'Professor: ' + str(self.professor['name']) + ', Capacity: ' + str(self.capacity) + ', TimeSlots: ' + f'{" ".join(related_timeSlots)}'

return id_str + 'A_Coursection(capacity: ' + str(self.capacity) + ')'


'''PRIMARY KEY: code'''
Expand All @@ -53,7 +55,7 @@ class A_Course(models.Model):
yearRequired = models.PositiveIntegerField()

def __str__(self):
return str(self.code)
return str(self.code) + ' - ' + str(self.title)


#one instance of this class should represent a single Course & CourseSection pair
Expand Down
4 changes: 4 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Meta:
managed = True #auto creates tables
db_table = 'appuser'


def __str__(self):
return self.user.first_name + ' ' + self.user.last_name + ' (' + self.user.username + '@uvic.ca)'

# Use Django signals to delete User instance when AppUser is deleted. Based on: https://stackoverflow.com/a/12754229
@receiver(post_delete, sender=AppUser)
def post_delete_user(sender, instance, **kwargs):
Expand Down

0 comments on commit ba6fe6d

Please sign in to comment.