Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Vladimir
noc
Commits
6c671d75
Commit
6c671d75
authored
May 20, 2022
by
Andrey Vertiprahov
Committed by
Dmitry Volodin
May 20, 2022
Browse files
#1831
Add iter_related_changed method for getting related model.
parent
cbaa0cc6
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/change/decorator.py
View file @
6c671d75
# ----------------------------------------------------------------------
# @change decorator and worker
# ----------------------------------------------------------------------
# Copyright (C) 2007-202
1
The NOC Project
# Copyright (C) 2007-202
2
The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
...
...
@@ -79,6 +79,15 @@ def _on_document_delete(sender, document, *args, **kwargs):
id
=
str
(
document
.
id
),
fields
=
None
,
)
if
not
hasattr
(
document
,
"get_changed_instance"
):
return
document
=
document
.
get_changed_instance
()
change_tracker
.
register
(
op
=
"update"
,
model
=
get_model_id
(
document
),
id
=
str
(
document
.
id
),
fields
=
None
,
)
def
_on_model_change
(
sender
,
instance
,
created
=
False
,
*
args
,
**
kwargs
):
...
...
@@ -121,3 +130,12 @@ def _on_model_delete(sender, instance, *args, **kwargs):
id
=
str
(
instance
.
id
),
fields
=
None
,
)
if
not
hasattr
(
instance
,
"get_changed_instance"
):
return
instance
=
instance
.
get_changed_instance
()
change_tracker
.
register
(
op
=
"update"
,
model
=
get_model_id
(
instance
),
id
=
str
(
instance
.
id
),
fields
=
None
,
)
dns/models/dnszonerecord.py
View file @
6c671d75
# ---------------------------------------------------------------------
# DNSZoneRecord model
# ---------------------------------------------------------------------
# Copyright (C) 2007-202
0
The NOC Project
# Copyright (C) 2007-202
2
The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from
typing
import
Optional
# Third-party modules
from
django.db
import
models
from
django.contrib.postgres.fields
import
ArrayField
...
...
@@ -32,7 +35,7 @@ class DNSZoneRecord(NOCModel):
db_table
=
"dns_dnszonerecord"
app_label
=
"dns"
zone
=
models
.
ForeignKey
(
DNSZone
,
verbose_name
=
"Zone"
,
on_delete
=
models
.
CASCADE
)
zone
:
"DNSZone"
=
models
.
ForeignKey
(
DNSZone
,
verbose_name
=
"Zone"
,
on_delete
=
models
.
CASCADE
)
name
=
models
.
CharField
(
_
(
"Name"
),
max_length
=
64
,
blank
=
True
,
null
=
True
)
ttl
=
models
.
IntegerField
(
_
(
"TTL"
),
null
=
True
,
blank
=
True
)
type
=
models
.
CharField
(
_
(
"Type"
),
max_length
=
16
)
...
...
@@ -50,7 +53,7 @@ class DNSZoneRecord(NOCModel):
)
@
classmethod
def
get_by_id
(
cls
,
id
):
def
get_by_id
(
cls
,
id
)
->
Optional
[
"DNSZoneRecord"
]
:
dnszonerecord
=
DNSZoneRecord
.
objects
.
filter
(
id
=
id
)[:
1
]
if
dnszonerecord
:
return
dnszonerecord
[
0
]
...
...
@@ -60,5 +63,5 @@ class DNSZoneRecord(NOCModel):
return
self
.
zone
@
classmethod
def
can_set_label
(
cls
,
label
)
:
def
can_set_label
(
cls
,
label
:
str
)
->
bool
:
return
Label
.
get_effective_setting
(
label
,
setting
=
"enable_dnszonerecord"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment