mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-06-19 20:43:10 +03:00
Add Model Style guide
This commit is contained in:
parent
3d2fbda813
commit
17d9195eba
11
README.md
11
README.md
|
@ -218,11 +218,12 @@ Models should take care of the data model and not much else.
|
||||||
### Base model
|
### Base model
|
||||||
|
|
||||||
It's a good idea to define a `BaseModel`, that you can inherit.
|
It's a good idea to define a `BaseModel`, that you can inherit.
|
||||||
|
|
||||||
Usually, fields like `created_at` and `updated_at` are perfect candidates to go into a `BaseModel`.
|
|
||||||
|
|
||||||
Defining a primary key can also go there. Potential candidate for that is the [`UUIDField`](https://docs.djangoproject.com/en/dev/ref/models/fields/#uuidfield)
|
Defining a primary key can also go there. Potential candidate for that is the [`UUIDField`](https://docs.djangoproject.com/en/dev/ref/models/fields/#uuidfield)
|
||||||
|
|
||||||
|
At Shahry We're using `TimeStampedModel` which has `created` and `updated` fields
|
||||||
|
|
||||||
|
Since all models should be audit logs the `BaseModel` Should has `AuditLogModel`.
|
||||||
|
|
||||||
Here's an example `BaseModel`:
|
Here's an example `BaseModel`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -230,9 +231,7 @@ from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(models.Model):
|
class BaseModel(AuditLogModel, TimeStampedModel):
|
||||||
created_at = models.DateTimeField(db_index=True, default=timezone.now)
|
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user