from django.db.models.fields.related import ForeignKey

from .forms import AssetField


class AssetKey(ForeignKey):

    def formfield(self, **kwargs):
        kwargs['form_class'] = AssetField
        return super(AssetKey, self).formfield(**kwargs)

    def value_from_object(self, obj):
        asset_obj = getattr(obj, self.name, None)
        if not asset_obj:
            return None
        return [asset_obj.id, asset_obj._meta.module_name]


from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])

from __future__ import unicode_literals, absolute_import
import django
from django.db.models.fields.related import ForeignKey

from .forms import AssetField


class AssetKey(ForeignKey):

    def formfield(self, **kwargs):
        kwargs['form_class'] = AssetField
        return super(AssetKey, self).formfield(**kwargs)

    def value_from_object(self, obj):
        asset_obj = getattr(obj, self.name, None)
        if not asset_obj:
            return None
        return [asset_obj.id, asset_obj._meta.module_name]


# This is only required for Django version < 1.7 suing South for migrations
if django.VERSION[:2] < (1, 7):
    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])

Fix south introspection rule for custom AssetField
Fix south introspection rule for custom AssetField

+ from __future__ import unicode_literals, absolute_import
+ import django
  from django.db.models.fields.related import ForeignKey
  
  from .forms import AssetField
  
  
  class AssetKey(ForeignKey):
  
      def formfield(self, **kwargs):
          kwargs['form_class'] = AssetField
          return super(AssetKey, self).formfield(**kwargs)
  
      def value_from_object(self, obj):
          asset_obj = getattr(obj, self.name, None)
          if not asset_obj:
              return None
          return [asset_obj.id, asset_obj._meta.module_name]
  
  
+ # This is only required for Django version < 1.7 suing South for migrations
+ if django.VERSION[:2] < (1, 7):
- from south.modelsinspector import add_introspection_rules
+     from south.modelsinspector import add_introspection_rules
- add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])
+     add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])
  
Fix south introspection rule for custom AssetField
## Code Before:
from django.db.models.fields.related import ForeignKey

from .forms import AssetField


class AssetKey(ForeignKey):

    def formfield(self, **kwargs):
        kwargs['form_class'] = AssetField
        return super(AssetKey, self).formfield(**kwargs)

    def value_from_object(self, obj):
        asset_obj = getattr(obj, self.name, None)
        if not asset_obj:
            return None
        return [asset_obj.id, asset_obj._meta.module_name]


from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])

## Instruction:
Fix south introspection rule for custom AssetField
## Code After:
from __future__ import unicode_literals, absolute_import
import django
from django.db.models.fields.related import ForeignKey

from .forms import AssetField


class AssetKey(ForeignKey):

    def formfield(self, **kwargs):
        kwargs['form_class'] = AssetField
        return super(AssetKey, self).formfield(**kwargs)

    def value_from_object(self, obj):
        asset_obj = getattr(obj, self.name, None)
        if not asset_obj:
            return None
        return [asset_obj.id, asset_obj._meta.module_name]


# This is only required for Django version < 1.7 suing South for migrations
if django.VERSION[:2] < (1, 7):
    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^fancypages\.assets\.fields\.AssetKey"])
