What is the best approach

23 views
Skip to first unread message

Arshdeep Singh

unread,
Jun 10, 2017, 2:26:58 AM6/10/17
to Django users

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

Melvyn Sopacua

unread,
Jun 10, 2017, 12:41:28 PM6/10/17
to django...@googlegroups.com

On Friday 09 June 2017 23:26:57 Arshdeep Singh wrote:

> 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.

 

All this is outside Django's scope. This is business logic you need to work out. Many of us could do it for you and be happy to make you an offer conforming to market prices.

 

Right now, your models are missing information (questionable gender choices aside). Work out how the rooms need to be filled and the data model will come to you. The most obvious being, that Students don't have a "year of enrollment" or "student type" to indicate the rooms they can apply for. In your specification above, the definition of preferences is incomplete.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages