mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-04-24 02:21:59 +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
|
||||
|
||||
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)
|
||||
|
||||
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`:
|
||||
|
||||
```python
|
||||
|
@ -230,9 +231,7 @@ from django.db import models
|
|||
from django.utils import timezone
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
created_at = models.DateTimeField(db_index=True, default=timezone.now)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
class BaseModel(AuditLogModel, TimeStampedModel):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
|
Loading…
Reference in New Issue
Block a user