Commit ef7ab00e authored by Daniel W Bond's avatar Daniel W Bond
Browse files

changed major field on student to many_to_many, and supported in admin...

changed major field on student to many_to_many, and supported in admin interface to allow migrations
parent 7fd4303a
......@@ -7,13 +7,22 @@ from .models import Student, Major, Confirmation
class StudentAdmin(admin.ModelAdmin):
list_display = ("get_name", "room", "privacy", "major", "created")
list_display = ("get_name", "room", "privacy", "get_first_major", "created")
def get_name(self, student):
return student.get_full_name_or_uname()
get_name.short_description = 'Name'
get_name.admin_order_field = 'user__username' # ordering by callables is hard
# We cannot use a manytomanyfield as a field in the list, so we're getting the first
# major. If we need to see a student's second major, we can just click the student.
# This covers nearly all students, who will have only one major.
def get_first_major(self, student):
return student.major.first()
get_first_major.short_description = 'Major'
# we're not going to give the option to sort by major for now
class MajorAdmin(admin.ModelAdmin):
list_display = ("name", "get_major_num", )
......@@ -168,7 +168,7 @@ class Student(TimeStampedModel):
on_campus = models.BooleanField(default=True)
room = models.ForeignKey(Room, null=True, blank=True)
major = models.ForeignKey('Major', related_name='major', null=True, blank=True)
major = models.ManyToManyField(Major, related_name='majors', blank=True)
times_changed_room = models.PositiveIntegerField(default=0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment