nautobot.apps.models
¶
Data model classes and utilities for app implementation.
nautobot.apps.models.BaseModel
¶
Bases: models.Model
Base model class that all models should inherit from.
This abstract base provides globally common fields and functionality.
Here we define the primary key to be a UUID field and set its default to
automatically generate a random UUID value. Note however, this does not
operate in the same way as a traditional auto incrementing field for which
the value is issued by the database upon initial insert. In the case of
the UUID field, Django creates the value upon object instantiation. This
means the canonical pattern in Django of checking self.pk is None
to tell
if an object has been created in the actual database does not work because
the object will always have the value populated prior to being saved to the
database for the first time. An alternate pattern of checking not self.present_in_database
can be used for the same purpose in most cases.
Source code in nautobot/core/models/__init__.py
present_in_database()
property
¶
validated_save()
¶
Perform model validation during instance save.
This is a convenience method that first calls self.full_clean()
and then self.save()
which in effect enforces model validation prior to saving the instance, without having
to manually make these calls seperately. This is a slight departure from Django norms,
but is intended to offer an optional, simplified interface for performing this common
workflow. The indended use is for user defined Jobs and scripts run via the nbshell
command.
Source code in nautobot/core/models/__init__.py
nautobot.apps.models.CustomValidator
¶
This class is used to register plugin custom model validators which act on specified models. It contains the clean
method which is overridden by plugin authors to execute custom validation logic. Plugin authors must raise
ValidationError within this method to trigger validation error messages which are propagated to the user.
A convenience method validation_error(<message>)
may be used for this purpose.
The model
attribute on the class defines the model to which this validator is registered. It
should be set as a string in the form <app_label>.<model_name>
.
Source code in nautobot/extras/plugins/__init__.py
clean()
¶
Implement custom model validation in the standard Django clean method pattern. The model instance is accessed
with the object
key within self.context
, e.g. self.context['object']
. ValidationError must be raised to
prevent saving model instance changes, and propagate messages to the user. For convenience,
self.validation_error(<message>)
may be called to raise a ValidationError.
Source code in nautobot/extras/plugins/__init__.py
validation_error(message)
¶
Convenience method for raising django.core.exceptions.ValidationError
which is required in order to
trigger validation error messages which are propagated to the user.
Source code in nautobot/extras/plugins/__init__.py
nautobot.apps.models.OrganizationalModel
¶
Bases: BaseModel
, ChangeLoggedModel
, CustomFieldModel
, RelationshipModel
, DynamicGroupMixin
, NotesMixin
Base abstract model for all organizational models.
Organizational models aid the primary models by building structured relationships and logical groups, or categorizations. Organizational models do not typically represent concrete networking resources or assets, but rather they enable user specific use cases and metadata about network resources. Examples include Device Role, Rack Group, Status, Manufacturer, and Platform.
Source code in nautobot/core/models/generics.py
nautobot.apps.models.PrimaryModel
¶
Bases: BaseModel
, ChangeLoggedModel
, CustomFieldModel
, RelationshipModel
, DynamicGroupMixin
, NotesMixin
Base abstract model for all primary models.
A primary model is one which is materialistically relevant to the network datamodel. Such models form the basis of major elements of the data model, like Device, IP Address, Site, VLAN, Virtual Machine, etc. Primary models usually represent tangible or logical resources on the network, or within the organization.
Source code in nautobot/core/models/generics.py
nautobot.apps.models.StatusField
¶
Bases: models.ForeignKey
Model database field that automatically limits custom choices.
The limit_choices_to for the field are automatically derived from
- the content-type to which the field is attached (e.g.
dcim.device
)
Source code in nautobot/extras/models/statuses.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
contribute_to_class(cls, name, *args, private_only=False, **kwargs)
¶
Overload default so that we can assert that .get_FOO_display
is
attached to any model that is using a StatusField
.
Using .contribute_to_class()
is how field objects get added to the model
at during the instance preparation. This is also where any custom model
methods are hooked in. So in short this method asserts that any time a
StatusField
is added to a model, that model also gets a
.get_status_display()
and a .get_status_color()
method without
having to define it on the model yourself.
Source code in nautobot/extras/models/statuses.py
formfield(**kwargs)
¶
Return a prepped formfield for use in model forms.
Source code in nautobot/extras/models/statuses.py
nautobot.apps.models.VarbinaryIPField
¶
Bases: models.BinaryField
IP network address
Source code in nautobot/ipam/fields.py
db_type(connection)
¶
Returns the correct field type for a given database vendor.
Source code in nautobot/ipam/fields.py
from_db_value(value, expression, connection)
¶
get_db_prep_value(value, connection, prepared=False)
¶
Converts Python (str) to DB (varbinary).
Source code in nautobot/ipam/fields.py
to_python(value)
¶
value_to_string(obj)
¶
nautobot.apps.models.extras_features(*features)
¶
Decorator used to register extras provided features to a model