create model on multiples schemas of database

17 views
Skip to first unread message

Moisés P. Sena

unread,
Mar 8, 2012, 6:10:36 PM3/8/12
to django...@googlegroups.com
Good night!

I need to create the "DDL" a model in several DB schemas, not only in the "public". The names of these schemas is "username" user logged.

I'm using PostgreSQL.

My model:

class Empresa(models.Model):
    '''
    classdocs
    '''
    cnpj = models.CharField(max_length=14, blank=False, null=False, unique=True,help_text=_("Required. 14 caracterss. Some numbers."))
    nome = models.CharField(max_length=255, blank=False, null=False)
    uf = models.ForeignKey(Uf, on_delete=models.PROTECT, blank=False, null=False)

    def __unicode__(self):
        return self.nome + " (" + self.cnpj + ")"

Thanks,

{}'

Python_Junkie

unread,
Mar 8, 2012, 9:55:39 PM3/8/12
to django...@googlegroups.com

That is a very interesting question.

I presume that you will not be doing this dynamically as a user logs on.

If that is the case, why don't you let django answer the question for you.

Create a database with the several different schemas and follow the instructions to let django create your model.


python manage.py inspectdb

Save this as a file by using standard Unix output redirection:

python manage.py inspectdb > models.py

I will try this myself to see if it works.
Reply all
Reply to author
Forward
0 new messages