Created
April 14, 2017 22:54
-
-
Save ragne/0d8831b55dd0d7e0092d724659091441 to your computer and use it in GitHub Desktop.
This file contains 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
def auto_props(cls): | |
gm2m_fields = map( lambda x: x[0], | |
filter(lambda x: isinstance(x[1], GM2MField), cls._meta._forward_fields_map.items())) | |
for field in gm2m_fields: | |
for model in getattr(cls, field).get_related_models(include_auto=True): | |
model_lower = model.lower() | |
if not hasattr(cls, model_lower): | |
setattr(cls, model_lower, property(lambda self: | |
map(lambda x: x.gm2m_tgt, | |
self.settings.filter(Model='.'.join([cls._meta.app_label, model]))))) | |
return cls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment