from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable, BaseBox


"""
from django.db.models import get_model
model = get_model('myapp', 'modelA')
model.objects.filter(**kwargs)

(Pdb)  models.get_models()[15]._meta.local_fields[0].verbose_name
u'ID'
(Pdb)  models.get_models()[15]._meta.local_fields[0].name
u'id'
"""

try:
    OPPS_APPS = tuple([(app._meta.app_label, u"{0} - {1}".format(
        app._meta.app_label, app._meta.object_name))
        for app in models.get_models() if 'opps.' in app.__module__])
except ImportError:
    OPPS_APPS = tuple([])


class QuerySet(Publishable):
    name = models.CharField(_(u"Dynamic queryset name"), max_length=140)
    slug = models.SlugField(
        _(u"Slug"),
        db_index=True,
        max_length=150,
        unique=True,
    )

    model = models.CharField(_(u'Model'), max_length=150, choices=OPPS_APPS)
    order = models.CharField(_('Order'), max_length=2, choices=(
        ('-', 'DESC'), ('', 'ASC')))


class DynamicBox(BaseBox):

    dynamicqueryset = models.ForeignKey(
        'boxes.QuerySet',
        verbose_name=_(u'Query Set')
    )

from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable, BaseBox


try:
    OPPS_APPS = tuple([(u"{0}.{1}".format(
        app._meta.app_label, app._meta.object_name), u"{0} - {1}".format(
            app._meta.app_label, app._meta.object_name))
        for app in models.get_models() if 'opps.' in app.__module__])
except ImportError:
    OPPS_APPS = tuple([])


class QuerySet(Publishable):
    name = models.CharField(_(u"Dynamic queryset name"), max_length=140)
    slug = models.SlugField(
        _(u"Slug"),
        db_index=True,
        max_length=150,
        unique=True,
    )

    model = models.CharField(_(u'Model'), max_length=150, choices=OPPS_APPS)
    limit = models.PositiveIntegerField(_(u'Limit'))
    order = models.CharField(_('Order'), max_length=1, choices=(
        ('-', 'DESC'), ('+', 'ASC')))


class DynamicBox(BaseBox):

    dynamicqueryset = models.ForeignKey(
        'boxes.QuerySet',
        verbose_name=_(u'Query Set')
    )

Fix OPPS_APPS, get object_name in dropdawn
Fix OPPS_APPS, get object_name in dropdawn

  from django.db import models
  from django.utils.translation import ugettext_lazy as _
  
  from opps.core.models import Publishable, BaseBox
  
  
- """
- from django.db.models import get_model
- model = get_model('myapp', 'modelA')
- model.objects.filter(**kwargs)
- 
- (Pdb)  models.get_models()[15]._meta.local_fields[0].verbose_name
- u'ID'
- (Pdb)  models.get_models()[15]._meta.local_fields[0].name
- u'id'
- """
- 
  try:
-     OPPS_APPS = tuple([(app._meta.app_label, u"{0} - {1}".format(
+     OPPS_APPS = tuple([(u"{0}.{1}".format(
+         app._meta.app_label, app._meta.object_name), u"{0} - {1}".format(
-         app._meta.app_label, app._meta.object_name))
+             app._meta.app_label, app._meta.object_name))
          for app in models.get_models() if 'opps.' in app.__module__])
  except ImportError:
      OPPS_APPS = tuple([])
  
  
  class QuerySet(Publishable):
      name = models.CharField(_(u"Dynamic queryset name"), max_length=140)
      slug = models.SlugField(
          _(u"Slug"),
          db_index=True,
          max_length=150,
          unique=True,
      )
  
      model = models.CharField(_(u'Model'), max_length=150, choices=OPPS_APPS)
+     limit = models.PositiveIntegerField(_(u'Limit'))
-     order = models.CharField(_('Order'), max_length=2, choices=(
+     order = models.CharField(_('Order'), max_length=1, choices=(
-         ('-', 'DESC'), ('', 'ASC')))
+         ('-', 'DESC'), ('+', 'ASC')))
  
  
  class DynamicBox(BaseBox):
  
      dynamicqueryset = models.ForeignKey(
          'boxes.QuerySet',
          verbose_name=_(u'Query Set')
      )
  
Fix OPPS_APPS, get object_name in dropdawn
## Code Before:
from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable, BaseBox


"""
from django.db.models import get_model
model = get_model('myapp', 'modelA')
model.objects.filter(**kwargs)

(Pdb)  models.get_models()[15]._meta.local_fields[0].verbose_name
u'ID'
(Pdb)  models.get_models()[15]._meta.local_fields[0].name
u'id'
"""

try:
    OPPS_APPS = tuple([(app._meta.app_label, u"{0} - {1}".format(
        app._meta.app_label, app._meta.object_name))
        for app in models.get_models() if 'opps.' in app.__module__])
except ImportError:
    OPPS_APPS = tuple([])


class QuerySet(Publishable):
    name = models.CharField(_(u"Dynamic queryset name"), max_length=140)
    slug = models.SlugField(
        _(u"Slug"),
        db_index=True,
        max_length=150,
        unique=True,
    )

    model = models.CharField(_(u'Model'), max_length=150, choices=OPPS_APPS)
    order = models.CharField(_('Order'), max_length=2, choices=(
        ('-', 'DESC'), ('', 'ASC')))


class DynamicBox(BaseBox):

    dynamicqueryset = models.ForeignKey(
        'boxes.QuerySet',
        verbose_name=_(u'Query Set')
    )

## Instruction:
Fix OPPS_APPS, get object_name in dropdawn
## Code After:
from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable, BaseBox


try:
    OPPS_APPS = tuple([(u"{0}.{1}".format(
        app._meta.app_label, app._meta.object_name), u"{0} - {1}".format(
            app._meta.app_label, app._meta.object_name))
        for app in models.get_models() if 'opps.' in app.__module__])
except ImportError:
    OPPS_APPS = tuple([])


class QuerySet(Publishable):
    name = models.CharField(_(u"Dynamic queryset name"), max_length=140)
    slug = models.SlugField(
        _(u"Slug"),
        db_index=True,
        max_length=150,
        unique=True,
    )

    model = models.CharField(_(u'Model'), max_length=150, choices=OPPS_APPS)
    limit = models.PositiveIntegerField(_(u'Limit'))
    order = models.CharField(_('Order'), max_length=1, choices=(
        ('-', 'DESC'), ('+', 'ASC')))


class DynamicBox(BaseBox):

    dynamicqueryset = models.ForeignKey(
        'boxes.QuerySet',
        verbose_name=_(u'Query Set')
    )
