1👍
The way you’ve done it is totally fine. I’ve found it to be useful to separate my templates from my model by explicitly providing the information needed by the template in the view, which is essentially what you’ve done. It’s a little bit weird to not be returning an actual queryset from a method called get_queryset
, but I’ve also come to the conclusion based on criticisms like this that class-based views as they are currently implemented in Django should be considered a means to an end, as opposed to a dogmatic way of organizing your view code. The abstraction simply isn’t as clean as say, the Django ORM.
If you really wanted something a little slicker, you could try using the values
method to narrow your queryset, with an annotation to add in the subscription count. But there’s probably not much point.
0👍
It depends on what you’re trying to do with the array ‘users’. Someone editing the template can only style and display the data in a certain way. The get_queryset function can provide the data for the template.
- [Answer]-Display models that includes certain values (basic search)
- [Answer]-Django bootstrap/middleware/enter-exit