refactor: rename app from itsm -> app
used app as this is a root application and not a django project app !1
This commit is contained in:
56
app/access/fields.py
Normal file
56
app/access/fields.py
Normal file
@ -0,0 +1,56 @@
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
class AutoCreatedField(models.DateTimeField):
|
||||
"""
|
||||
A DateTimeField that automatically populates itself at
|
||||
object creation.
|
||||
|
||||
By default, sets editable=False, default=datetime.now.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
kwargs.setdefault("editable", False)
|
||||
|
||||
kwargs.setdefault("default", now)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class AutoLastModifiedField(AutoCreatedField):
|
||||
"""
|
||||
A DateTimeField that updates itself on each save() of the model.
|
||||
|
||||
By default, sets editable=False and default=datetime.now.
|
||||
|
||||
"""
|
||||
|
||||
def pre_save(self, model_instance, add):
|
||||
|
||||
value = now()
|
||||
|
||||
setattr(model_instance, self.attname, value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
class AutoSlugField(models.SlugField):
|
||||
"""
|
||||
A DateTimeField that updates itself on each save() of the model.
|
||||
|
||||
By default, sets editable=False and default=datetime.now.
|
||||
|
||||
"""
|
||||
|
||||
def pre_save(self, model_instance, add):
|
||||
|
||||
value = self.name.lower().replace(' ', '_')
|
||||
|
||||
setattr(model_instance, self.attname, value)
|
||||
|
||||
return value
|
||||
|
||||
|
Reference in New Issue
Block a user