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

  • SEARCH
  • Home
  • 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 6705469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:24:27+00:00 2026-05-26T07:24:27+00:00

I have several Django apps, all within one project directory. Each app has a

  • 0

I have several Django apps, all within one project directory. Each app has a models.py file with a bunch of models. I have been importing models from one app to the other with no problem, specifically to create a new model with a foreign key field, pointing to the model in the other app. No problem so far.

I decided to create a new model. It has 4 ForeignKey fields, each pointing to a different model in a different app. Straight forward. However, when I try to use south to migrate the schema to the database, it tells me that it can’t import my models. Why?!

So, this is my new model:

class Action_Tracker(models.Model):
    dateOfAction = models.DateField(verbose_name = 'Date of Action')
    user = models.CharField(max_length=30, verbose_name = 'Action completed by')
    sys = models.ForeignKey(System, verbose_name='For System')
    wo = models.ForeignKey(Work_Order, verbose_name='Associated WO', blank=True, null=True)
    inv = models.ForeignKey(Invoice, verbose_name = 'Associated Invoice', blank=True, null=True)
    subdT = models.ForeignKey(SUBD_Tracker, verbose_name = 'Associated SUBD Tracker', blank=True, null=True)
    notes = models.TextField(verbose_name='Notes of Action', blank=True, null=True)

    def __unicode__(self):
        return u'%s -- %s' % (self.dateOfAction, self.notes)

    class Meta:
        orering = ['dateOfAction']

At the top of this models.py file I have the following imports:

from django.db import models
from django.forms import ModelForm, forms
from staff.models import Employee, Position
from work_orders.models import Work_Order, SUBD_Tracker
from invoices.models import Invoice

From what I can tell, I am importing these correctly. However, when I try to do a schema migration, I get the following error:

File "/srv/www/cpm/../cpm/systems/models.py", line 4, in <module>
  from work_orders.models import Work_Order, SUBD_Tracker
File "/srv/www/cpm/work_orders/models.py", line 5, in <module>
  from systems.models import System
File "/srv/www/cpm/systems/models.py", line 4, in <module>
  from work_orders.models import Work_Order, SUBD_Tracker
ImportError: cannot import name Work_Order

Any idea what is going wrong here??

Thanks

EDIT — Upon Request

I’m posting the work_order models.py code as requested (at least, the relevant parts):

from django.db import models
from django.forms import ModelForm, forms
from django import forms
from products.models import Product
from systems.models import System
from labour.models import Labour_Costs
from staff.models import Employee
from datetime import date
import datetime

class Work_Order(models.Model):
    IS_COMPLETE_CHOICES = (
        ('Y', 'Yes'),
        ('N', 'No'),
    )

    INVOICE_CREATED_CHOICES = (
        ('Y', 'Yes, mark WO complete and generate invoice (if applicable)'),
        ('N', 'No, just save these changes'),
    )

    WO_TYPE_CHOICES = (
        ('M', 'Mechanical'),
        ('I', 'Install'),
        ('S', 'Show'),
        ('R', 'Service'),
        ('B', 'Blow down'),
        ('U', 'Start up'),
    )

    woID = models.CharField(max_length = 25, primary_key = True, verbose_name = 'Work Order ID')
    woType = models.CharField(max_length = 2, verbose_name = 'WO Type', default='R', choices = WO_TYPE_CHOICES)
    systemID = models.ForeignKey(System, verbose_name = 'System ID')
    notesToCrew = models.TextField(blank = True, null = True, verbose_name = 'Notes to Crew')
    dateWOCreated = models.DateField(blank = True, null = True, default=datetime.date.today(), verbose_name = 'Date Created')
    dateWORequired = models.DateField(blank = True, null = True, verbose_name = 'Date Required')
    dateCompleted = models.DateField(blank = True, null = True, verbose_name = 'Date Completed')
    numDays = models.DecimalField(max_digits = 3, decimal_places = 0, verbose_name = 'Number of Days to Complete', blank = True, null = True)
    numHours = models.DecimalField(max_digits = 3, decimal_places = 2, verbose_name = 'Number of Hours to Complete', blank = True, null = True)
    isComplete = models.CharField (max_length = 3, default = 'N', verbose_name = 'Set WO as Completed?', choices = IS_COMPLETE_CHOICES)
    isScheduled = models.CharField (max_length = 3, default = 'N', verbose_name = 'Is WO scheduled?', choices = IS_COMPLETE_CHOICES)
    isReqSoon = models.BooleanField(default=False, verbose_name='Is WO Required soon') #This flag will be set in a function to indicate that the WO is reqd within the current week/few days, whatever
    problemDescription = models.TextField(verbose_name = 'Problem Description', blank = True, null = True)
    resolution = models.TextField(verbose_name = 'Resolution', blank = True, null = True)
    serviceFromBD = models.TextField(verbose_name = 'Service issues noticed', blank = True, null = True)
    serviceFromBDEstTime = models.DecimalField(max_digits = 3, decimal_places = 2, verbose_name = 'Est. Time to Repair', blank = True, null = True)
    numWorkers = models.DecimalField(max_digits = 3, default=1, decimal_places = 0, verbose_name = 'Number of Workers Required', blank = True, null = True)
    invoiceCreated = models.CharField (max_length = 3, default = 'N', verbose_name = 'Generate Invoice?', choices = INVOICE_CREATED_CHOICES)

    def __unicode__(self):
        return u'%s - %s' % (self.woID, self.systemID.systemAddress)

    class Meta:
        ordering = ['woID']


