Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2012-01-09 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
-+-
 Reporter:  Simon Litchfield |Owner:  nobody
|   Status:  closed
 Type:  Uncategorized|  Version:  SVN
Component:  Documentation|   Resolution:  fixed
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  1
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-
Changes (by guettli):

 * cc: hv@… (removed)
 * ui_ux:   => 0
 * type:   => Uncategorized
 * severity:   => Normal
 * easy:   => 0


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2010-07-07 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
--+-
  Reporter:  Simon Litchfield   | Owner:  
nobody
Status:  new  | Milestone:  
  
 Component:  Documentation|   Version:  SVN 
  
Resolution:   |  Keywords:  
  
 Stage:  Accepted | Has_patch:  0   
  
Needs_docs:  1|   Needs_tests:  0   
  
Needs_better_patch:  0|  
--+-
Comment (by zimnyx):

 Patch should be aware of "to_field_name" param for ModelChoiceField, which
 is pk by default, but can be overriden by this param.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2010-03-07 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
--+-
  Reporter:  Simon Litchfield   | Owner:  
nobody
Status:  new  | Milestone:  
  
 Component:  Documentation|   Version:  SVN 
  
Resolution:   |  Keywords:  
  
 Stage:  Accepted | Has_patch:  0   
  
Needs_docs:  1|   Needs_tests:  0   
  
Needs_better_patch:  0|  
--+-
Changes (by timo):

  * needs_better_patch:  1 => 0
  * has_patch:  1 => 0
  * needs_tests:  1 => 0
  * needs_docs:  0 => 1

Comment:

 removing has_patch since the patch isn't a doc patch

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2008-10-22 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
--+-
  Reporter:  Simon Litchfield <[EMAIL PROTECTED]>  | Owner:  
nobody  
Status:  new  | Milestone:  
post-1.0
 Component:  Documentation|   Version:  SVN 

Resolution:   |  Keywords:  

 Stage:  Accepted | Has_patch:  1   

Needs_docs:  0|   Needs_tests:  1   

Needs_better_patch:  1|  
--+-
Changes (by guettli):

 * cc: [EMAIL PROTECTED] (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2008-10-16 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
--+-
  Reporter:  Simon Litchfield <[EMAIL PROTECTED]>  | Owner:  
nobody  
Status:  new  | Milestone:  
post-1.0
 Component:  Documentation|   Version:  SVN 

Resolution:   |  Keywords:  

 Stage:  Accepted | Has_patch:  1   

Needs_docs:  0|   Needs_tests:  1   

Needs_better_patch:  1|  
--+-
Comment (by bradcater):

 I don't think that this is going to be solved by documentation. I've had
 the "ValueError: invalid literal for int() with base 10" error on a multi-
 form page (not a multi-page form, in my case :) ), also, and I managed to
 get rid of it by changing db/models/forms/__init__.py (line ~356) to:
 {{{
 def get_db_prep_value(self, value):
 if value is None:
 return None
 try:
 return int(value)
 except:
 return int(value.pk)
 }}}
 I then had a problem with the Select widget comparing each c in "choices"
 to the contents of the set "selected_choices." The real issue was that c
 could be any one of several types, but you have to compare to the db
 values (primary keys, in my case) for equality (list membership). I got
 around that by subclassing the Select widget with something like this:
 {{{
 class GoodSelect(Select):
 """ Fix the ForeignKey bug.
 It's a known issue: http://code.djangoproject.com/ticket/7287 """
 def render_option(self, option_value, option_label, selected_choices):
 selected_html = (option_value in selected_choices) and u'
 selected="selected"' or ''
 return u'%s' % (
 escape(option_value), selected_html,
 conditional_escape(force_unicode(option_label)))

 def render_options(self, choices, selected_choices):
 # Normalize to strings.
 selected_choices = set([self.__pk_or_unicode(v) for v in
 selected_choices])
 output = []
 for option_value, option_label in chain(self.choices, choices):
 if isinstance(option_label, (list, tuple)):
 output.append(u'' %
 escape(force_unicode(option_value)))
 for option in option_label:
 output.append(self.render_option(*option))
 output.append(u'')
 else:
 output.append(self.render_option(option_value,
 option_label, selected_choices))
 return u'\n'.join(output)

 def __pk_or_unicode(self,obj):
 # If the object is already unicode, try to convert it to an int
 first.
 # If that doesn't work, then just return the force_unicode bit.
 # This is *probably* safe because when we try to put stuff in the
 db, we convert it anyway.
 if isinstance(obj,unicode):
 try:
 return int(obj)
 except:
 return force_unicode(obj)
 elif isinstance(obj,str):
 return force_unicode(obj)
 else:
 return obj.pk
 }}}
 I'm still exploring to come up with a better fix, but for now, this is
 functioning well for me.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #7287: Newforms' initial values as models, for ModelChoiceField etc

2008-09-18 Thread Django
#7287: Newforms' initial values as models, for ModelChoiceField etc
--+-
  Reporter:  Simon Litchfield <[EMAIL PROTECTED]>  | Owner:  
nobody  
Status:  new  | Milestone:  
post-1.0
 Component:  Documentation|   Version:  SVN 

Resolution:   |  Keywords:  

 Stage:  Accepted | Has_patch:  1   

Needs_docs:  0|   Needs_tests:  1   

Needs_better_patch:  1|  
--+-
Comment (by mrmachine):

 Also bitten by this, and took a while to track down the real cause. I'm
 storing cleaned data for a multi-page form in the session, and using that
 as `initial` data when users go back to a previous page. When returning to
 a previous page, ModelChoiceField's were suddenly using the cleaned model
 instance's `__unicode__` as the form widget's value, which raised
 `ValueError: invalid literal for int() with base 10` (see #8974). It makes
 sense that I should be able to pass back in the cleaned_data that I'm
 getting out of a form.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---