Giter Site home page Giter Site logo

Comments (3)

bernardopires avatar bernardopires commented on June 18, 2024

Hi humbled,

I have a project that does exactly the same thing you want. When a tenant is created, I load some basic data like groups and permissions. loaddata itself doesn't have any direct relation with south, so it shouldn't be a problem to use it on tables that don't have migrations. When are you calling call_command("loaddata", "default_cities.json")? In my case I overrode the save method on my tenant model and called it at the end of the method. This ensures it will always get called. Hope this helps!

When I get home I'll take a look to see exactly how I've done it and I'll post the code here.

Cheers,
Bernardo

from django-tenant-schemas.

bernardopires avatar bernardopires commented on June 18, 2024

Alright, here's how my save method looks like

def save(self, *args, **kwargs):
    is_new = self.pk is None
    super(LawFirm, self).save(*args, **kwargs)

    if is_new:
        call_command('load_schema_data', 'groups.json', schema_name=self.schema_name, verbosity=0,)

You will probably need a loaddata command that actually accepts a schema name (else it might sync it to public), so I created a new command called load_schema_data (as seen above). Here's how this file looks like:

from tenant_schemas.management.commands import BaseTenantCommand


class Command(BaseTenantCommand):
    COMMAND_NAME = 'loaddata'

Hope this helps! Feel free to write here any problems you have.

Cheers

from django-tenant-schemas.

humbled avatar humbled commented on June 18, 2024

That's great, thanks @bernardopires! For those following at home, the second snippet above is saved as load_schema_data.py in myapp.management.commands. The latter took me a little figuring out as haven't made any custom django commands before. Your comment on #24 was helpful too.

Thanks again
Brad

from django-tenant-schemas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.