Skip to content

Instantly share code, notes, and snippets.

@MagnetonBora
Created October 30, 2016 22:11
Show Gist options
  • Save MagnetonBora/aa3159b132f1b09b936b7cedeb165443 to your computer and use it in GitHub Desktop.
Save MagnetonBora/aa3159b132f1b09b936b7cedeb165443 to your computer and use it in GitHub Desktop.
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