bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 423 forks source link

Populate tenant table after creation #467

Closed JakeMana closed 7 years ago

JakeMana commented 7 years ago

Hi, This is not as much an issue as my question about populating tenant tables with predefined data. What Im trying to achieve is, every time new account is created and with that new tables in new schema, I want those table populate with demo data. Is there any hook I can use, because I think pre/post_save signal wont work.

Viatrak commented 7 years ago

One option might be to write a Django migration in a Django app that's only installed in the tenant apps list. See: https://docs.djangoproject.com/en/1.10/howto/writing-migrations/

bernardopires commented 7 years ago

For some reason this is not documented (did it get deleted by accident?), but there's a hook called post_schema_sync which is called after the tenant has been migrated.

JakeMana commented 7 years ago

@bernardopires I could find that hook, but I'll definitely try it. Thanks!

JeansReal commented 6 years ago

Is there a way to create initial data from a migration?

I plan to seed the initial PublicTenant from a migration.

This runs but the object does not get created operations = [ migrations.RunPython(create_public_tenant, reverse_code=migrations.RunPython.noop) ]