question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MultipleModelField should accept other types as iterable not just list

See original GitHub issue

It seems to me that MultipleModelField should accept any iterable such as a Django queryset, tuple, and set – not just a list.

I commonly have forms using forms.ModelMultipleChoiceField which in the cleaned_data returns a queryset. I am having to wrap list around the data from a forms.ModelMultipleChoiceField to coerce it into a list for the library.

Views.py:

DuplicateMergeService.execute({
    'duplicates':list(form.cleaned_data['duplicates']),
    'by': request.user
})

Seems like MultipleModelField should accept any iterable and not be restricted to list

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jackton1commented, Dec 10, 2019

Personally switching from using the MultipleModelField -> forms.ModelMultipleChoiceField for queryset.

my_models = forms.ModelMultipleChoiceField(queryset=MyModel.objects.all())

OR

recipients = forms.MultipleChoiceField(choices=[...])
0reactions
peterfarrellcommented, Dec 11, 2019

@jackton1 Thanks for the feedback and mentioning the allow_unsaved. I guess @c17r already committed a change so I won’t submit the PR I started last night. Glad to see this improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Field Data Types - Iterable Support Center
This article explains different values and data types for fields and events in ... If the field is not already cast, CSV imports...
Read more >
Making Python Integers Iterable - Arpit Bhayani
In Python, Integers are not iterables but we can make them iterable by ... the range type which helps us iterate through all...
Read more >
Iterables - Python Like You Mean It
An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a...
Read more >
Iterable collections - Dart programming language
Iterables are a kind of collection. A collection can be empty, or it can contain many elements. Depending on the purpose, collections can...
Read more >
Why is Java's Iterator not an Iterable? - Stack Overflow
An iterator is stateful. The idea is that if you call Iterable.iterator() twice you'll get independent iterators - for most iterables, anyway.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found