On Tue, Dec 14, 2010 at 9:19 AM, john doe <thebiggestbangthe...@gmail.com>wrote:
> > > On Tue, Dec 14, 2010 at 5:16 AM, Jer-ming Lin <csie...@gmail.com> wrote: > >> Hi John, >> >> plz modify the Incident Model like Report Model, >> >> class Incident(models.Model): >> report = models.ForeignKey(Report) >> INCIDENT_CHOICES = ( >> ('SF', 'SegFault'), >> ('ML', 'Memory Leak'), >> ('MC', 'Memory Corruption'), >> ) >> type = models.CharField(max_length=2, choices=INCIDENT_CHOICES) >> >> Thanks again. I made the modification, yet I still get the error "Select a > valid choice. SF is not one of the available choices." ! > Could it be that when the form is accepting input it is getting confused > because the report has a type attribute and so does the incident. > Digging bit more, taking out the <div class="incidentType"> {{ new_incident_form.type.errors }} <label for="id_incidenttype">Type of Incident:</label> {{ new_incident_form.type }} </div> fixes the error. However removing the same for reportType while keeping the incidentType in place does not seem to help. This may indicate that the form is *not* getting confused because both report and incident have a type attribute. It seems there is an inherent problem with the incident type itself. Also if it helps, I am using the following to generate the html form return render_to_response('index.html', {'latest_incidentreporter_list': latest_incidentreporter_list, 'new_report_form':rform, 'new_incident_form':iform,'username':username}) so basically passing to form structures to the HTML page and then trying to show new_report_form.type and new_incident_form.type and that is where I run into issues. > BR >> Titan >> >> 2010/12/14 john doe <thebiggestbangthe...@gmail.com>: >> > >> > >> > On Mon, Dec 13, 2010 at 6:12 PM, Titan, Jer-ming Lin <csie...@gmail.com >> > >> > wrote: >> >> >> >> Hi John, >> >> >> >> each element in the choices is a two elements tuple. first one is >> >> the real data will be saved in the database and second one will >> >> present on the form. therefore, the max_length of 'type' field must be >> >> modified to fit the first element in the choices tuple. Plz see the >> >> following code, i change the first element and the type field's >> >> max_length. >> >> >> >> REPORT_CHOICES = ( >> >> ('BR', 'Bug Report'), >> >> ('UN', 'Unknown Problem'), >> >> ) >> >> type = models.CharField(max_length=2, choices=REPORT_CHOICES) >> > >> > Hi Titan, thank you. Yes that was something I could correct. >> > >> > However the problem of the error which says "Select a valid choice. SF: >> Seg >> > Fault is not one of the available choices." >> > still remains. Any insight here? >> > >> >> >> >> ps: you can also google some pages which use the IntegerField to >> >> save the choices. >> >> >> >> BR >> >> Titan >> >> >> >> On Dec 14, 9:04 am, john doe <thebiggestbangthe...@gmail.com> wrote: >> >> > Dear all, >> >> > I am making a small Django app for a bug tracking system to >> get >> >> > my >> >> > head round this awesome framework. I am facing a problem wherein when >> >> > accepting input via a form generated by models. The classes are >> listed >> >> > below >> >> > (not in its entirety). >> >> > >> >> > [code] >> >> > class Report(models.Model): >> >> > #type = models.CharField(max_length=200) >> >> > REPORT_CHOICES = ( >> >> > ('BR: Bug Report', 'Bug Report'), >> >> > ('UN: Unknown Problem', 'Unknown Problem'), >> >> > ) >> >> > type = models.CharField(max_length=1, choices=REPORT_CHOICES) >> >> > submitter = models.CharField(max_length=200, default='Anonymous') >> >> > ... >> >> > ... >> >> > class Incident(models.Model): >> >> > report = models.ForeignKey(Report) >> >> > INCIDENT_CHOICES = ( >> >> > ('SF: Seg Fault', 'SegFault'), >> >> > ('ML: Memory Leak', 'Memory Leak'), >> >> > ('MC: Memory Corruption', 'Memory Corruption'), >> >> > ) >> >> > type = models.CharField(max_length=1, choices=INCIDENT_CHOICES) >> >> > #description of the incident >> >> > description = models.CharField(max_length=20000) >> >> > ... >> >> > ... >> >> > [/code] >> >> > >> >> > I have generated a form wherein a user can enter a report, and >> multiple >> >> > incidents related to the report. When I use the function to accept >> the >> >> > input, not actually processing anything I get "Select a valid choice. >> >> > SF: >> >> > Seg Fault is not one of the available choices." . >> >> > >> >> > The HTML page code looks like below: >> >> > [code] >> >> > <h2>Submit a report</h2> >> >> > {% if new_report_form %} >> >> > <ul> >> >> > <form action="/submit_new_report/" method="post"> >> >> > {{ new_report_form.non_field_errors }} >> >> > <div class="reportType"> >> >> > {{ new_report_form.type.errors }} >> >> > <label for="id_reporttype">Type of Report:</label> >> >> > {{ new_report_form.type }} >> >> > </div> >> >> > <div class="incidentType"> >> >> > {{ new_incident_form.type.errors }} >> >> > <label for="id_incidenttype">Type of >> Incident:</label> >> >> > {{ new_incident_form.type }} >> >> > </div> >> >> > ... >> >> > ... >> >> > [/code] >> >> > >> >> > The form.is_valid() call is basically saying that there's a problem >> with >> >> > validating the form input because the choice selected for the >> >> > incident-type >> >> > is not valid. However, in the model description, the choices are >> clearly >> >> > valid and in the form I have different identifiers too. Can someone >> >> > please >> >> > provide some advice as to why this might be happening. >> >> > >> >> > Thanks in advance. >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups >> >> "Django users" group. >> >> To post to this group, send email to django-us...@googlegroups.com. >> >> To unsubscribe from this group, send email to >> >> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> >> . >> >> For more options, visit this group at >> >> http://groups.google.com/group/django-users?hl=en. >> >> >> > >> > >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.