Last active
August 29, 2015 14:27
-
-
Save blaix/614718ea3b4d130fb1a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nav = SiteNavigation(site) | |
nav.as_dict() | |
nav = SiteNavigation.for_site_id(site_id) | |
nav.as_dict() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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