変なふうに、それは前に働いており、今ではない:私は変更する場合「モジュール」オブジェクトは、Djangoのコンソールでサーバーランタイムで呼び出し可能けどOKではありません
Exception Value:
'module' object is not callable
Exception Location: C:\work\Portman\core\models\pmo_review_task.py in save, line 38
:
は、次のエラーを取得"core.models import sc_review_task"を "from core.models import *"に変更すると、エラーメッセージが "global name sc_review_task is not defined"に変更されます。
私はDjangoの管理を実行し、実行している場合:core.modelsから がsc_review_task = sc_review_task()
すべてがOKに見えるインポート - なしエラーメッセージを。
は私が、私は:)髪を失う
pmo_review_taskよこれを理解助けてください(ライン38は "付けたnewtask = sc_review_task()" である):
# -*- coding: utf-8 -*-
from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
from core.models import sc_review_task
class pmo_review_task(models.Model):
project_phase_to_review = models.ForeignKey('project_phase')
creation_date = models.DateTimeField(default=datetime.now())
is_closed = models.BooleanField(default=False,null=False)
review_date = models.DateTimeField(null=True,blank=True)
review_comment = models.TextField(null=True, blank=True)
reviewed_by = models.ForeignKey(User, null=True, blank=True)
is_review_result_ok = models.NullBooleanField(null=True)
scheduled_sc = models.ForeignKey('sc_event', null=True, blank=True)
review_goal = models.ForeignKey('phases')
def __unicode__(self):
return self.project_phase_to_review.project.name
def save(self, *args, **kwargs):
if self.is_closed and self.is_review_result_ok and self.scheduled_sc is None:
raise models.ImproperlyConfigured
if self.is_closed and self.is_review_result_ok is False:
self.project_phase_to_review.is_finished = False
self.project_phase_to_review.is_approved_for_sc = False
self.project_phase_to_review.save()
if self.is_closed and self.is_review_result_ok and self.scheduled_sc:
if self.scheduled_sc.has_taken_place is True:
raise Exception("Cannot assign a task to a SC event that has taken place")
#update reviewed project to indicate it has been saved
self.project_phase_to_review.is_approved_for_sc = True
self.project_phase_to_review.save()
#create sc_review_talk
newtask = sc_review_task()
newtask.project_phase_to_review = self.project_phase_to_review
newtask.sc_event_to_review_at = self.scheduled_sc
newtask.review_goal = self.review_goal
newtask.is_closed = False
newtask.save()
#call real save operation
super(pmo_review_task,self).save(*args, **kwargs)
class Meta:
app_label = 'core'
sc_review_task:
# -*- coding: utf-8 -*-
from django.db import models
from core.models import project_phase
class sc_review_task(models.Model):
sc_event_to_review_at = models.ForeignKey('sc_event', null=False)
project_phase_to_review = models.ForeignKey('project_phase', null=False)
review_goal = models.ForeignKey('phases',related_name="target_review_goal")
is_closed = models.BooleanField(default=False)
review_decision_phase = models.ForeignKey('phases', null=True, blank=True,related_name="sc_decided_phase")
review_decision_comment = models.TextField(null=True, blank=True)
def __unicode__(self):
return self.project_phase_to_review.project
def save(self, *args, **kwargs):
super(sc_review_task,self).save(*args, **kwargs)
if self.is_closed and self.project_phase_to_review.phase == self.review_decision_phase:
self.project_phase_to_review.is_approved_for_sc = False
self.project_phase_to_review.is_finished = False
self.project_phase_to_review.is_closed = False
self.project_phase_to_review.save()
elif self.is_closed:
self.project_phase_to_review.is_closed = True
self.project_phase_to_review.save()
new_phase = project_phase()
new_phase.project = self.project_phase_to_review.project
new_phase.phase = self.review_decision_phase
new_phase.save()
class Meta:
app_label = 'core'
各クラスは/ models /内の独自のファイルにあり、ここにはinit .py:
がありますfrom divisions import divisions
from django.db import models
from groups import groups
from phases import phases
from pmo_review_task import pmo_review_task
from priorities import priorities
from progress_indicator import progress_indicator
from project import project
from project_imported_from_excel import project_imported_from_excel
from project_phase import project_phase
from project_phase_history import project_phase_history
from project_status_submit_form import project_status_submit_form
from roles import roles
from sc_event import sc_event
from sc_review_task import sc_review_task
from milestone import milestone
from milestone import milestone_history
__all__ = ['divisions',
'groups',
'phases',
'pmo_review_task',
'priorities',
'progress_indicator',
'project',
'project_imported_from_excel',
'project_phase',
'project_phase_history',
'project_status_submit_form',
'roles',
'sc_event',
'sc_review_task',
'milestone',
'milestone_history']
それはモデルのために__init__.pyにsc_review_taskからsc_review_taskとしてインポートされるとき、なぜそれがsc_review_task.sc_review_taskすべきですか? pmo_review_taskが作成されたときと同じように動作します。 – abolotnov
"sc_review_task"モジュールをインポートします。それが彼の名前になるでしょう。 _Inside_あなたはクラス "sc_review_task()"を持っています。それでアドレスは 'sc_review_task.sc_review_task()'です( 'module_name.class_name.method_name()'のように) – Deviacium
ところで、 'newtask = sc_review_task()'の使用を強くお勧めするならば、 from sc_review_task import sc_review_task'(ただし、sc_review_taskモジュール内のすべてのクラス/メソッドに対してこれを行う必要があります。) – Deviacium