app/projrev/models.py
changeset 22 0321f984fb16
parent 21 153db75bb515
child 23 91cf6872d853
equal deleted inserted replaced
21:153db75bb515 22:0321f984fb16
     8 ]
     8 ]
     9 
     9 
    10 
    10 
    11 from django.db import models
    11 from django.db import models
    12 from django.contrib.auth.models import User
    12 from django.contrib.auth.models import User
       
    13 
       
    14 
       
    15 def sort_dict(d):
       
    16   """Function to sort dictionary elements.
       
    17   """
       
    18 
       
    19   items =  [(v, k) for k, v in d.items()]
       
    20   items.sort()
       
    21   return [(k, v) for v, k in items]
    13 
    22 
    14 
    23 
    15 class Project(models.Model):
    24 class Project(models.Model):
    16   """Model class for NME funded projects.
    25   """Model class for NME funded projects.
    17   """
    26   """
    36       "CC": "Conversion of available content in various regional languages",
    45       "CC": "Conversion of available content in various regional languages",
    37       "DV": "Development of Vocational Educational modules and use of haptic devices for education & training",
    46       "DV": "Development of Vocational Educational modules and use of haptic devices for education & training",
    38       }
    47       }
    39 
    48 
    40   STATE_CHOICES = {
    49   STATE_CHOICES = {
       
    50       "AN": "Andaman & Nicobar", 
    41       "DN": "Dadra and Nagar Haveli", 
    51       "DN": "Dadra and Nagar Haveli", 
    42       "DL": "Delhi", 
    52       "DL": "Delhi", 
    43       "WB": "West Bengal", 
    53       "WB": "West Bengal", 
    44       "HR": "Haryana", 
    54       "HR": "Haryana", 
    45       "HP": "Himachal Pradesh", 
    55       "HP": "Himachal Pradesh", 
    55       "PB": "Punjab", 
    65       "PB": "Punjab", 
    56       "DD": "Daman & Diu", 
    66       "DD": "Daman & Diu", 
    57       "RJ": "Rajasthan", 
    67       "RJ": "Rajasthan", 
    58       "CH": "Chandigarh", 
    68       "CH": "Chandigarh", 
    59       "CG": "Chattisgarh", 
    69       "CG": "Chattisgarh", 
    60       "AN": "Andaman & Nicobar", 
       
    61       "AP": "Andhra Pradesh", 
    70       "AP": "Andhra Pradesh", 
    62       "AS": "Assam", 
    71       "AS": "Assam", 
    63       "AR": "Arunachal Pradesh", 
    72       "AR": "Arunachal Pradesh", 
    64       "GA": "Goa", 
    73       "GA": "Goa", 
    65       "GJ": "Gujarat", 
    74       "GJ": "Gujarat", 
   666       "MPDM": "Damoh"
   675       "MPDM": "Damoh"
   667       }
   676       }
   668 
   677 
   669   # Field containing the Line Item to which the project belongs to.
   678   # Field containing the Line Item to which the project belongs to.
   670   line_item = models.CharField(max_length=256,
   679   line_item = models.CharField(max_length=256,
   671                                choices=tuple(LINE_ITEM_CHOICES.items()))
   680                                choices=sort_dict(LINE_ITEM_CHOICES))
   672 
   681 
   673   # Field containing the name of the institution working on the
   682   # Field containing the name of the institution working on the
   674   # project.
   683   # project.
   675   institution = models.CharField(max_length=256)
   684   institution = models.CharField(max_length=256)
   676 
   685 
   677   # Field containing the state to which the institution belongs to.
   686   # Field containing the state to which the institution belongs to.
   678   state = models.CharField(max_length=256,
   687   state = models.CharField(
   679                            choices=tuple(STATE_CHOICES.items()))
   688       max_length=256,
       
   689       choices=sorted(STATE_CHOICES.items(), key=lambda (k,v): (v,k)))
   680 
   690 
   681   # Field containing the district to which the institution belongs
   691   # Field containing the district to which the institution belongs
   682   # to in the state of India.
   692   # to in the state of India.
   683   district = models.CharField(max_length=256,
   693   district = models.CharField(max_length=256,
   684                               choices=tuple(DISTRICT_CHOICES.items()))
   694                               choices=sort_dict(DISTRICT_CHOICES))
   685 
   695 
   686   mobile_num = models.CharField(max_length=20)
   696   mobile_num = models.CharField(max_length=20)
   687 
   697 
   688   fax_num = models.CharField(max_length=20, null=True, blank=True)
   698   fax_num = models.CharField(max_length=20, null=True, blank=True)
   689 
   699