class SUBD_Tracker(models.Model):
    SUBD_CHOICES = (
        ('U', 'Startup'),
        ('B', 'Blowdown'),
    )

    sys = models.ForeignKey(System, verbose_name = 'Related System')
    subd = models.CharField(max_length=1, verbose_name = 'SU or BD', choices = SUBD_CHOICES)
    ssn = models.CharField(max_length=5, verbose_name = 'Season')
    approved = models.BooleanField(verbose_name = 'Approved', default = False)
    declined = models.BooleanField(verbose_name = 'Declined', default = False)
    cancelled = models.BooleanField(verbose_name = 'Cancel', default = False)
    firstNoticeSent = models.BooleanField(verbose_name = 'First Notice Sent?', default = False)
    secondNoticeSent = models.BooleanField(verbose_name = 'Second Notice Sent?', default = False)
    wo = models.ForeignKey(Work_Order, verbose_name = 'Related WO', blank = True, null = True)

    def __unicode__(self):
        if self.subd == 'U':
            return u'%s: Startup - %s' % (self.sys, self.ssn)
        else:
            return u'%s: Blowdown - %s' % (self.sys, self.ssn)

    class Meta:
        ordering = ['sys']
  • 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-05-26T07:24:28+00:00Added an answer on May 26, 2026 at 7:24 am

    If you read through the ForeignKey documentation, you’ll see that the first argument can be a string. This allows you to create your foreign keys without having to import, getting around the circular reference problem.

    So your model would then become:

    class Action_Tracker(models.Model):
        dateOfAction = models.DateField(verbose_name = 'Date of Action')
        user = models.CharField(max_length=30, verbose_name = 'Action completed by')
        sys = models.ForeignKey('systems.System', verbose_name='For System')
        wo = models.ForeignKey('work_orders.Work_Order', verbose_name='Associated WO', blank=True, null=True)
        inv = models.ForeignKey('invoices.Invoice', verbose_name = 'Associated Invoice', blank=True, null=True)
        subdT = models.ForeignKey('work_orders.SUBD_Tracker', verbose_name = 'Associated SUBD Tracker', blank=True, null=True)
        notes = models.TextField(verbose_name='Notes of Action', blank=True, null=True)
    
        def __unicode__(self):
            return u'%s -- %s' % (self.dateOfAction, self.notes)
    
        class Meta:
            ordering = ['dateOfAction']
    

    No import statements required!

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

Sidebar

Related Questions

I have a django project with 2 apps like this: ## tags app, models.py
I am working on a django project which will contain several apps. Each app
Django newbie here, I have several types of models, in each of them the
I have Django project on Dreamhost server which has several views that returns Json
I have several Customer s who book Appointment s. Each Appointment has exactly one
Assume I have 3 Models: City, Area, Entry. Each city has several Areas and
Let's say i have several different models in django project. Now i need to
I have ceated several django apps and stuffs for my own fun and so
I have a Django app that needs to pull the follower_count information from several
There have been several MongoDB and Django posts - one of the most recent

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.