I have an application which is made of several apps. The thing is that by default, only 1 app is installed. I called it 'base'. This base
app enables the user to manage users, groups (but that isn't the point here) AND should enable users to install other apps on runtime (that is the point).
I created an Application
model.
In my UI, I list all the applications with a button install
aside of it.
The idea is, when I click on this button, to :
- Mark the application as installed
- Add it to the App registry on runtime (that's the blocking point)
- Apply the migration for this app
So here are some samples of code :
My Application model :
from django.apps import apps
from django.conf import settings
from django.core import management
from django.db import models
class Application(models.Model):
class Meta:
db_table = 'base_application'
name = models.CharField(max_length=255, unique=True)
verbose_name = models.CharField(max_length=255)
version = models.CharField(max_length=255, null=True, blank=True)
summary = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
is_installed = models.BooleanField(default=False)
is_uninstallable = models.BooleanField()
My install() method would look like :
I know there are mistakes in it and that is the point of this question. I don't understand how the App Registry actually works.
Note that I must provide the reverse of it too (uninstall)
def install(self):
self.is_installed = True
self.save()
settings.INSTALLED_APPS.append(self.name)
apps.populate(settings.INSTALLED_APPS)
self.migrate()
My migrate() method :
def migrate(self):
management.call_command('makemigrations', self.name, interactive=False)
management.call_command('migrate', self.name, interactive=False)
The usual error I get is No installed app with label ....
Thanks in advance for your help. I can precise if needed.