loadGeneric.py 555 Bytes
Newer Older
1
from base_app.models import User
Florent Chehab's avatar
Florent Chehab committed
2
from django.utils import timezone
Florent Chehab's avatar
Florent Chehab committed
3

Florent Chehab's avatar
Florent Chehab committed
4
import reversion
Florent Chehab's avatar
Florent Chehab committed
5
from backend_app.models.abstract.my_model import MyModel
Florent Chehab's avatar
Florent Chehab committed
6 7 8


class LoadGeneric(object):
Florent Chehab's avatar
Florent Chehab committed
9 10 11
    """Class to handle the loading of initial data in a generic fashion
    """

Florent Chehab's avatar
Florent Chehab committed
12
    @classmethod
Florent Chehab's avatar
Florent Chehab committed
13
    def add_info_and_save(cls, obj: MyModel, admin: User):
Florent Chehab's avatar
Florent Chehab committed
14 15 16 17 18 19
        with reversion.create_revision():
            obj.moderated_by = admin
            obj.updated_by = admin
            obj.moderated_on = timezone.now()
            obj.updated_on = timezone.now()
            obj.save()