On Tue, Dec 14, 2010 at 9:17 PM, john doe <thebiggestbangthe...@gmail.com>wrote:

>
>
> On Tue, Dec 14, 2010 at 2:15 PM, Titan, Jer-ming Lin <csie...@gmail.com>wrote:
>
>> maybe your view function gets wrong. post it! XDD
>>
> looking at the request.POST itself I see:
[code]
<QueryDict: {u'submission_date': [u'2010-12-15 07:02:26', u'2010-12-15
07:02:26'], u'description': [u'efff'], u'most_recent_followup_date':
[u'9999-01-01 00:00:00', u'9999-01-01 00:00:00'], u'harmscore': [u'1'],
u'acknowledgement_date': [u'9999-01-01 00:00:00', u'9999-01-01 00:00:00'],
u'submitter': [u'Anonymous'], u'type': [u'BR', u'SF'], u'resolution_date':
[u'9999-01-01 00:00:00', u'9999-01-01 00:00:00']}>
[/code]

which shows the type choices for report and incident as BR and SF

Report type can be BR and UN, is this because when django sees incident type
as SF it says that it is not a valid choice?
Any advice will be great.


>
>> Thanks Titan :-). The code I use for my view function is below
> [code]
> #validate user
> def check_user_login(request):
>   username = request.POST['username']
>   password = request.POST['password']
>   #bad practice, think about salting passwords
>   user = authenticate(username=username, password=password)
>   if user is not None:
>       if user.is_active:
>           #prepare list of reports to be shown
>           latest_incidentreporter_list =
> Report.objects.all().filter(submitter__iexact=username).order_by('-submission_date')
>           #throw in a form so that user can enter a new report
>           rform = ReportForm()
>           report = Report()
>           report=initializeobject(report,'r')
>           rform = ReportForm(instance=report)
>           iform = IncidentForm()
>           incident = Incident()
>           incident=initializeobject(incident,'i')
>           iform = IncidentForm(instance=incident)
>
>           return render_to_response('index.html',
> {'latest_incidentreporter_list': latest_incidentreporter_list,
> 'new_report_form':rform, 'new_incident_form':iform,'username':username})
>       else:
>           return render_to_response('userlogin.html', {'User': user})
>           # Return a 'disabled account' error message
>   else:
>       return render_to_response('userlogin.html')
>       # Return an 'invalid login' error message.
>
> #initialize report or instance
> def initializeobject(object, level):
>   #not sure if I have to initialize the type of object here
>   object.submission_date=datetime.datetime.now()
>   object.acknowledgement_date=datetime.datetime(datetime.MAXYEAR, 1, 1)
>   object.most_recent_followup_date=datetime.datetime(datetime.MAXYEAR, 1,
> 1)
>   object.resolution_date=datetime.datetime(datetime.MAXYEAR, 1, 1)
>   object.resolved=False
>   return object
> [/code]
>
> and in my models.py I have
> [code]
> class ReportForm(ModelForm):
>   class Meta:
>     model=Report
>
> class IncidentForm(ModelForm):
>   class Meta:
>     model=Incident
> [/code]
>
>> BR
>> Titan
>>
>> On Dec 15, 1:50 am, john doe <thebiggestbangthe...@gmail.com> wrote:
>> > 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>
>> <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@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<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.

Reply via email to