On Jun 18, 7:32 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Jun 18, 2008 at 4:53 PM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > I have the following model:
>
> > class Publishers(models.Model):
> > books = models.CharField(maxlength=1, choices=BOOKS)
>
> > BOOKS is a tuple:
> > BOOKS = ( ('1', 'Book A'), ('2', 'Book B') )
>
> > When I use form_for_instance(Publishers) to generate my template's
> > HTML based upon the Publisher model, the books field is a standard
> > <input> field rather than a <select> field.
>
> You aren't actually passing the Publishers model to form_for_instance, are
> you?
No. I'm passing in an object.
> That wouldn't work, you must be passing a Publishers model instance?
> Or are you using form_for_model?
>
I'm definitely using form_for_instance.
> Is this a bug in Django or am I missing something? If its th latter,
>
> > how can I get the desired effect using my model (I realize I could
> > create a custom form by coding a PublisherForm(forms.Form) -- trying
> > to stay DRY). From my perspective, it seems reasonable to expect the
> > HTML to be a <select> field when a "choices" attribute is added to the
> > model definition.
>
> I just tried this with a similar model and a recent trunk checkout and
> form_for_instance generated a select input for the field with choices, as
> you would expect, so something is going awry with what you are doing. I
> can't really guess what, though, based on the information you provided.
>
> What version of Django are you using?
I'm using Django 0.96.2. Which version did you use in your tests?
> Is there a reason you are using the
> older form_for_ methods instead of the newer (and preferred) ModelForms?
Can you elaborate on ModelForms? I'm relying solely on Django taking
my model and generating the HTML. From what I can tell, using
ModelForms would require me to repeat my code by creating a new class
that defines the structure of the form. Again, I'd prefer to stay DRY
(don't repeat yourself), but if Django won't play nice, I'll be left
with no choice.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---