lostplaces-backend/django_lostplaces/docs/developer.md

155 lines
6.4 KiB
Markdown
Raw Normal View History

2020-09-15 21:07:53 +02:00
# django lostplaces documentation for developer
Greetings,
2020-09-27 23:56:45 +02:00
this documentation is for anyone who wants to work with this projects codebase or is just curious about how it works.
2020-09-15 21:07:53 +02:00
## Models
The models contain an custom user profile, some abstract base models and the models holding the actual data for this project
### Explorer user profile
2020-09-27 23:56:45 +02:00
Location: `lostplaces.models.models.Explorer`
Import from: `lostplaces.models.models.Explorer`
#### Super Classes
- django's `models.Model`
The class `lostplaces.models.Explorer` is our custom user profile. It has an ForeignKey pointing at django's default user model instead of providing an entire custom user model. That way this django app does not conflict with any other app that brings it's own user model.
2020-09-15 21:07:53 +02:00
You can access the explorer profile by accessing the 'explorer' attribute of any user instance
```python
2020-09-21 21:37:28 +02:00
user.explorer
2020-09-15 21:07:53 +02:00
```
2020-09-27 23:56:45 +02:00
Currently the explorer profile is used by the abstract model 'Submittable' and has the following realated names/fiels:
- [places](###place) A list containing all (lost) places the user has submitted
- [placeimages](###placeimages) A list containing all images relating a place that a user has submitted
- [photoalbums](###photoalbums) A list of all photo albums a explorere has submitted
2020-09-15 21:07:53 +02:00
### Taggable
2020-09-27 23:56:45 +02:00
Location: `lostplaces.models.abstract_models.Taggable`
Import from: `lostplaces.models.models.Taggable`
#### Super Classes
- django's `models.Model`
2020-09-15 21:07:53 +02:00
The abstract model Taggable represents an model that is taggable. It depends on the django app [taggit](https://github.com/jazzband/django-taggit). It only consists of one field:
2020-09-27 23:56:45 +02:00
- `tag`: TaggableManager, allows the sub class to be tagged, blank=True allows the admin form to be submitted without any tags
2020-09-15 21:07:53 +02:00
### Mapable
2020-09-27 23:56:45 +02:00
Location: `lostplaces.models.abstract_models.Mapable`
Import from: `lostplaces.models.models.Mapable`
#### Super Classes
- django's `models.Model`
The abstract model Mapable represents an model that can be displayed on a map. It consists of tree attributes
2020-09-15 21:07:53 +02:00
`name`
2020-09-21 21:37:28 +02:00
Name of the object, displayed on the map, max length 50 characters
2020-09-15 21:07:53 +02:00
`latitude`
Latitude of the referenced location, -90 <= value <= 90
`longitude`
Longitude of the referenced location -180 <= value <= 180
2020-09-21 21:37:28 +02:00
A mapable model has to provide its own get_absolute_url, in order to provide a link when clicked.
2020-09-15 21:07:53 +02:00
### Submittable
2020-09-27 23:56:45 +02:00
Location: `lostplaces.models.abstract_models.Submittable`
Import from: `lostplaces.models.models.Submittable`
#### Super Classes
- django's `models.Model`
2020-09-15 21:07:53 +02:00
The abstract model Submittable represents an model that can be submitted by an user. It knows who submitted something and when:
`submitted_by`
Squashed commit of the following: commit 0d62e72d72922a84e41c9f2cc21977b794784d1c Merge: 79fee63 85f2a81 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:55:18 2020 +0200 Merge branch 'develop' into refactor/models commit 79fee631d7ac28509067ecdd74078f1a2f6e0be2 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:54:32 2020 +0200 Updating references for related name commit 8e07e79df2de2601f2e2eadfdd37eb7c719c51b0 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:53:31 2020 +0200 Generating of related names fix commit 5fd804f37a805ae4707e13c3d941bdde3660afea Merge: 8cc1d3e 3b526c9 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:01:48 2020 +0200 Merge branch 'develop' into refactor/models commit 8cc1d3e690211dba6451e86569f00078b23e0621 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 20:21:08 2020 +0200 Tests commit 7c0591e5397f892b1f6fb80725a693c21f90468a Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 23:53:39 2020 +0200 Testing PlaceAsset commit 2e7b49ad1a15173565c81e7eb8bb3f35b9f622a6 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 22:25:08 2020 +0200 Restructuring models commit eb7d03b08b326f9115e70d0fd9ed5d0fc229a362 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 22:01:54 2020 +0200 Abstract class Expireable commit 2b51e741bb5734c5a578beeadef7819fe58b2223 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 21:54:07 2020 +0200 Abstract Model for PlaceAsset (i.e. Photoalbums)
2020-09-22 21:56:51 +02:00
Referencing the explorer profile, see [Explorer](##explorer-user-profile). If the explorer profile is deleted, this instance is kept (on_delete=models.SET_NULL). The related_name is set to the class name, lower case appending an s (%(class)ss)
2020-09-15 21:07:53 +02:00
`submitted_when`
2020-09-21 21:37:28 +02:00
When the object was submitted, automatically set by django (auto_now_add=True)
2020-09-15 21:07:53 +02:00
2020-09-27 23:56:45 +02:00
### Expireable
Location: `lostplaces.models.abstract_models.Expireable`
Import from: `lostplaces.models.models.Expireable`
#### Super Classes
- django's `models.Model`
This abstract model represents an object that can expire. It is currently used by the Voucher model. I consists of two fields:
`created_when`
The date the object was created, automatically set by django (auto_now_add=True)
`expires_when`
The date the object expires.
2020-09-15 21:07:53 +02:00
### Voucher
2020-09-27 23:56:45 +02:00
Locatoin: `lostplaces.models.models.Voucher`
Import from: `lostplaces.models.models.Voucher`
#### Super Classes
- django's `models.Model`
- [lostplaces.models.Expireable](###expireable)
2020-09-15 21:07:53 +02:00
A voucher code is needed to sign up using lostplaces sign up form. The model contains
`code`
2020-09-21 21:37:28 +02:00
The voucher code, max length 30 characters
2020-09-15 21:07:53 +02:00
`created_when`
2020-09-21 21:37:28 +02:00
When the voucher was created automatically set by django (auto_now_add=True)
2020-09-15 21:07:53 +02:00
`expires_when`
Till what date the voucher remains valid
### Place
2020-09-27 23:56:45 +02:00
Location: `lostplaces.models.place.Place`
Import from: `lostplaces.models.Place`
#### Super Classes
- django's `models.Model`
- [lostplaces.models.Submittable](###submittable)-
- [lostplaces.models.Taggable](###taggable)
- [lostlaces.models.Mapable]
2020-09-15 21:07:53 +02:00
The place model is the heart of this project. It stores all information about a place needed.
`location`
2020-09-21 21:37:28 +02:00
Human readable location description (town, village, street), max length 50 characters
2020-09-15 21:07:53 +02:00
`description`
Describing the place in detail
The place model uses these abstract super classes
- Submittable, see [Submittable](##submittable) for additional fields
- Taggable, see [Taggable](##taggable) for additional fields
- Mapable, see [Mapable](##mapable) for additional fields
2020-09-27 23:56:45 +02:00
The average_latlon function takes a list of places and returns the center point of all these places.
### PlaceAsset
Location: `lostplaces.models.PlaceAsset`
Import from: `lostplaces.models.place.PlaceAsset`
#### Super Classes
- django's `models.Model`
- [lostplaces.models.Submittable](###submittable)
A PlaceAsset is anything that belongs to a place. The PlaceImage model for exmpaple is a subclass of PlaceAsset. A PlaceAsset is supposed to be submittable by every user. Only the user who has submitted the asset, the place the asset belongs to or both can delete a asset.
An PlaceAsset has the following fields
`place`
The Place this PlaceAsset belongs to
The PlaceAsset model is a subclass of Submittable, see [Submittable](###submittable) for more details.
### External Link
Loacation: `lostplaces.models.external_link.ExternalLink`
Import From: `lostplaces.models.ExternalLink`
#### Super Classes
- django's `models.Model`
- [lostplaces.models.Submittable](###submittable)
- [lostplaces.models.PlaceAsset](###placeasset)
This model represents an URL to an external website. External Link is an PlaceAsset, see [above](###placeasset) for more details. External Link has to fields
`url`
the URL to the target
`label`
the label that is shown on the website
### PhotoAlbum
Loacation: `lostplaces.models.external_link.PhototAlbum`
Import From: `lostplaces.models.PhotoAlbum`
#### Super Classes
- django's `models.Model`
- [lostplaces.models.Submittable](###submittable)
- [lostplaces.models.PlaceAsset](###placeasset)
- [lostplaces.models.ExternalLink](###externallink)
A photo album is a link to an external site that is meant to contain photos of the place it is referenced in. It
does not have any fields, just the ones inherited from it's super class [ExternalLink](###externallink).