Class Based Views VS DRY principle

33 views
Skip to first unread message

Artem Bernatskyy

unread,
Nov 4, 2016, 3:56:56 PM11/4/16
to Django users
Hello.

Suppose i have a code (http://pastebin.com/6rUqKD8q)

And in CBV there are a bunch of methods with EXACTLY the same code.

My question is - can i somehow inherit them from ONE place, in order to be able to edit them from one place ?

Thanks for replies.

Matthew Pava

unread,
Nov 4, 2016, 4:00:25 PM11/4/16
to django...@googlegroups.com

Just create another CBV that factors out all of the similarities between all of the other CBVs.  Then inherit from your new CBV to create your more specific ones.  Basically instead of inheriting from the Django CBVs, you will inherit from your own.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/51ca427d-732a-4223-bf27-59fa7b346295%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Artem Bernatskyy

unread,
Nov 4, 2016, 8:56:36 PM11/4/16
to Django users
TNX
Reply all
Reply to author
Forward
0 new messages