59👍
✅
Try l_magazines.values_list('id', flat=True)
. That returns a list of ids instead of a list of single id tuples.
2👍
One thing to note is that there is a difference in the behaviour of values/values_list from a list comprehension:
- values/values_list will yield the actual value stored in the field, that is, just the id (not the whole object)
- if the value is a foreign key, and you have the appropriate relations set up in your model, the list comprehension will give you the object referred to by the foreign key.
Choosing the wrong one will either result in unnecessary database hits, or unnecessary faffing around, depending on what you are trying to do.
- [Django]-What is the best AJAX library for Django?
- [Django]-How to repeat a "block" in a django template
- [Django]-Rendering a value as text instead of field inside a Django Form
Source:stackexchange.com