[Mixins] - Order of the Mixins - Is it a bug?

65 views
Skip to first unread message

Vinnicyus Gracindo

unread,
Jun 15, 2018, 1:36:47 PM6/15/18
to django-d...@googlegroups.com
Hi. I beat my brains out trying to find out why my cbv was not working with LoginRequiredMixin.
I found the order of the mixins in the inheritance:
It works: class UserListView(LoginRequiredMixin, ListView) 
Doesn't work:  class UserListView(ListView, LoginRequiredMixin

Is that how it was designed? or is it a bug?

Thanks.

Markus Holtermann

unread,
Jun 15, 2018, 1:50:15 PM6/15/18
to django-d...@googlegroups.com
Hi Vinnicyus,

this is by design.

There's an interesting talk by Ana Balica on Mixins in Django: https://www.youtube.com/watch?v=rMn2wC0PuXw

/Markus
>--
>You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
>To post to this group, send email to django-d...@googlegroups.com.
>Visit this group at https://groups.google.com/group/django-developers.
>To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMjWKi8LdUEwBnTfPX43x%3D5DWUam74dy-eVBof5%2BJmGOr1SLYQ%40mail.gmail.com.
>For more options, visit https://groups.google.com/d/optout.

jackotonye

unread,
Jun 15, 2018, 4:52:22 PM6/15/18
to Django developers (Contributions to Django itself)
By design mixins are applied in the order they are inherited.

`class A: pass`
`class B: pass`

```
class C(A, B):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # This will call A.__init__() then B.__init__()


```

Vinnicyus Gracindo

unread,
Jun 16, 2018, 10:31:09 AM6/16/18
to django-d...@googlegroups.com
I understood now. Thank you so much. 

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
Reply all
Reply to author
Forward
0 new messages