2018-10-26 23:42:53 +00:00
|
|
|
from django.shortcuts import render
|
2018-12-14 01:58:59 +00:00
|
|
|
from django.views.generic import View
|
|
|
|
from GeoffreyApp.models import *
|
|
|
|
from django.views import generic
|
2018-12-15 21:12:17 +00:00
|
|
|
from django.db.models import Q
|
2018-10-26 23:42:53 +00:00
|
|
|
# Create your views here.
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class Home(View):
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
|
|
|
base_num = Base.objects.count()
|
|
|
|
shop_num = Shop.objects.count()
|
|
|
|
player_num = Player.objects.count()
|
|
|
|
item_num = ItemListing.objects.count()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"num_players": player_num,
|
|
|
|
"num_bases": base_num,
|
|
|
|
"num_shops": shop_num,
|
|
|
|
"num_items": item_num,
|
|
|
|
}
|
|
|
|
|
|
|
|
return render(request, 'GeoffreyApp/home.html', context=context)
|
|
|
|
|
|
|
|
|
|
|
|
class PlayerList(generic.ListView):
|
|
|
|
model = Player
|
|
|
|
|
|
|
|
|
|
|
|
class ShopList(generic.ListView):
|
|
|
|
model = Shop
|
|
|
|
|
2018-12-15 21:12:17 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
qs = Shop.objects.all()
|
|
|
|
|
|
|
|
search = self.request.GET.get('q')
|
|
|
|
if search:
|
|
|
|
qs = qs.filter(Q(name__icontains=search) | Q(owner__name__icontains=search))
|
|
|
|
|
|
|
|
return qs
|
|
|
|
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class BaseList(generic.ListView):
|
|
|
|
model = Base
|
|
|
|
|
|
|
|
class ItemListingList(generic.ListView):
|
|
|
|
model = ItemListing
|
|
|
|
|