mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 11:42:52 -06:00
Merge pull request #18901 from netbox-community/18872-JournalEntry-kind-required
Fixes #18872: JournalEntry `kind` is a required field
This commit is contained in:
commit
79b0c0f5d6
@ -14,7 +14,7 @@ from netbox.events import get_event_type_choices
|
|||||||
from netbox.forms import NetBoxModelForm
|
from netbox.forms import NetBoxModelForm
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from users.models import Group, User
|
from users.models import Group, User
|
||||||
from utilities.forms import add_blank_choice, get_field_value
|
from utilities.forms import get_field_value
|
||||||
from utilities.forms.fields import (
|
from utilities.forms.fields import (
|
||||||
CommentField, ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelChoiceField,
|
CommentField, ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelChoiceField,
|
||||||
DynamicModelMultipleChoiceField, JSONField, SlugField,
|
DynamicModelMultipleChoiceField, JSONField, SlugField,
|
||||||
@ -687,8 +687,7 @@ class ImageAttachmentForm(forms.ModelForm):
|
|||||||
class JournalEntryForm(NetBoxModelForm):
|
class JournalEntryForm(NetBoxModelForm):
|
||||||
kind = forms.ChoiceField(
|
kind = forms.ChoiceField(
|
||||||
label=_('Kind'),
|
label=_('Kind'),
|
||||||
choices=add_blank_choice(JournalEntryKindChoices),
|
choices=JournalEntryKindChoices
|
||||||
required=False
|
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
comments = CommentField()
|
||||||
|
|
||||||
|
25
netbox/extras/migrations/0123_journalentry_kind_default.py
Normal file
25
netbox/extras/migrations/0123_journalentry_kind_default.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from extras.choices import JournalEntryKindChoices
|
||||||
|
|
||||||
|
|
||||||
|
def set_kind_default(apps, schema_editor):
|
||||||
|
"""
|
||||||
|
Set kind to "info" on any entries with no kind assigned.
|
||||||
|
"""
|
||||||
|
JournalEntry = apps.get_model('extras', 'JournalEntry')
|
||||||
|
JournalEntry.objects.filter(kind='').update(kind=JournalEntryKindChoices.KIND_INFO)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('extras', '0122_charfield_null_choices'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
code=set_kind_default,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user