Create and save records through ManyToManyField selection.
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.
and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.
Django Version:1.5.2Exception Type:NoReverseMatchException Value: Reverse for 'gradingstudent' with arguments '()' and keyword arguments '{u'student_id': None, u'school_id': 1}' not found. Exception Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 I am new to Django. I got this error and struggle to find a solution for it but no luck. Please help! View.py def grading_student(request, school_id=1, student_id=1): urls.py url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', views.grading_student, name='gradingstudent'), from template : if I use : a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> Enter Student Score Enter Student Score {{form.instance.id}} Enter Student Score http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.
No this not add form and I verify it. I also use pk but it does not work either. On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote: > > On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote: > >> Django Version:1.5.2Exception Type:NoReverseMatchException Value: >> >> Reverse for 'gradingstudent' with arguments '()' and keyword arguments >> '{u'student_id': None, u'school_id': 1}' not found. >> >> Exception >> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py >> >> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 >> I am new to Django. I got this error and struggle to find a solution for >> it but no luck. Please help! >> >> View.py def grading_student(request, school_id=1, student_id=1): >> urls.py >> url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', >> views.grading_student, name='gradingstudent'), >> >> from template : >> if I use : >> a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> >> Enter Student Score > It work. But when I try to replace 1 by form.instance.id i got error >> about. >> >> a href="{% url 'contest:gradingstudent' school_id=1 student_id= >> form.instance.id %}"> Enter Student Score > >> if I change to this url >> >> a href="{% url 'contest:gradingstudent' school_id=1 student_id %}"> {{ >> form.instance.id}} Enter Student Score > I got other error >> >> Don't mix *args and **kwargs in call to reverse()! >> >> What is the properway to do? >> >> >> Thanks, >> >> > The error is telling you that form.instance.id is None. Presumably this > is because you are on an add form, and the instance hasn't been created yet > - in which case you can't link to its contest page. > -- > DR. > -- 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.
Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.
I found it. Inside {%%} shoud use variable. Inthis case is form.instance.id instead of {{form.instance.id}} On Saturday, September 21, 2013 5:06:07 PM UTC-5, Trung Nguyen wrote: > > No this not add form and I verify it. I also use pk but it does not work > either. > > On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote: >> >> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote: >> >>> Django Version:1.5.2Exception Type:NoReverseMatchException Value: >>> >>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments >>> '{u'student_id': None, u'school_id': 1}' not found. >>> >>> Exception >>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py >>> >>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 >>> I am new to Django. I got this error and struggle to find a solution >>> for it but no luck. Please help! >>> >>> View.py def grading_student(request, school_id=1, student_id=1): >>> urls.py >>> url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', >>> views.grading_student, name='gradingstudent'), >>> >>> from template : >>> if I use : >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> >>> Enter Student Score >> It work. But when I try to replace 1 by form.instance.id i got error >>> about. >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id= >>> form.instance.id %}"> Enter Student Score >> >>> if I change to this url >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id %}"> {{ >>> form.instance.id}} Enter Student Score >> I got other error >>> >>> Don't mix *args and **kwargs in call to reverse()! >>> >>> What is the properway to do? >>> >>> >>> Thanks, >>> >>> >> The error is telling you that form.instance.id is None. Presumably this >> is because you are on an add form, and the instance hasn't been created yet >> - in which case you can't link to its contest page. >> -- >> DR. >> > -- 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.
Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.
On Friday, September 20, 2013 10:44:33 PM UTC-5, Trung Nguyen wrote: > > Django Version:1.5.2Exception Type:NoReverseMatchException Value: > > Reverse for 'gradingstudent' with arguments '()' and keyword arguments > '{u'student_id': None, u'school_id': 1}' not found. > > Exception > Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py > > in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 > I am new to Django. I got this error and struggle to find a solution for > it but no luck. Please help! > > View.py def grading_student(request, school_id=1, student_id=1): > urls.py > url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', > views.grading_student, name='gradingstudent'), > > from template : > if I use : > a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> > Enter Student Score It work. But when I try to replace 1 by form.instance.id i got error > about. > > a href="{% url 'contest:gradingstudent' school_id=1 student_id= > form.instance.id %}"> Enter Student Score > if I change to this url > > a href="{% url 'contest:gradingstudent' school_id=1 student_id %}"> {{ > form.instance.id}} Enter Student Score I got other error > > Don't mix *args and **kwargs in call to reverse()! > > What is the properway to do? > > > Thanks, > > -- 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.
Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.
If I pass in a variable to the template like return render_to_response("grading_school_form.html", RequestContext(request, { "formset": formset, "pk":school_id, "spk":1})) then in the template {% for form in formset %} {{ spk }} {{ form.first_name }} {{ form.last_name}} {{ form.schoolName }} Enter Student Score {% endfor %} It does work. But i need to dynamicly assign the form ID to the student id like student_id= form.instanse.pk then it complain like everse for 'gradingstudent' with arguments '()' and keyword arguments '{u'student_id': None, u'school_id': 1}' not found. when i try to assign spk = form.instanse.pk like {% with form.instance.id.to_int as spk%} {{ spk }} {{ form.first_name }} {{ form.last_name}} {{ form.schoolName }} Enter Student Score {% endwith %} On Saturday, September 21, 2013 5:06:07 PM UTC-5, Trung Nguyen wrote: > > No this not add form and I verify it. I also use pk but it does not work > either. > > On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote: >> >> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote: >> >>> Django Version:1.5.2Exception Type:NoReverseMatchException Value: >>> >>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments >>> '{u'student_id': None, u'school_id': 1}' not found. >>> >>> Exception >>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py >>> >>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 >>> I am new to Django. I got this error and struggle to find a solution >>> for it but no luck. Please help! >>> >>> View.py def grading_student(request, school_id=1, student_id=1): >>> urls.py >>> url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', >>> views.grading_student, name='gradingstudent'), >>> >>> from template : >>> if I use : >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> >>> Enter Student Score >> It work. But when I try to replace 1 by form.instance.id i got error >>> about. >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id= >>> form.instance.id %}"> Enter Student Score >> >>> if I change to this url >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id %}"> {{ >>> form.instance.id}} Enter Student Score >> I got other error >>> >>> Don't mix *args and **kwargs in call to reverse()! >>> >>> What is the properway to do? >>> >>> >>> Thanks, >>> >>> >> The error is telling you that form.instance.id is None. Presumably this >> is because you are on an add form, and the instance hasn't been created yet >> - in which case you can't link to its contest page. >> -- >> DR. >> > -- 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.
Formset from inlineformset_factory for the model who has multiple foreign key?
I got this Error when I hit the submit from 'ManagementForm data is missing or has been tampered with'] class Course(models.Model): course = models.CharField(max_length=30) course_name = models.CharField(max_length=30) class Student(models.Model): 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 class ContestScore(models.Model): student = models.ForeignKey(Student) course = models.ForeignKey(Course) score = models.FloatField() def __unicode__(self): return u"%s - %s - %s" % (self.student, self.course, self.score) In the view def grading_student(request, school_id=1, student_id=1): student = Student.objects.get(pk=student_id) ContestInlineFormSet = inlineformset_factory(Student, Score, extra =0) if request.method == "POST": formset = ContestInlineFormSet(request.POST, instance=student) # Do something. Should generally end with a redirect. For example: return HttpResponseRedirect(reverse ('contest:gradings', args=(school_id),)) else: formset = ContestInlineFormSet(instance=student) return render_to_response("grading_student_form.html", RequestContext(request, { "formset": formset})) the formset = ContestInlineFormSet(instance=student) render the page good. But when I click submit to post data the formset = ContestInlineFormSet(request.POST, instance=student) give me the error ManagementForm data is missing or has been tampered with'] Please help! What I am doing wrong here? If the model has only one foreign key it work fine. Thanks. -- 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.