# Path: django_core/db/models/managers.py
# class CommonManager(BaseManager):
# 
#     def get_by_id(self, id, **kwargs):
#         """Gets a document by an id.
# 
#         :param id: id of the document to retrieve.
#         """
#         return self.get_or_none(id=id, **kwargs)
# 
#     def get_by_id_or_404(self, id, **kwargs):
#         """Gets by a instance instance r raises a 404 is one isn't found."""
#         obj = self.get_by_id(id=id, **kwargs)
# 
#         if obj:
#             return obj
# 
#         raise Http404
# 
#     def get_by_ids(self, ids, **kwargs):
#         """Gets documents by ids.
# 
#         :param ids: list of ids of documents to return
#         :param fields: a tuple of field names to return.  If None, all fields
#             are returned (default).
#         """
#         return self.filter(id__in=ids)
# 
#     def bulk_create(self, objs, *args, **kwargs):
#         """Insert many object at once."""
#         if hasattr(self.model, 'save_prep'):
#             # Method from AbstractBaseModel. If the model class doesn't
#             # subclass AbstractBaseModel, then don't call this.
#             self.model.save_prep(instance_or_instances=objs)
# 
#         return super(CommonManager, self).bulk_create(objs=objs,
#                                                       *args,
#                                                       **kwargs)
# 
#     def delete_by_id(self, id):
#         """Deletes a document by id."""
#         return self.delete_by_ids(ids=[id])
# 
#     def delete_by_ids(self, ids):
#         """Delete objects by ids.
# 
#         :param ids: list of objects ids to delete.
#         :return: True if objects were deleted.  Otherwise, return False if no
#                 objects were found or the delete was not successful.
#         """
#         try:
#             self.filter(id__in=ids).delete()
#             return True
#         except self.model.DoesNotExist:
#             return False
# 
# Path: django_core/db/models/mixins/dates.py
# class AbstractDateTimeTrackingModelMixin(models.Model):
#     """Model for tracking created and last modified datetimes."""
#     created_dttm = models.DateTimeField(default=datetime.utcnow)
#     last_modified_dttm = models.DateTimeField(default=datetime.utcnow)
# 
#     class Meta:
#         abstract = True
# 
#     def save(self, *args, **kwargs):
#         if self.id or not self.last_modified_dttm:
#             # only update the last_modified_dttm if the object is new or the
#             # last modified dttm doesn't exists.
#             self.last_modified_dttm = datetime.utcnow()
# 
#         return super(AbstractDateTimeTrackingModelMixin, self).save(*args,
#                                                                     **kwargs)
# 
# Path: django_core/utils/list_utils.py
# def make_obj_list(obj_or_objs):
#     """This method will take an object or list of objects and ensure a list is
#     returned.
# 
#     Example:
# 
#     >>> make_obj_list('hello')
#     ['hello']
#     >>> make_obj_list(['hello', 'world'])
#     ['hello', 'world']
#     >>> make_obj_list(None)
#     []
# 
#     """
#     if not obj_or_objs:
#         return []
# 
#     if not isinstance(obj_or_objs, (list, tuple)):
#         return [obj_or_objs]
# 
#     return obj_or_objs


from copy import deepcopy
from datetime import datetime
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django_core.db.models.managers import CommonManager
from django_core.db.models.mixins.dates import AbstractDateTimeTrackingModelMixin
from django_core.utils.list_utils import make_obj_list
from __future__ import unicode_literals




@python_2_unicode_compatible
class AbstractBaseModel(AbstractDateTimeTrackingModelMixin):
    """Base model for other db model to extend.  This class contains common
    model attributes needed by almost all models.

    Fields:

    * created: created user.  The user who created this instance.
    * created_dttm: created datetime.
    * last_modified: last user to modify this instance
    * last_modified_dttm: updated datetime. Datetime this document was last
        updated.
    """
    created_user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='%(app_label)s_%(class)s_created_user+')
    last_modified_user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='%(app_label)s_%(class)s_last_modified_user+')

