Created
October 22, 2016 18:25
-
-
Save buddylindsey/95f50298e5e8ec0a164594019a9ab1c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from django.contrib.auth.models imort User | |
from django.shortcuts import render | |
from django.views.generic import ListView | |
# views.py | |
def index(request): | |
users = User.objects.all() | |
staff = User.objects.filter(is_staff=True) | |
context = {'users': users, 'staff': staff} | |
return render(request, 'home/index.html', context) | |
class DataMixin(object): | |
def get_context_data(self, **kwargs): | |
context = super() | |
context['staff'] = User.objects.filter(is_staff=True) | |
return context | |
class IndexView(DataMixin, ListView): | |
model = User | |
context_object_name = 'users' # object_list | |
template_name = 'home/index.html' | |
def get_context_data(self, **kwargs): | |
context = super() | |
context['superuser'] = User.objects.filter(is_superuser=True) | |
return context | |
class TwoView(DataMixin, ListView): | |
pass | |
# urls.py | |
from home.views import index, IndexView | |
urlpatterns = [ | |
url(r'^$', index, name='index'), | |
url(r'^$', IndexView.as_view(), name='index'), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment