taggit import error when using django with zinnia

1.8k views Asked by At

I have a django app in which i am trying to use django-taggit and zinnia blog, below are my settings and code

directory structure

test_app
   apps
     app_one
         __init__.py
         views.py
         forms.py   
         urls.py
         models
             taggit_custom.py    
     app_two
   settings
     local_settings.py
   manage.py

local_settings.py

INSTALLED_APPS = (
   'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'south',
    'taggit',
    'zinnia',
)

taggit_custom.py

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from taggit.models import TaggedItem

class CustomModel_one(models.Model):
    ......
    ......

So from the above i am trying to use django-zinnia-blog for my site as blog, but i want to use django-taggit instead of tagging, and just given a try to use taggit, so installed taggit by pip install django-taggit

But when i tried to use the taggit application as above like from taggit.models import TaggedItem its displaying the below error

Note: Infact no imports from taggit module like

from taggit.models import TaggedItem
from taggit.managers import TaggableManager
from taggit.forms........ etc.,

are working even though the application is installed(Also checked by pip freeze and taggit is there :))

result

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x9902e8c>>
Traceback (most recent call last):
  File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
    self.validate(display_num_errors=True
  ......
  ......
 File "/home/user/name/virtualenvironment/apps/test_app/models/taggit_custom.py", line 4, in <module>
    from taggit.models import TaggedItem
ImportError: No module named models

So can anyone please let me know why taggit importing is not working even though taggit has been installed ?

Edited

Also when i tried something like below

(Inside virtual env)

import taggit
print dir(taggit.models)

result

['Aggregate', 'AutoField', 'Avg', 'BLANK_CHOICE_DASH', 'BLANK_CHOICE_NONE', 'BigIntegerField', 'BooleanField', 'CASCADE', 'CharField', 'CommaSeparatedIntegerField', 'Count', 'DO_NOTHING', 'DateField', 'DateTimeField', 'DecimalField', 'DictWrapper', 'EmailField', 'F', 'Field', 'FieldDoesNotExist', 'FileField', 'FilePathField', 'FloatField', 'ForeignKey', 'GenericIPAddressField', 'IPAddressField', 'ImageField', 'ImproperlyConfigured', 'IntegerField', 'Manager', 'ManyToManyField', 'ManyToManyRel', 'ManyToOneRel', 'Max', 'Min', 'Model', 'NOT_PROVIDED', 'NullBooleanField', 'ObjectDoesNotExist', 'OneToOneField', 'OneToOneRel', 'PROTECT', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'ProtectedError', 'Q', 'QueryWrapper', 'SET', 'SET_DEFAULT', 'SET_NULL', 'SlugField', 'SmallIntegerField', 'StdDev', 'SubfieldBase', 'Sum', 'TextField', 'TimeField', 'URLField', 'Variance', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'aggregates', 'base', 'capfirst', 'clean_ipv6_address', 'connection', 'constants', 'copy', 'curry', 'datetime', 'decimal', 'deletion', 'exceptions', 'expressions', 'fields', 'force_text', 'forms', 'get_app', 'get_apps', 'get_model', 'get_models', 'is_iterator', 'loading', 'manager', 'math', 'options', 'parse_date', 'parse_datetime', 'parse_time', 'permalink', 'proxy', 'query', 'query_utils', 'register_models', 'related', 'settings', 'signals', 'six', 'smart_text', 'sql', 'tee', 'timezone', 'total_ordering', 'unicode_literals', 'validators', 'warnings', 'wraps']

so from the above whether taggit is working/installed ? and but why its showing an error when i tried from taggit.models import TaggedItem ?

1

There are 1 answers

0
Abid Hasan Muin On

I know it's a 7 year old thread. But I'm sharing my experience for the future purpose, someone might be benefited from it. I've just faced similar problem. I installed django-taggit (current version is 1.3.0) in my venv. I added it to INSTALLED_APPS. Later on I tried to import in my models.py. But it was showing import error. I restarted my VSCode. After a couple of minutes, like 1-2 minutes, it was fixed automatically. IDK, it was weird. Maybe it needs some time to get working.

So, if you installed it correctly (in the right env) then it should work. Just give it some time, maybe restart your IDE and try again.