Exemplo n.º 1
0
    def handle(self, *args, **options):

        import codecs
        fp = codecs.open('sch2.txt', encoding='utf-8')

        for line in fp:
            parts = [x.strip() for x in line.split('\t')]

            grade_raw = parts[0]
            gender_raw = parts[5]
            gender = 'W'
            if gender_raw == '0':
                gender = 'M'
            pdata = dict(
                first_name=parts[2],
                last_name=parts[1],
                gender=gender,
                #birthday
            )

            grade = Grade.objects.get(name=grade_raw)
            print pdata['first_name'], pdata['last_name']
            print grade.name

            pupil = Pupil(**pdata)
            pupil.save()
            participation = GradeParticipant(pupil=pupil, grade=grade)
            participation.save()
Exemplo n.º 2
0
 def save_m2m():
    old_save_m2m()
    # This is where we actually link the pizza with toppings
    instance.grade_set.clear()
    for grade in self.cleaned_data['grades']:
        p = GradeParticipant(pupil=instance, grade=grade)
        p.save()                
Exemplo n.º 3
0
 def save_m2m():
    old_save_m2m()
    # This is where we actually link the pizza with toppings
    instance.pupils.clear()
    for pupil in self.cleaned_data['participants']:
        p = GradeParticipant(pupil=pupil, grade=instance)
        p.save()                
Exemplo n.º 4
0
 def save_m2m():
     old_save_m2m()
     # This is where we actually link the pizza with toppings
     instance.grade_set.clear()
     for grade in self.cleaned_data['grades']:
         p = GradeParticipant(pupil=instance, grade=grade)
         p.save()
Exemplo n.º 5
0
 def save_m2m():
     old_save_m2m()
     # This is where we actually link the pizza with toppings
     instance.pupils.clear()
     for pupil in self.cleaned_data['participants']:
         p = GradeParticipant(pupil=pupil, grade=instance)
         p.save()
Exemplo n.º 6
0
    def handle(self, *args, **options):

        import codecs
        fp = codecs.open('sch2.txt', encoding='utf-8')
        
        for line in fp:
            parts = [x.strip() for x in line.split('\t')]
            
            grade_raw=parts[0]
            gender_raw=parts[5]
            gender='W'
            if gender_raw=='0':
                gender='M'
            pdata = dict(
                first_name=parts[2],
                last_name=parts[1],
                gender=gender,
                #birthday
            )
            
            grade = Grade.objects.get(name=grade_raw)
            print pdata['first_name'], pdata['last_name']
            print grade.name
            
            
            
            pupil = Pupil(**pdata)
            pupil.save()
            participation = GradeParticipant(
                pupil=pupil,
                grade=grade
            )
            participation.save()