I am new comer I struggle to save a record using admin page .
What extra ethod should I add to save ContestScore record.

Thanks.

class School(models.Model):
    school_name = models.CharField(max_length=30)
    school_city = models.CharField(max_length=30)
    coach_name = models.CharField(max_length=30)
    coach_fone = models.CharField(max_length=30)
    def  __unicode__(self):
        return u"%s - %s" % (self.school_name , self.school_city)
class ContestCourse(models.Model):
    CONTEST_LEVEL_CHOICES = (
    ('AV', 'Advantage'),
    ('BG', 'Beginer'),
    )

    course = models.CharField(max_length=30)
    course_name = models.CharField(max_length=30)
    level   =  models.CharField(max_length=2, choices=CONTEST_LEVEL_CHOICES)

    def  __unicode__(self):
        return u"%s - %s - %s" % (self.course , self.course_name, 
self.level)
 
class Student(models.Model):
    YEAR_IN_SCHOOL_CHOICES = (
    ('FR', 'Freshman'),
    ('SO', 'Sophomore'),
    ('JR', 'Junior'),
    ('SR', 'Senior'),
    )
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    grade     = models.CharField(max_length=2, 
choices=YEAR_IN_SCHOOL_CHOICES )
    schoolName =  models.ForeignKey(School)
    def  __unicode__(self):
        return u"%s - %s - %s" % (self.first_name , self.last_name, 
self.schoolName)


class ContestScore(models.Model):
    student =  models.ForeignKey(Student)
    courses  =  models.ManyToManyField(ContestCourse, verbose_name = "List 
of enroll courses" )
    score   =  models.FloatField()
    def  __unicode__(self):
        return u"%s - %s - %s - %s" % (self.student, self.course, 
self.score)
    def get_courses(self):
        return self.course.all()


admin.py
from django.contrib import admin
from contest.models import School
from contest.models import ContestCourse
from contest.models import Student
from contest.models import ContestScore
from contest.models import SchoolScore


class StudentAdmin(admin.ModelAdmin):
    list_display = ('first_name', 'last_name', 'grade', 'schoolName')  
    search_fields = ['last_name']
class ContestCourseAdmin(admin.ModelAdmin):
    list_display = ('course', 'course_name', 'level')  
    search_fields = ['course']
class SchoolAdmin(admin.ModelAdmin):
    list_display = ('school_name', 'school_city', 'coach_name', 
'coach_fone')  
    search_fields = ['school_name']
class ContestScoreAdmin(admin.ModelAdmin):
    list_display = ('student',  'score') 
    filter_horizontal = ('courses',)
    search_fields = ['student']



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to