I'm using MultiSelectField to store a topic/topic's of conversation
My model looks somewhat like this:
class Conversation(models.Model):
(...)
note= models.CharField(max_lenght=250)
TOPIC_CHOICES =(
(1,"about cats"),
(2, "about dogs"),
(3, "about fluffy little things"),
)
topic =MultiSelectField(choices=TOPIC_CHOICES)
I'm using ListView and filtering by GET parameters inside get_queryset:
form extract:
class SearchForm(Form):
(...)
topic = MultipleChoiceField(choices=Conversation.TOPIC_CHOICES, required=False)
get_queryset extract :
(...)
if form.cleaned_data['topic']:
search_params.update({'topic__in': form.cleaned_data['topic']})
(...)
return qs.filter(**search_params)
This method worked fine for single value choice fields.
But in this case if I for ex. select in form "about cats" I got only objects that topic is set to cats only("about cats" and nothing else -single value).
What I want is all objects in which one of topic values is 1-"about cats". This mean if some object have topic=1,3(cats and fluffy things) it should appear too
Second scenario: I select "about cats" and "about dogs" in form - I want all objects that have cats as one of the topic's and all objects that have a dogs as one of the topic's Right now when I select more than one option for ex. cats and dogs I get all that have only cats and all that got only dogs as a topic
Is there any other field lookup string instead of __in that will achieve that?
If not what is most hassle free way to do that?
logger.debug(form.cleaned_data[topic])prints out : DEBUG [u'1', u'2'] so it's a list PS Look at my latest edit - I made a false statement in the beginning and corrected it now.