Created
April 19, 2014 10:20
-
-
Save jarshwah/11080199 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 _get_model(self): | |
DynamicClass = cache.get('DynamicModel_' + self.table_name) | |
if DynamicClass is None: | |
# get the custom columns required for this table.. | |
attrs = dict((c.column_name, models.CharField(max_length=100, blank=True, null=True)) for c in self.custom_fields.all()) | |
class Meta: | |
db_table = self.table_name | |
app_label = self._meta.app_label | |
managed = False | |
unique_together = (('chain_id', 'chain_n', 'group_id'),) | |
attrs['Meta'] = Meta | |
attrs['__module__'] = ThisApp.__module__ | |
# create then cache it | |
DynamicClass = type(str(self.table_name), (CallbackRecord,), attrs) | |
cache.set('DynamicModel_' + self.table_name, DynamicClass, 60*20) | |
return DynamicClass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment