Need help with a modelChoiceField

0 views
Skip to first unread message

Bobby Roberts

unread,
Aug 7, 2009, 10:28:58 AM8/7/09
to Django users
ok here's my form:

class ParseFileChoiceField (forms.ModelChoiceField):
def label_from_instance (self,obj):
return obj.ProcessFile

class FrmParser (forms.Form):
parsefile = ParseFileChoiceField(queryset=Upload.objects.filter
(numrecs__exact=0),empty_label='Choose',required=True,widget=forms.Select
())


The result is this:

<select name="parsefile" id="id_parsefile">
<option value="" selected="selected">Choose</option>
<option value="3">Upload object</option>
</select>

I need the visible text to be the ProcessFile value rather than Upload
Object


any ideas?

Bobby Roberts

unread,
Aug 7, 2009, 2:33:11 PM8/7/09
to Django users
hi. does anyone have any ideas why this is not working... we are
using django 0.96 on this particular server.

Daniel Roseman

unread,
Aug 7, 2009, 2:57:19 PM8/7/09
to Django users
On Aug 7, 7:33 pm, Bobby Roberts <tchend...@gmail.com> wrote:
> hi.  does anyone have any ideas why this is not working... we are
> using django 0.96 on this particular server.

label_from_instance was added after that version. For now the only
thing you can do is to define __unicode__ on the Upload model, and
that will provide the value that is displayed.
--
DR.

Karen Tracey

unread,
Aug 7, 2009, 3:07:48 PM8/7/09
to django...@googlegroups.com

No __unicode__ in 0.96.  Probably __str__.

Karen

Bobby Roberts

unread,
Aug 7, 2009, 3:08:56 PM8/7/09
to Django users
> label_from_instance was added after that version. For now the only
> thing you can do is to define __unicode__ on the Upload model, and
> that will provide the value that is displayed.
> --
> DR.

worked like a charm Daniel... thanks again!
Reply all
Reply to author
Forward
0 new messages