import arrow
from django.conf import settings
from django.db import models
from .mixins import ModelPermissionsMixin


class CCEModel(ModelPermissionsMixin, models.Model):
    """
    Abstract base model with permissions mixin.
    """
    class Meta:
        abstract = True


class CCEAuditModel(CCEModel):
    """
    Abstract model with fields for the user and timestamp of a row's creation
    and last update.

    .. note:: - Inherits from **CCEModel**
              - Requires **django-cuser** package to determine current user

    :tags:
        django-cuser
    """
    from cuser.fields import CurrentUserField

    last_updated_by = CurrentUserField(
        related_name='%(app_label)s_%(class)s_last_updated')
    last_updated_at = models.DateTimeField(auto_now=True)
    created_by = CurrentUserField(add_only=True,
                                  related_name='%(app_label)s_%(class)s_'
                                               'last_created')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        abstract = True

    @property
    def tz_last_updated_at(self):
        if not hasattr(settings, 'TIME_ZONE'):
            return arrow.get(self.last_updated_at).datetime
        return arrow.get(self.last_updated_at, settings.TIME_ZONE).datetime

    @property
    def tz_created_at(self):
        if not hasattr(settings, 'TIME_ZONE'):
            return arrow.get(self.created_at).datetime
        return arrow.get(self.created_at, settings.TIME_ZONE).datetime

from django.db import models
from django.utils.timezone import localtime

from .mixins import ModelPermissionsMixin


class CCEModel(ModelPermissionsMixin, models.Model):
    """
    Abstract base model with permissions mixin.
    """
    class Meta:
        abstract = True


class CCEAuditModel(CCEModel):
    """
    Abstract model with fields for the user and timestamp of a row's creation
    and last update.

    .. note:: - Inherits from **CCEModel**
              - Requires **django-cuser** package to determine current user

    :tags:
        django-cuser
    """
    from cuser.fields import CurrentUserField

    last_updated_by = CurrentUserField(related_name='%(app_label)s_%(class)s_last_updated')
    last_updated_at = models.DateTimeField(auto_now=True)
    created_by = CurrentUserField(add_only=True, related_name='%(app_label)s_%(class)s_last_created')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        abstract = True

    @property
    def tz_last_updated_at(self):
        return localtime(self.last_updated_at)

    @property
    def tz_created_at(self):
        return localtime(self.created_at)

Update Timezone aware values for CCEAuditModel
Update Timezone aware values for CCEAuditModel

- import arrow
- from django.conf import settings
  from django.db import models
+ from django.utils.timezone import localtime
+ 
  from .mixins import ModelPermissionsMixin
  
  
  class CCEModel(ModelPermissionsMixin, models.Model):
      """
      Abstract base model with permissions mixin.
      """
      class Meta:
          abstract = True
  
  
  class CCEAuditModel(CCEModel):
      """
      Abstract model with fields for the user and timestamp of a row's creation
      and last update.
  
      .. note:: - Inherits from **CCEModel**
                - Requires **django-cuser** package to determine current user
  
      :tags:
          django-cuser
      """
      from cuser.fields import CurrentUserField
  
+     last_updated_by = CurrentUserField(related_name='%(app_label)s_%(class)s_last_updated')
-     last_updated_by = CurrentUserField(
-         related_name='%(app_label)s_%(class)s_last_updated')
      last_updated_at = models.DateTimeField(auto_now=True)
+     created_by = CurrentUserField(add_only=True, related_name='%(app_label)s_%(class)s_last_created')
-     created_by = CurrentUserField(add_only=True,
-                                   related_name='%(app_label)s_%(class)s_'
-                                                'last_created')
      created_at = models.DateTimeField(auto_now_add=True)
  
      class Meta:
          abstract = True
  
      @property
      def tz_last_updated_at(self):
+         return localtime(self.last_updated_at)
-         if not hasattr(settings, 'TIME_ZONE'):
-             return arrow.get(self.last_updated_at).datetime
-         return arrow.get(self.last_updated_at, settings.TIME_ZONE).datetime
  
      @property
      def tz_created_at(self):
+         return localtime(self.created_at)
-         if not hasattr(settings, 'TIME_ZONE'):
-             return arrow.get(self.created_at).datetime
-         return arrow.get(self.created_at, settings.TIME_ZONE).datetime
  
Update Timezone aware values for CCEAuditModel
## Code Before:
import arrow
from django.conf import settings
from django.db import models
from .mixins import ModelPermissionsMixin


class CCEModel(ModelPermissionsMixin, models.Model):
    """
    Abstract base model with permissions mixin.
    """
    class Meta:
        abstract = True


class CCEAuditModel(CCEModel):
    """
    Abstract model with fields for the user and timestamp of a row's creation
    and last update.

    .. note:: - Inherits from **CCEModel**
              - Requires **django-cuser** package to determine current user

    :tags:
        django-cuser
    """
    from cuser.fields import CurrentUserField

    last_updated_by = CurrentUserField(
        related_name='%(app_label)s_%(class)s_last_updated')
    last_updated_at = models.DateTimeField(auto_now=True)
    created_by = CurrentUserField(add_only=True,
                                  related_name='%(app_label)s_%(class)s_'
                                               'last_created')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        abstract = True

    @property
    def tz_last_updated_at(self):
        if not hasattr(settings, 'TIME_ZONE'):
            return arrow.get(self.last_updated_at).datetime
        return arrow.get(self.last_updated_at, settings.TIME_ZONE).datetime

    @property
    def tz_created_at(self):
        if not hasattr(settings, 'TIME_ZONE'):
            return arrow.get(self.created_at).datetime
        return arrow.get(self.created_at, settings.TIME_ZONE).datetime

## Instruction:
Update Timezone aware values for CCEAuditModel
## Code After:
from django.db import models
from django.utils.timezone import localtime

from .mixins import ModelPermissionsMixin


class CCEModel(ModelPermissionsMixin, models.Model):
    """
    Abstract base model with permissions mixin.
    """
    class Meta:
        abstract = True


class CCEAuditModel(CCEModel):
    """
    Abstract model with fields for the user and timestamp of a row's creation
    and last update.

    .. note:: - Inherits from **CCEModel**
              - Requires **django-cuser** package to determine current user

    :tags:
        django-cuser
    """
    from cuser.fields import CurrentUserField

    last_updated_by = CurrentUserField(related_name='%(app_label)s_%(class)s_last_updated')
    last_updated_at = models.DateTimeField(auto_now=True)
    created_by = CurrentUserField(add_only=True, related_name='%(app_label)s_%(class)s_last_created')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        abstract = True

    @property
    def tz_last_updated_at(self):
        return localtime(self.last_updated_at)

    @property
    def tz_created_at(self):
        return localtime(self.created_at)
