Commit 7ad61144 authored by KUNAL GOYAL's avatar KUNAL GOYAL

applicant login

parents ec7c9f04 ccd82ecc
from allocation.models import *
def f():
a=Applicant.objects.all().order_by('rank')
c=Choice.objects.all()
my_dict=dict([(x,0) for x in c])
for x in a:
choices=x.ordered_choices()
temp=0
i=0
while temp==0 and i<len(choices):
if(choices[i].capacity>my_dict[choices[i]]):
my_dict[choices[i]]=my_dict[choices[i]]+1
temp=1
x.alloted_choice.clear()
clalloc=Allocationcl(choice=choices[i],applicant=x)
clalloc.save()
# x.alloted_choice.clear()
# x.alloted_choice.create(choices[i])
# if(temp!=1)
# x.alloted_choice.clear()
# x.alloted_choice.create(Null_choice)
# cll=Allocationcl(choice=Null_choice,applicant=x)
i=i+1
return a
\ No newline at end of file
from django.contrib import admin
from .models import Applicant,Choice,Application
from .models import Applicant,Choice,Application,Allocationcl
admin.site.register(Choice)
......@@ -11,5 +11,7 @@ class ChoiceInline(admin.TabularInline):
class ApplicantAdmin(admin.ModelAdmin):
fields = ['name', 'rank']
inlines = [ChoiceInline]
admin.site.register(Applicant, ApplicantAdmin)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-09 20:28
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('allocation', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='application',
options={'ordering': ['priority']},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-14 12:11
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0002_auto_20171010_0158'),
]
operations = [
migrations.CreateModel(
name='Allocationcl',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('applicant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant')),
('choice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice')),
],
options={
'ordering': ['applicant__rank'],
},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-14 13:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0003_allocationcl'),
]
operations = [
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', through='allocation.Allocationcl', to='allocation.Choice'),
),
migrations.AlterField(
model_name='applicant',
name='choices',
field=models.ManyToManyField(related_name='choices', through='allocation.Application', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:52
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0004_auto_20171014_1830'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0005_auto_20171016_0322'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0006_auto_20171016_0326'),
]
operations = [
migrations.AlterField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(default=None, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 22:01
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0007_auto_20171016_0328'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 22:14
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0008_auto_20171016_0331'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', through='allocation.Allocationcl', to='allocation.Choice'),
),
]
from django.db import models
# import math
class Choice(models.Model):
choice_name = models.CharField(max_length=200)
# alloted_applicants = models.ManyToManyField(Applicant, through='Allocationcl')
capacity = models.IntegerField()
def __str__(self):
return self.choice_name
# Null_Choice=Choice.objects.create(choice_name="None",capacity=1000)
# Null_Choice.save()
class Applicant(models.Model):
choices = models.ManyToManyField(Choice, through='Application')
choices = models.ManyToManyField(Choice, through='Application', related_name='choices')
name = models.CharField(max_length=200)
alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_choice')
rank = models.IntegerField()
def __str__(self):
return self.name
def ordered_choices(self): #https://stackoverflow.com/questions/934779/django-order-a-model-by-a-many-to-many-field
def ordered_choices(self):
#https://stackoverflow.com/questions/934779/django-order-a-model-by-a-many-to-many-field
"Return a properly ordered set of choices"
return self.choices.all().order_by('application__priority')
......@@ -25,3 +32,12 @@ class Application(models.Model):
# make the roles order properly
ordering = ['priority']
class Allocationcl(models.Model):
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
applicant = models.ForeignKey(Applicant, 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 = ['applicant__rank']
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