开发者

Django represent a many-to-many relationship as a CharField

开发者 https://www.devze.com 2022-12-30 08:37 出处:网络
I have a many-to-many field on one of my models and a ModelForm to represent it. I have it in a template but it shows up as a multiple s开发者_JS百科elect field. I need it to show up as a CharField so

I have a many-to-many field on one of my models and a ModelForm to represent it. I have it in a template but it shows up as a multiple s开发者_JS百科elect field. I need it to show up as a CharField so the user can put in comma-delimited values. Is there any way to do this?


Take a look at the code in django.contrib.admin.widgets.ForeignKeyRawIdWidget to see how the admin's raw_id_fields are implemented and try specifying it as the widgets= kwarg when you define that field on your form.

0

精彩评论

暂无评论...
验证码 换一张
取 消