from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from threadedcomments.models import ThreadedComment

from django.contrib.gis.db import models

from treemap.instance import Instance


class EnhancedThreadedComment(ThreadedComment):
    """
    This class wraps the ThreadedComment model with moderation specific fields
    """

    # If the comment should be hidden in the default filter view for moderation
    is_archived = models.BooleanField(default=False)

    # We could retrieve this through the GenericForeignKey on ThreadedComment,
    # but it makes things simpler to record instance here.
    instance = models.ForeignKey(Instance)

    def save(self, *args, **kwargs):
        if hasattr(self.content_object, 'instance'):
            self.instance = self.content_object.instance

        super(EnhancedThreadedComment, self).save(*args, **kwargs)

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from threadedcomments.models import ThreadedComment

from django.contrib.gis.db import models


class EnhancedThreadedComment(ThreadedComment):
    """
    This class wraps the ThreadedComment model with moderation specific fields
    """

    # If the comment should be hidden in the default filter view for moderation
    is_archived = models.BooleanField(default=False)

    # We could retrieve this through the GenericForeignKey on ThreadedComment,
    # but it makes things simpler to record instance here.
    instance = models.ForeignKey('treemap.Instance')

    def save(self, *args, **kwargs):
        if hasattr(self.content_object, 'instance'):
            self.instance = self.content_object.instance

        super(EnhancedThreadedComment, self).save(*args, **kwargs)

Fix circular dependency problem with django apps
Fix circular dependency problem with django apps

It looks like translation is importing *all other* django apps in the project
when it is used from treemap. This means that it will load apps that
depend on treemap when it is not finished import treemap. So while it
appears that treemap/otm1_migrator/otm_comments have sane, non-circular
dependencies on each other, the translation app is causing the circle.

I'm pretty sure this is actually a django pattern. Django enjoys
including dynamic apps that walk through installed apps and do magic
stuff. To compensate, they provide this alternative, string-based import
strategy that dynamic apps adhere to.

  from __future__ import print_function
  from __future__ import unicode_literals
  from __future__ import division
  
  
  from threadedcomments.models import ThreadedComment
  
  from django.contrib.gis.db import models
- 
- from treemap.instance import Instance
  
  
  class EnhancedThreadedComment(ThreadedComment):
      """
      This class wraps the ThreadedComment model with moderation specific fields
      """
  
      # If the comment should be hidden in the default filter view for moderation
      is_archived = models.BooleanField(default=False)
  
      # We could retrieve this through the GenericForeignKey on ThreadedComment,
      # but it makes things simpler to record instance here.
-     instance = models.ForeignKey(Instance)
+     instance = models.ForeignKey('treemap.Instance')
  
      def save(self, *args, **kwargs):
          if hasattr(self.content_object, 'instance'):
              self.instance = self.content_object.instance
  
          super(EnhancedThreadedComment, self).save(*args, **kwargs)
  
Fix circular dependency problem with django apps
## Code Before:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from threadedcomments.models import ThreadedComment

from django.contrib.gis.db import models

from treemap.instance import Instance


class EnhancedThreadedComment(ThreadedComment):
    """
    This class wraps the ThreadedComment model with moderation specific fields
    """

    # If the comment should be hidden in the default filter view for moderation
    is_archived = models.BooleanField(default=False)

    # We could retrieve this through the GenericForeignKey on ThreadedComment,
    # but it makes things simpler to record instance here.
    instance = models.ForeignKey(Instance)

    def save(self, *args, **kwargs):
        if hasattr(self.content_object, 'instance'):
            self.instance = self.content_object.instance

        super(EnhancedThreadedComment, self).save(*args, **kwargs)

## Instruction:
Fix circular dependency problem with django apps
## Code After:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from threadedcomments.models import ThreadedComment

from django.contrib.gis.db import models


class EnhancedThreadedComment(ThreadedComment):
    """
    This class wraps the ThreadedComment model with moderation specific fields
    """

    # If the comment should be hidden in the default filter view for moderation
    is_archived = models.BooleanField(default=False)

    # We could retrieve this through the GenericForeignKey on ThreadedComment,
    # but it makes things simpler to record instance here.
    instance = models.ForeignKey('treemap.Instance')

    def save(self, *args, **kwargs):
        if hasattr(self.content_object, 'instance'):
            self.instance = self.content_object.instance

        super(EnhancedThreadedComment, self).save(*args, **kwargs)
