down votefavorite 
<https://stackoverflow.com/questions/44457374/how-should-i-do-this-in-django#>

I was thinking about making a Hostel Allocation Web application. It has 
models, Student, Room, Hostel. What I want is to create a function that 
allocates students after each year. For that, I thought in the student view 
each student after completing his four years of stay can click on vacate 
hostel after completing his degree, and for others, I want to create 
something that allocates them, Now there are certain constraints, there are 
Undergraduate students with degree period 4 years and each year has access 
to different types of rooms, First-year triple sharing, second and 
third-year double sharing and fourth-year single rooms. Also, a Hostel has 
Ph.D. students as well but their stay period is not defined.

So, what I was thinking is that First years should be allotted by uploading 
a CSV file and I have made that part, So the next part is to allot 
subsequent years based on their preferences, So how could I make something 
like this in Django that allows them to make it based on their preference, 
I was thinking each student would be given a unique token, and while 
filling for rooms one student can do for a room, and that token needs to be 
entered. Is this the right way or should I do something else. I am a newbie 
please suggest me a good way to do this.

models.py

class Student(models.Model):
    name = models.CharField(max_length = 40,help_text = "Name of the student")
    entry_number = models.CharField(max_length = 11,help_text = "Entry Number 
of a student")
    hostel_name = models.ForeignKey('Hostel', on_delete = models.SET_NULL,null 
= True)
    room = models.ForeignKey('Room',on_delete = models.SET_NULL,null = True)
    CHOICES = (
        ('m','Male'),
        ('f','Female'),
        ('e','Engaged'),
    )
    gender = models.CharField(max_length=1,choices=CHOICES)
    def __str__(self):
       return '%s, %s' % (self.name,self.entry_number)
    def get_absolute_url(self):
        return reverse('student-detail',args=[str(self.id)])
    class Meta:
        verbose_name="Student Record"

class Hostel(models.Model):
    name= models.CharField(max_length= 15)
    locality= models.URLField(max_length= 200, blank= True, 
default='',help_text='Google maps URL of the hostel')
    total_rooms= models.PositiveSmallIntegerField(null=True, blank =True)
    CHOICES = (
        ('m', 'Male'),
        ('f', 'Female'),
        ('e', 'Engaged'),
    )
    gender = models.CharField(max_length=1, choices=CHOICES, 
verbose_name=_('Type of Hostel'), help_text='Either Boys/Girls or Married 
students Hostel')
    def __str__(self):
        return  self.name
    def get_absolute_url(self):
        return reverse('hostel-detail',args=[str(self.id)])
    class Meta:
        verbose_name="Hostel Record"

class Room(models.Model):
    hostel= models.ForeignKey(Hostel, on_delete=models.CASCADE)
    name= models.CharField(max_length = 5)
    floor= models.CharField(max_length = 1, blank=True)
    wing= models.CharField(max_length = 1, blank=True)
    comment= models.CharField(max_length = 100,blank=True, default = "comment 
here")
    room_capacity = 
models.PositiveSmallIntegerField(validators=[MaxValueValidator(3),])
    room_accomodation= models.PositiveSmallIntegerField()

    def __str__(self):
        return self.name
    def get_absolute_url(self):
        return reverse('room-detail',args=[str(self.id)])
    class Meta:
        verbose_name="Room Record

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/912b30a8-5ca8-4ea6-ba09-29654d1943e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to