Three step list comprehension for getting a set of categories existing in a group of objects
1 2 3 4 5 | ## helpers.py
def get_categories(category_model, item_set):
return [category for category in
category_model.objects.all() if category in
[item.category for item in item_set]]
|
More like this
- Browser-native date input field by kytta 1 month, 1 week ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 2 weeks ago
- FileField having auto upload_to path by junaidmgithub 2 months, 3 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months ago
Comments
Please login first before commenting.