我有一个由几个应用程序组成的应用程序。事实是,默认情况下,仅安装1个应用程序。我称它为“基础”。此base
应用程序使用户可以管理用户,组(但这不是重点),并且应该使用户能够在运行时安装其他应用程序。 / p>
我创建了一个Application
模型。
在我的用户界面中,我列出了所有应用程序,旁边还有一个按钮install
。
我的想法是,当我单击此按钮时:
这是一些代码示例:
我的应用程序模型:
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()
我的install()方法如下:
我知道其中存在错误,这就是这个问题的重点。我不了解App Registry的实际工作原理。
请注意,我也必须提供相反的信息(卸载)
def install(self):
self.is_installed = True
self.save()
settings.INSTALLED_APPS.append(self.name)
apps.populate(settings.INSTALLED_APPS)
self.migrate()
我的migration()方法:
def migrate(self):
management.call_command('makemigrations', self.name, interactive=False)
management.call_command('migrate', self.name, interactive=False)
我经常遇到的错误是No installed app with label ....
在此先感谢您的帮助。我可以根据需要精确调整。