Add Model Style guide

This commit is contained in:
Mohamed Mansor 2023-11-12 00:06:43 +02:00
parent 3d2fbda813
commit 17d9195eba

View File

@ -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