# Path: django_core/db/models/managers.py
# class CommonManager(BaseManager):
# 
#     def get_by_id(self, id, **kwargs):
#         """Gets a document by an id.
# 
#         :param id: id of the document to retrieve.
#         """
#         return self.get_or_none(id=id, **kwargs)
# 
#     def get_by_id_or_404(self, id, **kwargs):
#         """Gets by a instance instance r raises a 404 is one isn't found."""
#         obj = self.get_by_id(id=id, **kwargs)
# 
#         if obj:
#             return obj
# 
#         raise Http404
# 
#     def get_by_ids(self, ids, **kwargs):
#         """Gets documents by ids.
# 
#         :param ids: list of ids of documents to return
#         :param fields: a tuple of field names to return.  If None, all fields
#             are returned (default).
#         """
#         return self.filter(id__in=ids)
# 
#     def bulk_create(self, objs, *args, **kwargs):
#         """Insert many object at once."""
#         if hasattr(self.model, 'save_prep'):
#             # Method from AbstractBaseModel. If the model class doesn't
#             # subclass AbstractBaseModel, then don't call this.
#             self.model.save_prep(instance_or_instances=objs)
# 
#         return super(CommonManager, self).bulk_create(objs=objs,
#                                                       *args,
#                                                       **kwargs)
# 
#     def delete_by_id(self, id):
#         """Deletes a document by id."""
#         return self.delete_by_ids(ids=[id])
# 
#     def delete_by_ids(self, ids):
#         """Delete objects by ids.
# 
#         :param ids: list of objects ids to delete.
#         :return: True if objects were deleted.  Otherwise, return False if no
#                 objects were found or the delete was not successful.
#         """
#         try:
#             self.filter(id__in=ids).delete()
#             return True
#         except self.model.DoesNotExist:
#             return False
# 
# Path: django_core/db/models/mixins/dates.py
# class AbstractDateTimeTrackingModelMixin(models.Model):
#     """Model for tracking created and last modified datetimes."""
#     created_dttm = models.DateTimeField(default=datetime.utcnow)
#     last_modified_dttm = models.DateTimeField(default=datetime.utcnow)
# 
#     class Meta:
#         abstract = True
# 
#     def save(self, *args, **kwargs):
#         if self.id or not self.last_modified_dttm:
#             # only update the last_modified_dttm if the object is new or the
#             # last modified dttm doesn't exists.
#             self.last_modified_dttm = datetime.utcnow()
# 
#         return super(AbstractDateTimeTrackingModelMixin, self).save(*args,
#                                                                     **kwargs)
# 
# Path: django_core/utils/list_utils.py
# def make_obj_list(obj_or_objs):
#     """This method will take an object or list of objects and ensure a list is
#     returned.
# 
#     Example:
# 
#     >>> make_obj_list('hello')
#     ['hello']
#     >>> make_obj_list(['hello', 'world'])
#     ['hello', 'world']
#     >>> make_obj_list(None)
#     []
# 
#     """
#     if not obj_or_objs:
#         return []
# 
#     if not isinstance(obj_or_objs, (list, tuple)):
#         return [obj_or_objs]
# 
#     return obj_or_objs


# Path: django_core/db/models/mixins/base.py
from copy import deepcopy
from datetime import datetime
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django_core.db.models.managers import CommonManager
from django_core.db.models.mixins.dates import AbstractDateTimeTrackingModelMixin
from django_core.utils.list_utils import make_obj_list

from __future__ import unicode_literals




@python_2_unicode_compatible
class AbstractBaseModel(AbstractDateTimeTrackingModelMixin):
    """Base model for other db model to extend.  This class contains common
    model attributes needed by almost all models.

    Fields:

    * created: created user.  The user who created this instance.
    * created_dttm: created datetime.
    * last_modified: last user to modify this instance
    * last_modified_dttm: updated datetime. Datetime this document was last
        updated.
    """
    created_user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='%(app_label)s_%(class)s_created_user+')
    last_modified_user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='%(app_label)s_%(class)s_last_modified_user+')

    objects = CommonManager()