Commit aae239c1 authored by Dmitry Volodin's avatar Dmitry Volodin
Browse files

Merge branch 'noc-1819-3' into 'master'

Exclude Auto generate fields from managedobject save.

See merge request noc/noc!6360
parents a18c2d8e d2acaffb
......@@ -29,6 +29,13 @@ class NOCModelBase(ModelBase):
# NB: Every hipster may be misused
if not is_base:
# Exclude non-update fields
if hasattr(m, "_non_update_fields"):
m._allow_update_fields = tuple(
for field in m._meta.fields
if not in m._ignore_on_save and not field.primary_key
return m
......@@ -62,5 +69,5 @@ class NOCModelBase(ModelBase):
return kls
class NOCModel(object, metaclass=NOCModelBase):
class NOCModel(Model, metaclass=NOCModelBase):
......@@ -616,6 +616,18 @@ class ManagedObject(NOCModel):
_e_labels_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
_neighbor_cache = cachetools.TTLCache(1000, ttl=300)
_ignore_on_save = (
def __str__(self):
......@@ -1402,6 +1414,12 @@ class ManagedObject(NOCModel):
caps[] = c.get("value")
return caps
def save(self, **kwargs):
kwargs = kwargs or {}
if getattr(self, "_allow_update_fields", None) and "update_fields" not in kwargs:
kwargs["update_fields"] = self._allow_update_fields
def update_caps(self, caps: Dict[str, Any], source: str) -> Dict[str, Any]:
Update existing capabilities with a new ones.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment