Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:31:24+00:00 2026-06-08T13:31:24+00:00

I have two model classes in my models.py module in the default location. PythonFinal

  • 0

I have two model classes in my models.py module in the default location.

PythonFinal
    |_   manage.py
    |_  template
    |_ PythonFinal
    |       |_  __init__.py
    |       |_  settings.py
    |       |_  urls.py
    |       |_  swgi.py
    | 
    |      
    |___ fertility
            |_  __init__.py
            |_  models.py
            |_  tests.py
            |_  views.py
            |_  dateUtils.py

I simply want to import the classes into dateUtils.py

from fertility.models import Cycle, Period

if __name__ == '__main__':
    p1 = Period(periodFirstDay='2012-7-26' , periodNumber=4) 

If I run this module I get

ImportError: no module named fertility

If I try to import models from the python commandline I get

import models    
Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "models.py", line 1, in <module>
        from django.db import models
      File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 11, in <module>
        if DEFAULT_DB_ALIAS not in settings.DATABASES:
      File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 184, in inner
        self._setup()
      File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 40, in _setup
        raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
    ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

I added my projects root folder to the PYTHONPATH in ~/.bashrc.
My wsgi.py reads

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PythonFinal.settings")

I do not think it is not a circular import because I get the ImportError instead of a NamingError, and I simply don’t have many imports yet. For obvious reasons I need to be able to import my model to other modules I can unit test or I need another simple workflow that accomplishes the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:31:27+00:00Added an answer on June 8, 2026 at 1:31 pm

    If PythonFinal is in /home/users/jeremy/django/PythonFinal, then /home/users/jeremy/django should be in your PYTHONPATH environment variable, and DJANGO_SETTINGS_MODULE should be set to "PythonFinal.PythonFinal.settings". Then you can use

    from PythonFinal.fertility.models import Cycle, Period
    

    from the Python command line.

    It is, however, more common to have the settings.py file in the same folder as manage.py, and a number of tools and tutorials expect this setup…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes: class Order(models.Model): ... date = models.DateTimeField(blank=True, verbose_name=u'Date add',default=datetime.now) price =
I have two classes: class Translation(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() object =
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I have two very simple classes Submission and Store class Submission(models.Model): title = models.CharField(max_length=50,
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...
I have two model classes, say parent and child. Parents are created first, and
I have two questions. 1: At the moment I have two model classes that
Given two model classes, Foo and Bar , I want Foo to have 3
I have two classes (MVC view model) which inherits from one abstract base class.
I have a hibernate model with two classes, let's say A and B. B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.