Including new app causing AttributeError: 'str' object has no attribute '_meta' in Python/Django app -
using python 2.7 , django 1.9.9 i'm getting following error when try in include app developing within installed_aps
traceback (most recent call last): file "manage.py", line 22, in <module> execute_from_command_line(sys.argv) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line utility.execute() file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute self.fetch_command(subcommand).run_from_argv(self.argv) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 398, in execute self.check() file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check include_deployment_checks=include_deployment_checks, file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks new_errors = check(app_configs=app_configs) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models errors.extend(model.check(**kwargs)) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 1180, in check errors.extend(cls._check_long_column_names()) file "/var/www/cltc/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 1631, in _check_long_column_names m2m in f.remote_field.through._meta.local_fields: attributeerror: 'str' object has no attribute '_meta'
this is, believe being caused wrong in models.py looks this:
from django.db import models django.contrib.auth.models import user django.conf import settings import datetime django.core.exceptions import validationerror django.utils.translation import ugettext_lazy _ class category(models.model): name = models.charfield('category', max_length=30) age = models.integerfield('member age @ start of subscription', default=18) class subscription(models.model): name = models.charfield('subscription', max_length=30) cost = models.decimalfield('price', max_digits=6, decimal_places=2, default=0.00) start = models.datefield('start date') end = models.datefield('end date') category = models.manytomanyfield( category, through = 'subscritptioncategory', related_name = 'category', verbose_name = 'membership category', help_text = 'membership categories included in subscription' ) def __unicode__(self): return u'%s' % (self.name) def clean (self): if self.start > self.end: raise validationerror( _("start date must earlier end date"), ) def is_live(self): if self.end >= datetime.datetime.now().date(): return true else: return false class subscriptioncategory (models.model): subscription = models.foreignkey( subscription, verbose_name = 'subscription', help_text = 'a class of membership (which include several members, eg family).', ) category = models.foreignkey( category, verbose_name = 'category', help_text = 'a class of member (eg adult)', )
any welcome
you have typo in declaration of through
attribute of subscription.category: "subscritptioncategory" rather "subscriptioncategory". because of that, django can't find model you're referencing.
note since don't define fields on through model, there's not point having it; code simpler, , many of django's functions work better, if didn't define it.
Comments
Post a Comment