mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Convert DataSource to a primary model
This commit is contained in:
parent
a6e2c4c583
commit
ee378cd0aa
@ -31,7 +31,7 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
||||
class Meta:
|
||||
model = DataSource
|
||||
fields = [
|
||||
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'parameters',
|
||||
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'comments', 'parameters',
|
||||
'ignore_rules', 'created', 'last_updated', 'file_count',
|
||||
]
|
||||
|
||||
|
@ -3,7 +3,7 @@ from django.utils.translation import gettext as _
|
||||
|
||||
import django_filters
|
||||
|
||||
from netbox.filtersets import ChangeLoggedModelFilterSet
|
||||
from netbox.filtersets import NetBoxModelFilterSet
|
||||
from .models import *
|
||||
|
||||
__all__ = (
|
||||
@ -12,7 +12,7 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
class DataSourceFilterSet(ChangeLoggedModelFilterSet):
|
||||
class DataSourceFilterSet(NetBoxModelFilterSet):
|
||||
|
||||
class Meta:
|
||||
model = DataSource
|
||||
@ -23,7 +23,8 @@ class DataSourceFilterSet(ChangeLoggedModelFilterSet):
|
||||
return queryset
|
||||
return queryset.filter(
|
||||
Q(name__icontains=value) |
|
||||
Q(description__icontains=value)
|
||||
Q(description__icontains=value) |
|
||||
Q(comments__icontains=value)
|
||||
)
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ from core.choices import DataSourceTypeChoices
|
||||
from core.models import *
|
||||
from netbox.forms import NetBoxModelBulkEditForm
|
||||
from utilities.forms import (
|
||||
add_blank_choice, BulkEditNullBooleanSelect, StaticSelect,
|
||||
add_blank_choice, BulkEditNullBooleanSelect, CommentField, SmallTextarea, StaticSelect,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
@ -29,6 +29,10 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
comments = CommentField(
|
||||
widget=SmallTextarea,
|
||||
label=_('Comments')
|
||||
)
|
||||
parameters = forms.JSONField(
|
||||
required=False
|
||||
)
|
||||
@ -39,8 +43,8 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = DataSource
|
||||
fieldsets = (
|
||||
(None, ('type', 'enabled', 'description', 'parameters', 'ignore_rules')),
|
||||
(None, ('type', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules')),
|
||||
)
|
||||
nullable_fields = (
|
||||
'description', 'description', 'parameters', 'parameters', 'ignore_rules',
|
||||
'description', 'description', 'parameters', 'comments', 'parameters', 'ignore_rules',
|
||||
)
|
||||
|
@ -11,5 +11,5 @@ class DataSourceImportForm(NetBoxModelImportForm):
|
||||
class Meta:
|
||||
model = DataSource
|
||||
fields = (
|
||||
'name', 'type', 'url', 'enabled', 'description', 'parameters', 'ignore_rules',
|
||||
'name', 'type', 'url', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules',
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ class DataSourceForm(NetBoxModelForm):
|
||||
class Meta:
|
||||
model = DataSource
|
||||
fields = [
|
||||
'name', 'type', 'url', 'enabled', 'description', 'ignore_rules',
|
||||
'name', 'type', 'url', 'enabled', 'description', 'comments', 'ignore_rules',
|
||||
]
|
||||
widgets = {
|
||||
'type': StaticSelect(
|
||||
|
@ -0,0 +1,26 @@
|
||||
# Generated by Django 4.1.5 on 2023-02-01 20:04
|
||||
|
||||
from django.db import migrations, models
|
||||
import taggit.managers
|
||||
import utilities.json
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0084_staging'),
|
||||
('core', '0002_remove_datasource_git_branch_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='datasource',
|
||||
name='custom_field_data',
|
||||
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datasource',
|
||||
name='tags',
|
||||
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
|
||||
),
|
||||
]
|
18
netbox/core/migrations/0004_datasource_comments.py
Normal file
18
netbox/core/migrations/0004_datasource_comments.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.5 on 2023-02-01 20:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0003_datasource_custom_field_data_datasource_tags'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='datasource',
|
||||
name='comments',
|
||||
field=models.TextField(blank=True),
|
||||
),
|
||||
]
|
@ -14,7 +14,7 @@ from django.utils.module_loading import import_string
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from extras.models import JobResult
|
||||
from netbox.models import ChangeLoggedModel
|
||||
from netbox.models import PrimaryModel
|
||||
from netbox.registry import registry
|
||||
from utilities.files import sha256_hash
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
@ -29,7 +29,7 @@ __all__ = (
|
||||
logger = logging.getLogger('netbox.core.data')
|
||||
|
||||
|
||||
class DataSource(ChangeLoggedModel):
|
||||
class DataSource(PrimaryModel):
|
||||
"""
|
||||
A remote source, such as a git repository, from which DataFiles are synchronized.
|
||||
"""
|
||||
@ -55,10 +55,6 @@ class DataSource(ChangeLoggedModel):
|
||||
enabled = models.BooleanField(
|
||||
default=True
|
||||
)
|
||||
description = models.CharField(
|
||||
max_length=200,
|
||||
blank=True
|
||||
)
|
||||
ignore_rules = models.TextField(
|
||||
blank=True,
|
||||
help_text=_("Patterns (one per line) matching files to ignore when syncing")
|
||||
|
@ -9,6 +9,7 @@ class DataSourceIndex(SearchIndex):
|
||||
('name', 100),
|
||||
('url', 300),
|
||||
('description', 500),
|
||||
('comments', 5000),
|
||||
)
|
||||
|
||||
|
||||
|
@ -16,6 +16,9 @@ class DataSourceTable(NetBoxTable):
|
||||
type = columns.ChoiceFieldColumn()
|
||||
status = columns.ChoiceFieldColumn()
|
||||
enabled = columns.BooleanColumn()
|
||||
tags = columns.TagColumn(
|
||||
url_name='core:datasource_list'
|
||||
)
|
||||
file_count = tables.Column(
|
||||
verbose_name='Files'
|
||||
)
|
||||
@ -23,7 +26,7 @@ class DataSourceTable(NetBoxTable):
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = DataSource
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'parameters', 'created',
|
||||
'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'comments', 'parameters', 'created',
|
||||
'last_updated', 'file_count',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count')
|
||||
|
@ -70,6 +70,8 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'inc/panels/tags.html' %}
|
||||
{% include 'inc/panels/comments.html' %}
|
||||
{% plugin_left_page object %}
|
||||
</div>
|
||||
<div class="col col-md-6">
|
||||
|
Loading…
Reference in New Issue
Block a user