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.