Django : Unable to import model from another App -


i hoping seek assistance on problem i'm having. i'm still learning django (and python) , come across particular issue i'm unable locate answer for. i've created new app called "news" , setup model app. using admin interface have created data. "pages" app, i'm trying import news_article class , getting error no module named news.models.

i struggling see what's going wrong here.

any assistance appreciated.

dir structure

bolton_gc [folder] - bolton_gc [folder]   - news [folder]     - migrations [folder]     - __init__.py     - __init__.pyc     - admin.py     - admin.pyc     - models.py     - models.pyc     - tests.py     - views.py   - pages [folder]     - migrations [folder]     - __init__.py     - __init__.pyc     - admin.py     - admin.pyc     - models.py     - models.pyc     - tests.py     - views.py     - views.pyc   - static [folder]   - templates [folder]   - __init__.py   - __init__.pyc   - settings.py   - settings.pyc   - urls.py   - urls.pyc   - wsgi.py   - wsgi.pyc - db.sqlite3 - manage.py 

news\model.py

from django.db import models datetime import datetime  class news_article(models.model):     class meta:         ordering = ['news_datetime_submitted']     news_title = models.charfield(max_length=75, verbose_name="news title")     news_text = models.charfield(max_length=300, verbose_name="news text")     news_active = models.booleanfield(default=true, verbose_name="news active")     news_datetime_submitted = models.datetimefield(default=datetime.now(), verbose_name="news date")      def __str__(self):         return self.news_title 

pages\views.py

from django.shortcuts import httpresponse, get_object_or_404, render models import page, announcement, menu, sub_menu django.core.exceptions import objectdoesnotexist news.models import news_article import pdb  # helper functions  def get_announcement():     try:         return announcement.objects.get(announcement_active=true)     except objectdoesnotexist:         return none  def clean_url(dirtyurl, badlist):     item in badlist:         dirtyurl = dirtyurl.replace(item,'')     return dirtyurl[1:-1]  # view functions  def page(request):     rdict = {}     path = clean_url(request.path, ['"', "'"]) #    pdb.set_trace()     p = get_object_or_404(page, urlconf_text=path)     rdict['p'] = p     announcement = get_announcement()     if not announcement == none:         rdict['announcement'] = announcement     rdict['sitenav'] = path     rdict['menu'] = menu.objects.all().order_by('menu_position')     return render(request, 'en/public/page.html', rdict) 

error

importerror @ /home/  no module named news.models  request method:     request url:    http://127.0.0.1:8000/home/ django version:     1.8.2 exception type:     importerror exception value:      no module named news.models  exception location:     c:\me\websites\bolton_gc\bolton_gc\pages\views.py in <module>, line 4 python executable:  c:\python27\python.exe python version:     2.7.9 python path:      ['c:\\me\\websites\\bolton_gc',  'c:\\python27\\lib\\site-packages\\setuptools-18.0.1-py2.7.egg',  'c:\\windows\\system32\\python27.zip',  'c:\\python27\\dlls',  'c:\\python27\\lib',  'c:\\python27\\lib\\plat-win',  'c:\\python27\\lib\\lib-tk',  'c:\\python27',  'c:\\python27\\lib\\site-packages']  server time:    tue, 14 jul 2015 13:21:14 +0100 

switch

from news.models import news_article 

to

from bolton_gc.news.models import news_article 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -