I would like to use the default django permissions in my project. Base is that there are 3 types of users, a super user and two other distinct type of users. I'm working towards a system with groups and permissions. So add the two different types of users to their groups on creation.
The whole project is TDD (pure for learning TDD) and that means I want to test the permission system all over the project. But testing in Django happens with creating a new db on every test run.
Thats where my problem is. I would like on creation of the db (maybe better on launching server) to create my groups and set permissions on the groups. I'm thinking about south, but that means adding al lot of migration files on every push to the 'master' branch.
Is there a way to run a command on 'runserver' (or something similar) that checks if there are groups, and update/create the permissions on those groups?
You can provide initial data in a fixtures directory (fixtures/initial_data.json) and they will be loaded in your test created db.
Initial data doc
Related
I've read in some articles that it's best practice NOT to add DB users via flyway db migration. It's not very clear to me as to why it's not a good practice. One thing we thought about is that it might be good to have the user configuration automatically documented in the code.
One article mentioned that you might want different user configuration for different environments. But you could also control that in flyway.
When/why would you not want to add DB users using flyway DB migration?
If I'm deploying a new user for the database that will be common across all environments, I would absolutely make the creation of that user a part of the Flyway deployment scripts. It fundamentally makes sense. "Version 43.43 is where we added the login snarglegrass to the app."
On the other hand, if you are working on setting up different environments with varying permissions, I probably will make that part of the flow control commands in pre/post deployment scripts instead of using Flyway. The reason for this is because it can be challenging to write the scripts in such a way as they're repeatable and safe. You could still do it that way though.
To elaborate, we have one server we have setup to run django. Issue is that we need to establish "public" test server that our end-users can test, before we push the changes to the production.
Now, normally we would have production.domain.com and testing.domain.com and run them separately. However, due to conditions outside our control we only have access to one domain. We will call it program.domain.com for now.
Is there a way to setup two entirely separete django intances (AKA we do not want admin of production version to be able to access demo data, and vice versa) in such a way we have program.domain.com/production and program.domain.com/development enviroments?
I tried to look over Djangos "sites"-framework but as far as I can see, all it can do is separate the domains, not paths, and it has both "sites" able to access same data.
However, as I stated, we want to keep our testing data and our production data separate. Yet, we want to give our end-user testers access to version they can tinker around, keeping separation of production, public test and local development(runserver command) versions.
I would say you use the /production or /development path to select which database to use. You can read more about multitenancy from here https://books.agiliq.com/projects/django-multi-tenant/en/latest/
I try to set up two projects,
The first is a management project - it involves auth_user, sessions, writing to db.
The second project is a "serve content" project, it only read from the db, uses no sessions, users..
It rely on db data created in the first project, but does not change it.
The second project urls will be accessed very frequently. That's why I want to seperate the projects, with different subdomaons, and two apache instances, giving the second one more "power" (processes in wsgi deamon conf).
So what should I share between the projects? Same settings? SECRET_KEY? Models?
I assume I should also remove session app.
Can I set django db to be in read only mode?
I have few questions about this plugin.
1- what does it do?
Is it for exchanging databases between teams or changing their schema or creating tables based on models or something else?
2- if it is not meant to create tables based on models where can I find a script that does this?
3-can it work under windows?
thanks
The Migrations plugin allows versioning of your db changes. Much like is available in other PHP frameworks and Rails.
You essentially start with your original schema and create the initial migration. Each time you make a change you generate a 'diff' that gets stored in the filesystem.
When you run a migration, the database is updated with the changes you made. Think deployment to a staging or production server where you want the structure to be the same as your code is moved from environment to environment.
We are starting to look at this plugin so we can automate our deployments, as the DB changes are done manually right now.
I am about to start a django project, where I need a base deployment, lets say just for admins initially. Later admins can add instances of my main public site.
Now, one instance will, obviously be separated by dynamic sub-domains. I need to capture sub-domains from requests, and compute accordingly. It has its own base templates, static files, etc (easiest part). It would have set of feature apps (common for all instances, but not the data in their models). And I am thinking of using Django1.2's multiple database support, and try to get one db per instance (* adding dynamically :( , if that is feasible, It will include dynamic db/model creations*). Or I can go for adding an instance foreign_key in all feature apps models, to separate them instant-wise.
If my instances were known prior to deployment, I would have used multiple database support easily by capturing the sub-domains and diverting my ORM calls to concerned db. But, that is not the case. Those has to be dynamic (added as need arises).
Now before I give it a try, to get solution/rid of delusions about it, I would want experts of SO to think about it. I would appreciate the suggestions, insights and of-course criticism.
I can make it community wiki, if suggested. Thanks guys.
Shouldn't you just run a separate Django instance in a each their Apache VirtuaHost? Then, you can have a Django settings file for each instance and they can each point at their proper database. This also simplifies your code because you don't need to map subdomain names to databases inside your views. As a real bonus, your code gets re-usable because it doesn't depend on your complex setup.
Ususally you can do instances of your app with the sites framework.