# Path: lemon/fields.py
# class ContentTypeChoiceField(ModelChoiceField):
# 
#     def __init__(self, admin_site, *args, **kwargs):
#         self.admin_site = admin_site
#         super(ContentTypeChoiceField, self).__init__(*args, **kwargs)
# 
#     def _get_choices(self):
#         if hasattr(self, '_choices'):
#             return self._choices
#         return ContentTypeChoiceIterator(self.admin_site, self)
#     choices = property(_get_choices, ModelChoiceField._set_choices)


from django import forms
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.forms.formsets import formset_factory
from django.forms.models import BaseInlineFormSet
from django.forms.models import ModelFormMetaclass, _get_foreign_key
from django.utils.translation import ugettext_lazy as _
from .fields import ContentTypeChoiceField

    username = forms.RegexField(
        label=_('Username'),
        max_length=30,
        regex=r'^[\w.@+-]+$',
        help_text=_(
            'Required. 30 characters or fewer. Letters, digits and '
            '@/./+/-/_ only.'
        ),
        error_messages={
            'invalid': _(
                'This value may contain only letters, numbers and @/./+/-/_ '
                'characters.'
            )
        }
    )

    class Meta:
        model = User


class MenuItemForm(forms.ModelForm):

    admin_site = None

    class Meta(object):
        fields = ['content_type', 'name', 'position']

    def __init__(self, *args, **kwargs):
        qs = ContentType.objects.all()

# Path: lemon/fields.py
# class ContentTypeChoiceField(ModelChoiceField):
# 
#     def __init__(self, admin_site, *args, **kwargs):
#         self.admin_site = admin_site
#         super(ContentTypeChoiceField, self).__init__(*args, **kwargs)
# 
#     def _get_choices(self):
#         if hasattr(self, '_choices'):
#             return self._choices
#         return ContentTypeChoiceIterator(self.admin_site, self)
#     choices = property(_get_choices, ModelChoiceField._set_choices)


# Path: lemon/forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.forms.formsets import formset_factory
from django.forms.models import BaseInlineFormSet
from django.forms.models import ModelFormMetaclass, _get_foreign_key
from django.utils.translation import ugettext_lazy as _
from .fields import ContentTypeChoiceField


    username = forms.RegexField(
        label=_('Username'),
        max_length=30,
        regex=r'^[\w.@+-]+$',
        help_text=_(
            'Required. 30 characters or fewer. Letters, digits and '
            '@/./+/-/_ only.'
        ),
        error_messages={
            'invalid': _(
                'This value may contain only letters, numbers and @/./+/-/_ '
                'characters.'
            )
        }
    )

    class Meta:
        model = User


class MenuItemForm(forms.ModelForm):

    admin_site = None

    class Meta(object):
        fields = ['content_type', 'name', 'position']

    def __init__(self, *args, **kwargs):
        qs = ContentType.objects.all()

        content_type = ContentTypeChoiceField(