Created
October 30, 2016 22:11
-
-
Save MagnetonBora/aa3159b132f1b09b936b7cedeb165443 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
from django.db import models | |
from model_utils.managers import InheritanceManager | |
class Product(models.Model): | |
name = models.CharField(max_length=50) | |
description = models.CharField(max_length=200, null=True, blank=True) | |
timestamp = models.DateTimeField(null=True, blank=True) | |
objects = InheritanceManager() | |
def __str__(self): | |
return 'Product {}'.format(self.name) | |
def create_ext_product(): | |
attrs = { | |
'__module__': 'web.models' | |
} | |
attrs.update({ | |
'str_property_{}'.format(i): models.CharField( | |
max_length=50, null=True, blank=True | |
) for i in range(1, 16) | |
}) | |
attrs.update({ | |
'str_property_{}#enabled'.format(i): models.BooleanField(default=True) for i in range(1, 16) | |
}) | |
attrs.update({ | |
'int_property_{}'.format(i): models.IntegerField( | |
null=True, blank=True | |
) for i in range(1, 16) | |
}) | |
attrs.update({ | |
'int_property_{}#enabled'.format(i): models.BooleanField(default=True) for i in range(1, 16) | |
}) | |
return type('ExtProduct', (Product,), attrs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment