from django.db import models from multiselectfield import MultiSelectField from admin.models import Functions # Create your models here. LEVELS = Functions.getStudentLevels() DAYS = Functions.getDaysAvailable() FACULTIES = Functions.getFacultyList() DEPARTMENTS = Functions.getDepartmentList() class Venue(models.Model): code = models.CharField(max_length=10, unique=True) name = models.CharField(max_length=10, unique=True) capacity = models.IntegerField(default=50) type = models.IntegerField(default=0) reservedFaculty = MultiSelectField(choices=FACULTIES, max_length=2048) reservedDepartment = MultiSelectField(choices=DEPARTMENTS, max_length=2048) reservedLevel = MultiSelectField(choices=LEVELS, max_length=2048) reservedDays = MultiSelectField(choices=DAYS, max_length=2048)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) newid = Functions.getNewId(Venue, 'VEN', "{:03}") self.fields["code"].initial = newid CAPACITY = Functions.getVenueTypes() self.fields["type"] = forms.ChoiceField( label='Type', choices=CAPACITY, required=False, widget=forms.Select(attrs={'class': 'form-control p-input'})) LEVELS = Functions.getStudentLevels() AVAILABLEDAYS = Functions.getDaysAvailable() FACULTIES = Functions.getFacultyList() DEPARTMENTS = Functions.getDepartmentList() self.fields["reservedDays"] = forms.MultipleChoiceField( label='Days', choices=AVAILABLEDAYS, widget=forms.SelectMultiple( attrs={ 'class': 'selectpicker w-100', 'multiple': 'multiple', 'style': 'width:100%', })) self.fields["reservedLevel"] = forms.MultipleChoiceField( label='Levels', choices=LEVELS, widget=forms.SelectMultiple( attrs={ 'class': 'selectpicker w-100', 'multiple': 'multiple', 'style': 'width:100%', })) self.fields["reservedFaculty"] = forms.MultipleChoiceField( label='Faculties', choices=FACULTIES, widget=forms.SelectMultiple( attrs={ 'class': 'selectpicker w-100 populate-drop', 'multiple': 'multiple', 'data-live-search': 'true', 'style': 'width:100%', 'data-source': 'faculty', 'data-link': 'reservedDepartment', 'singular': '0', })) self.fields["reservedDepartment"] = forms.MultipleChoiceField( label='Departments', choices=DEPARTMENTS, widget=forms.SelectMultiple( attrs={ 'class': 'selectpicker w-100', 'multiple': 'multiple', 'data-live-search': 'true', 'style': 'width:100%', }))