On Tue, Mar 17, 2009 at 5:13 PM, Juan Hernandez <vladjani...@gmail.com>wrote:

> Hi there:
>
> I have this model for example
>
> class Categories(models.Model):
>     name = models.CharField(max_length=30)
>
> which holds this data on the DB
>
> +----+--------------+
> | id | name         |
> +----+--------------+
> |  1 | Musica       |
> |  2 | Programacion |
> |  3 | Libros       |
> |  4 | Politica     |
> |  5 | Humor        |
> |  6 | Basura       |
> |  7 | Varios       |
>
> How come now, everytime I create a form with either this
>
> class PostForm(ModelForm):
>     post = forms.CharField(widget=forms.Textarea({'rows': '20', 'cols':
> '75'}))
>     class Meta:
>         model = Post
>         exclude = 'id'
>
> or this
>
>
> class CategoriesForm(forms.Form):
>     categories = forms.ModelChoiceField(queryset=Categories.objects.all())
>
>
> It shows this HTML output on the select field?
>
> <tr><th><label for="id_categories">Categories:</label></th>
>
> <td><select name="categories" id="id_categories">
>
> <option value="" selected="selected">---------</option>
>
> <option value="1">Categories object</option>
> <option value="2">Categories object</option>
>
> <option value="3">Categories object</option>
> <option value="4">Categories object</option>
>
> <option value="5">Categories object</option>
>
> <option value="6">Categories object</option>
> <option value="7">Categories object</option>
>
> </select></td></tr>
>
> What is going on here? Am I missing something now? I've been doing this for
> a long time and I guess I forgot something
>
> >
>
By default it uses the __unicode__ method to show the output.  So either
define __unicode__ on the Post class, or do what's described here:
http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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 
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