mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 21:48:16 -06:00
14438 script model
This commit is contained in:
parent
1034ee7380
commit
4cb3b63f79
@ -4,6 +4,18 @@ from django.db import migrations, models
|
|||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
def update_scripts(apps, schema_editor):
|
||||||
|
ScriptModule = apps.get_model('extras', 'ScriptModule')
|
||||||
|
Script = apps.get_model('extras', 'Script')
|
||||||
|
|
||||||
|
for module in ScriptModule.objects.all():
|
||||||
|
for script, cls in module.get_module_scripts:
|
||||||
|
Script.objects.create(
|
||||||
|
name=script,
|
||||||
|
script_module=module,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@ -19,7 +31,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='script',
|
model_name='script',
|
||||||
name='script_module',
|
name='module',
|
||||||
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, related_name='scripts', to='extras.scriptmodule'),
|
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, related_name='scripts', to='extras.scriptmodule'),
|
||||||
preserve_default=False,
|
preserve_default=False,
|
||||||
),
|
),
|
||||||
@ -32,4 +44,8 @@ class Migration(migrations.Migration):
|
|||||||
name='script',
|
name='script',
|
||||||
options={'ordering': ('name', 'pk')},
|
options={'ordering': ('name', 'pk')},
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=update_scripts,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -26,7 +26,7 @@ class Script(EventRulesMixin, models.Model):
|
|||||||
verbose_name=_('name'),
|
verbose_name=_('name'),
|
||||||
max_length=79,
|
max_length=79,
|
||||||
)
|
)
|
||||||
script_module = models.ForeignKey(
|
module = models.ForeignKey(
|
||||||
to='extras.ScriptModule',
|
to='extras.ScriptModule',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name='scripts'
|
related_name='scripts'
|
||||||
@ -59,9 +59,8 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.python_name
|
return self.python_name
|
||||||
|
|
||||||
'''
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def scripts(self):
|
def get_module_scripts(self):
|
||||||
|
|
||||||
def _get_name(cls):
|
def _get_name(cls):
|
||||||
# For child objects in submodules use the full import path w/o the root module as the name
|
# For child objects in submodules use the full import path w/o the root module as the name
|
||||||
@ -83,7 +82,6 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
|||||||
scripts[_get_name(cls)] = cls
|
scripts[_get_name(cls)] = cls
|
||||||
|
|
||||||
return scripts
|
return scripts
|
||||||
'''
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.file_root = ManagedFileRootPathChoices.SCRIPTS
|
self.file_root = ManagedFileRootPathChoices.SCRIPTS
|
||||||
|
Loading…
Reference in New Issue
Block a user