# Path: django_core/db/models/managers.py
# class GenericManager(models.Manager):
#     """Model manager for models that have generic objects."""
# 
#     def create_generic(self, content_object=None, **kwargs):
#         """Create a generic object.
# 
#         :param content_object: the content object to create a new object for.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.create(**kwargs)
# 
#     def filter_generic(self, content_object=None, **kwargs):
#         """Filter by a generic object.
# 
#         :param content_object: the content object to filter on.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.filter(**kwargs)
# 
#     def get_or_create_generic(self, content_object=None, **kwargs):
#         """Gets or creates a generic object.  This is a wrapper for
#         get_or_create(...) when you need to get or create a generic object.
# 
#         :param obj: the object to get or create
#         :param kwargs: any other kwargs that the model accepts.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.get_or_create(**kwargs)
# 
#     def get_by_content_type(self, content_type):
#         """Gets all objects by a content type."""
#         return self.filter(content_type=content_type)
# 
#     def get_by_model(self, model):
#         """Gets all object by a specific model."""
#         content_type = ContentType.objects.get_for_model(model)
#         return self.filter(content_type=content_type)


from django.contrib.contenttypes.fields import GenericForeignKey
from django.db import models
from ..managers import GenericManager
from __future__ import unicode_literals




class AbstractGenericObject(models.Model):
    """Abstract model class for a generic object."""

    class Meta:
        abstract = True

    content_type = models.ForeignKey('contenttypes.ContentType')
    object_id = models.PositiveIntegerField(db_index=True, unique=False)
    content_object = GenericForeignKey('content_type', 'object_id')
    objects = GenericManager()


class AbstractNullableGenericObject(models.Model):
    """Abstract model class for a generic object that's optional."""

    class Meta:
        abstract = True

    content_type = models.ForeignKey('contenttypes.ContentType', blank=True,
                                     null=True, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField(db_index=True, unique=False,
                                            blank=True, null=True)
    content_object = GenericForeignKey('content_type', 'object_id')

# Path: django_core/db/models/managers.py
# class GenericManager(models.Manager):
#     """Model manager for models that have generic objects."""
# 
#     def create_generic(self, content_object=None, **kwargs):
#         """Create a generic object.
# 
#         :param content_object: the content object to create a new object for.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.create(**kwargs)
# 
#     def filter_generic(self, content_object=None, **kwargs):
#         """Filter by a generic object.
# 
#         :param content_object: the content object to filter on.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.filter(**kwargs)
# 
#     def get_or_create_generic(self, content_object=None, **kwargs):
#         """Gets or creates a generic object.  This is a wrapper for
#         get_or_create(...) when you need to get or create a generic object.
# 
#         :param obj: the object to get or create
#         :param kwargs: any other kwargs that the model accepts.
#         """
#         if content_object:
#             kwargs['content_type'] = ContentType.objects.get_for_model(
#                 content_object
#             )
#             kwargs['object_id'] = content_object.id
# 
#         return self.get_or_create(**kwargs)
# 
#     def get_by_content_type(self, content_type):
#         """Gets all objects by a content type."""
#         return self.filter(content_type=content_type)
# 
#     def get_by_model(self, model):
#         """Gets all object by a specific model."""
#         content_type = ContentType.objects.get_for_model(model)
#         return self.filter(content_type=content_type)


# Path: django_core/db/models/mixins/generic.py
from django.contrib.contenttypes.fields import GenericForeignKey
from django.db import models
from ..managers import GenericManager

from __future__ import unicode_literals




class AbstractGenericObject(models.Model):
    """Abstract model class for a generic object."""

    class Meta:
        abstract = True

    content_type = models.ForeignKey('contenttypes.ContentType')
    object_id = models.PositiveIntegerField(db_index=True, unique=False)
    content_object = GenericForeignKey('content_type', 'object_id')
    objects = GenericManager()


class AbstractNullableGenericObject(models.Model):
    """Abstract model class for a generic object that's optional."""

    class Meta:
        abstract = True

    content_type = models.ForeignKey('contenttypes.ContentType', blank=True,
                                     null=True, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField(db_index=True, unique=False,
                                            blank=True, null=True)
    content_object = GenericForeignKey('content_type', 'object_id')

    objects = GenericManager()