[ADD] Attempt to explain the sentinel user function

Let's see if the docs are generated properly with this
This commit is contained in:
Peter Pfeufer 2023-11-12 11:28:22 +01:00
parent cbb5c80b94
commit 33ad1413d5
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27
2 changed files with 29 additions and 0 deletions

View File

@ -7,5 +7,6 @@ Alliance Auth is providing its own CSS framework with a couple of CSS classes.
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
framework/api
framework/css framework/css
``` ```

View File

@ -0,0 +1,28 @@
# Alliance Auth Helper-Functions API
## User API
### get_main_character_from_user
### get_main_character_name_from_user
### get_sentinel_user
This function is useful in models when using `User` model-objects as foreign keys.
Django needs to know what should happen to those relations when the user is being
deleted. To keep the data, you can have Django map this to the sentinel user.
Import:
```python
from allianceauth.framework.api.user import get_sentinel_user
```
And later in your model:
```python
creator = models.ForeignKey(
to=User,
on_delete=models.SET(get_sentinel_user),
)
```