ModelForm changing default field for ForeingKey

602 views
Skip to first unread message

Jonas Geiregat

unread,
Jan 21, 2011, 6:58:36 PM1/21/11
to django...@googlegroups.com
Hello,

I'm creating a subset of a ModelForm.

class FavArtistForm(ModelForm):
class Meta:
model = FavArtist
fields = ('artist',)
widgets = {
'artist': CharField(),
}


The field artist is of the type ForeignKey which is by default represented by django as a select tag.
I'd rather have the user enter their own value, so I tried to change it to the CharField field.
This doesn't work.

I'm receiving the following error: AttributeError: 'CharField' object has no attribute 'is_hidden'


Is changing the default representation of a ForeignKey field not allowed in django or am I missing something ?


Regards,

Jonas.

Daniel Roseman

unread,
Jan 22, 2011, 5:34:16 AM1/22/11
to django...@googlegroups.com
The problem has nothing to do with foreign keys. It's simply that you're trying to change a widget, but you have used a Field type instead of a widget type. Use this instead:

        widgets = { 
            'artist': TextInput(),
        }   
--
DR.

Ymir Camilo Acosta Rodriguez

unread,
Jun 3, 2014, 9:49:27 PM6/3/14
to django...@googlegroups.com
Thank you Daniel, it works for me. ;)
Reply all
Reply to author
Forward
0 new messages