Readability
L
yac2012 = Events.objects.get(slug='yac2012')! ! # is for current site type?! if settings.IS_INTERNAL_SITE:! is_for = (yac2012.is_published_for_internal ! and yac2012.is_published_for_external)! else:! is_for = yac2012.is_published_for_external!
Or
try
to
proxy
all
not
found
class EventManager(models.Manager):! def get_query_set(self):! return EventQuerySet(self.model, ! using=self._db)! ! def __getattr__(self, name):! if name.startswith('_'):! raise AttributeError(name)! else:! return getattr(self.get_query_set(), ! name)!
class EventTypeConditions(object):! @classmethod! def is_published(cls, prefix=None):! if prefix:! field = '%s__is_moderated' % prefix! else:! field = 'is_moderated'! ! return Q(is_moderated=True)! Field
name
with
prefix
class EventTypeConditions(object):! @classmethod! def is_published(cls, prefix=None):! if prefix:! field = '%s__is_moderated' % prefix! else:! field = 'is_moderated'! ! return Q(**{field: True})! Use
prefixed
field
Use
it
for
Event
class EventQuerySet(QuerySet):! ...! def filter_by_with_published_type(self):! return self.filter(! EventConditions.is_with_published_type()! )!
How
to
reuse
condiTons?
class
Event(models.Model):
...
@property
def
is_with_published_type(self):
return
EventConditions.is_with_published_type(model_instance=self)