int3
int3

Reputation: 13201

Is there a Django ModelField that allows for multiple choices, aside from ManyToMany?

I'd like the user to be able to make multiple selections via the admin interface, and store the result as a list of comma-separated values. A select-multiple or a list of checkboxes would be great. However, I don't need the items in this list of values to refer to any models in particular... I just want a text list of items, plain and simple, hence I don't think the ManyToManyField is the one I'm looking for. What's the quickest way to do this in Django?

Upvotes: 12

Views: 15162

Answers (3)

Mick T
Mick T

Reputation: 387

Django-multiselectfield does what you require:

https://github.com/goinnn/django-multiselectfield

It's inspired by the snippet that Alexander mentioned.

Upvotes: 4

jkatzer
jkatzer

Reputation: 724

This django snippet accomplishes the same with a much smaller footprint.

http://djangosnippets.org/snippets/23/

make sure to update those imports since they are pre version 1.0

Upvotes: 0

Alexander Torstling
Alexander Torstling

Reputation: 18898

There is a django snippet which does just this: multiple choice model field. It says:

Usually you want to store multiple choices as a manytomany link to another table. Sometimes however it is useful to store them in the model itself. This field implements a model field and an accompanying formfield to store multiple choices as a comma-separated list of values, using the normal CHOICES attribute.

Upvotes: 11

Related Questions