cleanup in camps/
This commit is contained in:
parent
d20a964793
commit
aaa4df27db
|
@ -1,6 +1,4 @@
|
||||||
from django.conf import settings
|
|
||||||
from .models import Camp
|
from .models import Camp
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
|
|
||||||
def camp(request):
|
def camp(request):
|
||||||
|
|
|
@ -17,10 +17,8 @@ class CampViewMixin(object):
|
||||||
if queryset:
|
if queryset:
|
||||||
# check if we have a foreignkey to Camp, filter if so
|
# check if we have a foreignkey to Camp, filter if so
|
||||||
for field in queryset.model._meta.fields:
|
for field in queryset.model._meta.fields:
|
||||||
if field.name=="camp" and field.related_model._meta.label == "camps.Camp":
|
if field.name == "camp" and field.related_model._meta.label == "camps.Camp":
|
||||||
return queryset.filter(camp=self.camp)
|
return queryset.filter(camp=self.camp)
|
||||||
|
|
||||||
# Camp relation not found, or queryset is empty, return it unaltered
|
# Camp relation not found, or queryset is empty, return it unaltered
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@ from camps.models import Camp
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
|
||||||
def get_current_camp():
|
def get_current_camp():
|
||||||
try:
|
try:
|
||||||
return Camp.objects.get(camp__contains=timezone.now())
|
return Camp.objects.get(camp__contains=timezone.now())
|
||||||
except Camp.DoesNotExist:
|
except Camp.DoesNotExist:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class CampPropertyListFilter(admin.SimpleListFilter):
|
class CampPropertyListFilter(admin.SimpleListFilter):
|
||||||
"""
|
"""
|
||||||
SimpleListFilter to filter models by camp when camp is
|
SimpleListFilter to filter models by camp when camp is
|
||||||
|
@ -27,7 +29,6 @@ class CampPropertyListFilter(admin.SimpleListFilter):
|
||||||
for camp in unique_camps:
|
for camp in unique_camps:
|
||||||
yield (camp.slug, camp.title)
|
yield (camp.slug, camp.title)
|
||||||
|
|
||||||
|
|
||||||
def queryset(self, request, queryset):
|
def queryset(self, request, queryset):
|
||||||
# if self.value() is None return everything
|
# if self.value() is None return everything
|
||||||
if not self.value():
|
if not self.value():
|
||||||
|
@ -45,4 +46,3 @@ class CampPropertyListFilter(admin.SimpleListFilter):
|
||||||
if item.camp != camp:
|
if item.camp != camp:
|
||||||
queryset = queryset.exclude(pk=item.pk)
|
queryset = queryset.exclude(pk=item.pk)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue