X
X
Xaip2020-01-24 00:49:16
Django
Xaip, 2020-01-24 00:49:16

Dynamic table name change via _meta model attribute?

I did not find an attribute or model method that could dynamically set the table name for the model. Therefore, I decided to change through the hidden _meta attribute of the model. I change the table name dynamically, because there is a partitioning on a certain field
. Are there any side effects?

class Test(models.Model):
    number = models.IntegerField("Партицируемый атрибут", default=0)
    
    class Meta:
        db_table = 'test'
        
Test._meta.db_table = "test_1"
Test.objects.all()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-01-24
@bacon

Why change the table name? Partitioning should resolve this itself at the database level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question