def get_meta_title(self, **kwargs): from bluebottle.utils.model_dispatcher import get_project_model if isinstance(self, get_project_model()): return u'{name_project} | {country}'.format( name_project=self.title, country=self.country.name if self.country else '') return self.title
def to_native(self, value): """ Serialize followed objects to a simple representation """ if isinstance(value, get_project_model()): # For now, simply return only slug of the project. Alternatively, we could consider returning a nested objects return value.slug if value: return value.id
from django.db.models.aggregates import Max from django.http import Http404 from django.utils.translation import ugettext_lazy as _ from bluebottle.bluebottle_drf2.views import RetrieveUpdateDeleteAPIView, ListCreateAPIView from rest_framework import permissions, exceptions from bluebottle.utils.serializer_dispatcher import get_serializer_class from bluebottle.utils.model_dispatcher import get_project_model, get_fundraiser_model from tenant_extras.drf_permissions import TenantConditionalOpenClose PROJECT_MODEL = get_project_model() FUNDRAISER_MODEL = get_fundraiser_model() FUNDRAISER_SERIALIZER = get_serializer_class('FUNDRAISERS_FUNDRAISER_MODEL', 'default') class FundraiserListView(ListCreateAPIView): model = FUNDRAISER_MODEL serializer_class = FUNDRAISER_SERIALIZER permission_classes = (TenantConditionalOpenClose, permissions.IsAuthenticatedOrReadOnly,) paginate_by = 10 paginate_by_param = 'page_size' # because we overwrite get_queryset, this is ignored # TODO: Write cleaner code that takes this argument into account. # ordering = ('-created', ) def get_queryset(self, queryset=None): queryset = super(FundraiserListView, self).get_queryset(queryset)
def project_count(self): """ Return the number of projects a user started / is owner of """ return get_project_model().objects.filter(owner=self).count()