Commit 1279f3fc authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Merge branch '251-we-should-systematically-enforce-model-constraints-on-save' into 'django'

Resolve "we should systematically enforce model constraints on .save()"

Closes #251

See merge request !128
parents 62349dff acec89d8
Pipeline #40341 failed with stage
in 1 minute and 27 seconds
......@@ -32,8 +32,29 @@ def generate_token(length=32):
return get_random_string(length)
class BaseModel(models.Model):
"""Base model for all allgo models
class TimeStampModel(models.Model):
This base class overrides .save() to enforce validation of the model
constraints before creating or updating an entry.
The validation is automatically peformed unless `force_insert` or
`force_update` is true.
see also:
def save(self, force_insert=False, force_update=False, **kw):
if not (force_insert or force_update):
super().save(force_insert, force_update, **kw)
class Meta:
abstract = True
class TimeStampModel(BaseModel):
An abstract base class model that provides self-updating ``created_at`` and
``updated_at`` fields.
......@@ -46,7 +67,7 @@ class TimeStampModel(models.Model):
abstract = True
class AllgoUser(models.Model):
class AllgoUser(BaseModel):
Class linked to the Django user management. If there is a need to add a
field related to a user, it should be added here and not in the auth_user
......@@ -74,7 +95,7 @@ class AllgoUser(models.Model):
return [a.docker_name for a in Webapp.objects.filter(]
class DockerOs(models.Model):
class DockerOs(BaseModel):
Contains the different Operating Systems that a user can choose from to
build its container.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment