Skip to content

Instantly share code, notes, and snippets.

@blaix
Last active August 29, 2015 14:27
Show Gist options
  • Save blaix/614718ea3b4d130fb1a7 to your computer and use it in GitHub Desktop.
Save blaix/614718ea3b4d130fb1a7 to your computer and use it in GitHub Desktop.
nav = SiteNavigation(site)
nav.as_dict()
nav = SiteNavigation.for_site_id(site_id)
nav.as_dict()
class SiteNavigation(object):
def __init__(self, site):
"""Initialize a nav object with a site OR a site id"""
if not isinstance(site, Site):
site = Site.objects.get(site)
# perform init...
# vs...
class SiteNavigation(object):
def __init__(self, site):
"""Initialize a nav object with a site"""
# perform init...
@classmethod
def for_site_id(cls, site_id):
"""Initialize a nav object with a site id"""
site = Site.objects.get(site_id)
return cls(site)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment