greetings. I am using the admin interface to show data retrieved by a collector process and put in a different table for each source; each source is identified by "cliente", "num1" and "num2". At run time django scans the db for tables with proper names and builds classes modeled from an abstract template. The code will make everything clearer:
class Telefonate(models.Model): id = models.BigIntegerField(unique=True, primary_key=True) # some other fields here class Meta: abstract = True def telefonate_factory(cliente, num1, num2): if type(num1) != type(''): raise TypeError('parameter client1 must be of type %s insted of %s' % (type(''), type(cliente))) if type(num2) != type(''): raise TypeError('parameter client2 must be of type %s insted of %s' % (type(''), type(cliente))) if type(cliente) != type(''): raise TypeError('parameter num must be of type %s insted of %s' % (type(''), type(num))) cliente = str(cliente).lower() nome = 'Telefonate%s%s%s' % (cliente.capitalize(), num1, num2) ret = type(nome, (Telefonate,), {'__module__': Telefonate.__dict__['__module__']}) ret._meta.db_table = 'telefonate_%s_%s_%s' % (cliente, num1, num2) ret._meta.verbose_name = 'telefonate di %s-%s-%s' % (cliente.capitalize().replace('_', ' '), num1, num2) ret._meta.verbose_name_plural = 'telefonate di %s-%s-%s' % (cliente.capitalize().replace('_', ' '), num1, num2) return ret from django.db import connection, transaction, connections extractor = re.compile(r'^telefonate_([a-z_]+?)_(\d+)_(\d+)$') for db in settings.DATABASES.keys(): conn = connections[db] cursor = conn.cursor() cursor.execute('SHOW TABLES LIKE "telefonate_%%"') for t in cursor.fetchall(): vals = extractor.search(str(t[0])).groups() globals()['Telefonate' + vals[0].capitalize() + vals[1] + vals[2]] = telefonate_factory(vals[0], vals[1], vals[2]) Then my problem: class Blocks is an abstract class, being used as class telefonate. Each class Blocks/cliente/num1/num2 has a OneToOneField related to the corresponding class Telefonate/cliente/num1/num2: how to write class Blocks? in particular the OneToOneField? class Blocchi(models.Model): call = models.OneToOneField(Telefonate, unique=True, primary_key=True) block_start = models.IntegerField() block_end = models.IntegerField() class Meta: db_table = u'blocchi' verbose_name_plural = 'blocchi' abstract = True ordering = ['call'] -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.