Commit b7d5c58d authored by EASHAN GUPTA's avatar EASHAN GUPTA

added univs

parent 0cec1ba9
from allocation.models import *
def f(univ):
a=Applicant.objects.filter(university.objects.all()[0].name=univ).order_by('rank')
c=Choice.objects.all()
def allocator(univ):
a=Applicant.objects.filter(institute__name=univ).order_by('rank')
c=Choice.objects.filter(institute__name=univ)
my_dict=dict([(x,0) for x in c])
for x in a:
choices=x.ordered_choices()
......
......@@ -2,6 +2,13 @@ from django.contrib import admin
from .models import *
# class UnivAppInLine(admin.TabularInline):
# model=UnivApp
# extra=0
# class UnivChoiceInLine(admin.TabularInline):
# model=UnivChoice
# extra=0
class ChoiceInline(admin.TabularInline):
model = Application #https://stackoverflow.com/questions/5947843/django-how-does-manytomanyfield-with-through-appear-in-admin
......@@ -12,10 +19,13 @@ class AllotedChoiceToAppInLine(admin.TabularInline):
extra=0
class ApplicantAdmin(admin.ModelAdmin):
fields = ['name', 'rank']
fields = ['name', 'rank','institute']
inlines = [ChoiceInline, AllotedChoiceToAppInLine]
# class
admin.site.register(University)
# class ChoiceAdmin(admin.ModelAdmin):
# fields=['choice_name', 'capacity']
# inlines=[UnivChoiceInLine]
admin.site.register(Institute)
admin.site.register(Choice)
admin.site.register(Applicant, ApplicantAdmin)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-16 19:42
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Allocationcl',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
options={
'ordering': ['applicant__rank'],
},
),
migrations.CreateModel(
name='Applicant',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('rank', models.IntegerField()),
],
),
migrations.CreateModel(
name='Application',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('priority', models.IntegerField()),
('applicant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant')),
],
options={
'ordering': ['priority'],
},
),
migrations.CreateModel(
name='Choice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_name', models.CharField(max_length=200)),
('capacity', models.IntegerField()),
],
),
migrations.CreateModel(
name='University',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.AddField(
model_name='choice',
name='university',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='allocation.University'),
),
migrations.AddField(
model_name='application',
name='choice',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_applicant', through='allocation.Allocationcl', to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='choices',
field=models.ManyToManyField(related_name='applicants', through='allocation.Application', to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='university',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='applicants', to='allocation.University'),
),
migrations.AddField(
model_name='allocationcl',
name='applicant',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant'),
),
migrations.AddField(
model_name='allocationcl',
name='choice',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-16 20:02
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('allocation', '0001_initial'),
]
operations = [
migrations.RenameModel(
old_name='University',
new_name='Institute',
),
migrations.AlterModelOptions(
name='allocationcl',
options={'ordering': ['applicant__rank'], 'verbose_name': 'Allocated Choice', 'verbose_name_plural': 'Allocated Choice'},
),
migrations.AlterModelOptions(
name='institute',
options={'verbose_name': 'Institute', 'verbose_name_plural': 'Institutes'},
),
migrations.RenameField(
model_name='applicant',
old_name='university',
new_name='institute',
),
migrations.RenameField(
model_name='choice',
old_name='university',
new_name='institute',
),
]
from django.db import models
# import math
class University(models.Model):
class Institute(models.Model):
name=models.CharField(max_length=200)
def __str__(self):
return self.name
class Meta:
verbose_name='Institute'
verbose_name_plural='Institutes'
class Choice(models.Model):
choice_name = models.CharField(max_length=200)
university=models.ForeignKey(University,on_delete=models.CASCADE, related_name='choices')
institute=models.ForeignKey(Institute, on_delete=models.CASCADE, related_name='choices')
capacity = models.IntegerField()
def __str__(self):
return self.choice_name
......@@ -14,11 +20,11 @@ class Choice(models.Model):
# Null_Choice.save()
class Applicant(models.Model):
institute=models.ForeignKey(Institute,on_delete=models.CASCADE,related_name='applicants')
choices = models.ManyToManyField(Choice, through='Application', related_name='applicants')
name = models.CharField(max_length=200)
alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_applicant')
rank = models.IntegerField()
university=models.ForeignKey(University,on_delete=models.CASCADE,related_name='applicants')
def __str__(self):
return self.name
def ordered_choices(self):
......@@ -27,12 +33,13 @@ class Applicant(models.Model):
return self.choices.all().order_by('application__priority')
class Application(models.Model):
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
applicant = models.ForeignKey(Applicant, on_delete=models.CASCADE)
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
priority = models.IntegerField()
class Meta:
# if you have an inline configured in the admin, this will
# make the roles order properly
ordering = ['priority']
......@@ -43,4 +50,17 @@ class Allocationcl(models.Model):
class Meta:
# if you have an inline configured in the admin, this will
# make the roles order properly
verbose_name='Allocated Choice'
verbose_name_plural='Allocated Choice'
ordering = ['applicant__rank']
# class UnivChoice(models.Model):
# ,limit_choices_to={'institute':applicant.institute}
# choice=models.ForeignKey(Choice,on_delete=models.CASCADE)
# university=models.ForeignKey(University,on_delete=models.CASCADE)
# , limit_choices_to={'university__name':'applicant_university__name'}
# class UnivApp(models.Model):
# applicant=models.ForeignKey(Applicant,on_delete=models.CASCADE)
# university=models.ForeignKey(University,on_delete=models.CASCADE)
# class Meta:
# ordering=['applicant__rank']
\ No newline at end of file
No preview for this file type
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