Skip to content

Commit

Permalink
introduces custom relationships for the contrib module
Browse files Browse the repository at this point in the history
  • Loading branch information
Kircheneer committed Jan 4, 2024
1 parent d7168b7 commit a86facf
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/user/modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ This page describes how to model various kinds of fields on a `nautobot_ssot.con
The following table describes in brief the different types of model fields and how they are handled.

| Type of field | Field name | Notes | Applies to |
| -------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|----------------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Normal fields](#normal-fields) | Has to match ORM exactly | Make sure that the name matches the name in the ORM model. | Fields that are neither custom fields nor relations |
| [Custom fields](#custom-fields) | Field name doesn't matter | Use `nautobot_ssot.contrib.CustomFieldAnnotation` | [Nautobot custom fields](https://docs.nautobot.com/projects/core/en/stable/user-guides/custom-fields/?h=custom+fields) |
| [*-to-one relationships](#-to-one-relationships) | Django lookup syntax | See [here](https://docs.djangoproject.com/en/3.2/topics/db/queries/#lookups-that-span-relationships) - your model fields need to use this syntax | `django.db.models.OneToOneField`, `django.db.models.ForeignKey`, `django.contrib.contenttypes.fields.GenericForeignKey` |
| [*-to-many relationships](#-to-many-relationships) | Has to match ORM exactly | In case of a generic foreign key see [here](#special-case-generic-foreign-key) | `django.db.models.ManyToManyField`, `django.contrib.contenttypes.fields.GenericRelation`, `django.db.models.ForeignKey` [backwards](https://docs.djangoproject.com/en/3.2/topics/db/queries/#backwards-related-objects) |
| Custom Relationships | n/a | Not yet supported | https://docs.nautobot.com/projects/core/en/stable/models/extras/relationship/ |
| Custom Relationships | Field name doesn't matter | Use `nautobot_ssot.contrib.CustomRelationshipAnnotation` | https://docs.nautobot.com/projects/core/en/stable/models/extras/relationship/ |


## Normal Fields
Expand Down
Loading

0 comments on commit a86facf

Please sign in to comment.