down votefavorite
<https://stackoverflow.com/questions/45081886/django-multi-table-on-same-model#>
I have huge table that needed to be sliced into some smaller table, ex:
campaign_01, campaign_02, ... While using django queryset with different
table name for same model, what I only know to set table name on a model
is: Model._meta.db_table = 'tableXXX'
However this method doesn't work in single shell/request. (only work for
first time, but not for the next) -> maybe because it still on same
instance? After the second time we tried to set _meta.db_table =
'tableYYY', it will occur an error "django.db.utils.ProgrammingError:
missing FROM-clause entry for table "tableXXX""
I also have tried some suggestion I read for this problem answer like:
class ListingManager(models.Manager):
def get_custom_obj(self, table_name):
self.model._meta.db_table = table_name
return self
class ObjectName(models.Model):
objects = ListingManager()
Try to create an Object manager to get new object, but it not work, it
still throw same error as before (on the second time setting _meta.db_table)
The only way to make it work if we want to set multiple times for
_meta.db_table is we need to exit() the shell first, then re-enter the
shell mode (which means for loop is not gonna work).
I know it can be achieved with raw query 'Insert into tableXXX values ()',
but any method to do it using django queryset? Thanks~
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/fba2ca9e-874f-45b8-b285-3c116fefb036%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.