Re: Inconsistencies/Bug in ModelForm

2008-08-29 Thread Steve Holden

Malcolm Tredinnick wrote:
> 
> On Thu, 2008-08-28 at 21:32 -0400, Steve Holden wrote:
>> lingrlongr wrote:
>>> Submitted ticket #8663 for the following:
>>>
>>> When a ModelForm? is used to display a form for a Model, the fields
>>> defined with a choices option insert a "---" value for the first
>>> option when the form is rendered. If you override a field and manually
>>> specify the choices for a Select widget, this "---" does not
>>> appear as the first choice.
>>>
>> I believe this is by design, to allow you the option of forcing the user
>> to select a specific value.
> 
> I understood the original poster's question to be about the difference
> between the auto-generated version and the version when he manually
> specified the field. My first reaction is that he's right and it should
> be the same in both cases (with the "" string), but I need to think
> about it a bit more.
>
So the existing admin framework only includes the "---" option if
the foreign key field can take null values? That would certainly make
sense, and would be a sensible extension to the manually-specified fields.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Inconsistencies/Bug in ModelForm

2008-08-28 Thread lingrlongr

Yes, Malcolm.  You understood it correctly.  I'll probably just add a
quick MY_CHOICES_2 tuple that has these "-" values until I see
what the plan is.

On Aug 28, 9:40 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-08-28 at 21:32 -0400, Steve Holden wrote:
> > lingrlongr wrote:
> > > Submitted ticket #8663 for the following:
>
> > > When a ModelForm? is used to display a form for a Model, the fields
> > > defined with a choices option insert a "---" value for the first
> > > option when the form is rendered. If you override a field and manually
> > > specify the choices for a Select widget, this "---" does not
> > > appear as the first choice.
>
> > I believe this is by design, to allow you the option of forcing the user
> > to select a specific value.
>
> I understood the original poster's question to be about the difference
> between the auto-generated version and the version when he manually
> specified the field. My first reaction is that he's right and it should
> be the same in both cases (with the "" string), but I need to think
> about it a bit more.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Inconsistencies/Bug in ModelForm

2008-08-28 Thread Malcolm Tredinnick


On Thu, 2008-08-28 at 21:32 -0400, Steve Holden wrote:
> lingrlongr wrote:
> > Submitted ticket #8663 for the following:
> > 
> > When a ModelForm? is used to display a form for a Model, the fields
> > defined with a choices option insert a "---" value for the first
> > option when the form is rendered. If you override a field and manually
> > specify the choices for a Select widget, this "---" does not
> > appear as the first choice.
> > 
> I believe this is by design, to allow you the option of forcing the user
> to select a specific value.

I understood the original poster's question to be about the difference
between the auto-generated version and the version when he manually
specified the field. My first reaction is that he's right and it should
be the same in both cases (with the "" string), but I need to think
about it a bit more.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Inconsistencies/Bug in ModelForm

2008-08-28 Thread Steve Holden

lingrlongr wrote:
> Submitted ticket #8663 for the following:
> 
> When a ModelForm? is used to display a form for a Model, the fields
> defined with a choices option insert a "---" value for the first
> option when the form is rendered. If you override a field and manually
> specify the choices for a Select widget, this "---" does not
> appear as the first choice.
> 
I believe this is by design, to allow you the option of forcing the user
to select a specific value.

> # models.py
> from django.db import models
> 
> MY_CHOICES = (
>   (0, 'Zero'),
>   (1, 'One'),
> )
> 
So wouldn't it be possible to put another choice, {"", "") at
the top of your list?

[...]
regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Inconsistencies/Bug in ModelForm

2008-08-28 Thread lingrlongr

Submitted ticket #8663 for the following:

When a ModelForm? is used to display a form for a Model, the fields
defined with a choices option insert a "---" value for the first
option when the form is rendered. If you override a field and manually
specify the choices for a Select widget, this "---" does not
appear as the first choice.

# models.py
from django.db import models

MY_CHOICES = (
  (0, 'Zero'),
  (1, 'One'),
)

class MyModel(models.Model):
  my_field = models.IntegerField(choices=MY_CHOICES)

# forms.py
from django import forms
from myapp.models import MyModel, MY_CHOICES

class MyModelForm(forms.ModelForm):
#my_field =
forms.IntegerField(widget=forms.Select(choices=MY_CHOICES))
class Meta:
model = MyModel

View the HTML for the form with my_field commented out:

>>> from myapp.forms import MyModelForm
>>> f = MyModelForm()
>>> print f
My field:
-
Zero
One


Now uncomment my_field in MyModelForm?:

>>> from myapp.forms import MyModelForm
>>> f = MyModelForm()
>>> print f
My field:
Zero
One


This value doesn't appear in the 2nd case: -

SVN-8643
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---