我一直在使用Django的ORM(django 1.3)進行wtf時刻處理。在開發服務器:Django查詢從shell中運行,但不是dev服務器?在dev服務器中引發FieldError
# in x.modules.training.models
class Training(x.models.Base):
trainers = models.ManyToManyField(staff_models.Staff, related_name='trainings_taught')
people = models.ManyToManyField(x.models.Person, related_name='trainings_attended')
# in any view
from x.modules.staff.models import Staff
from x.models import Person
Staff.objects.filter(trainings_taught=12)
# [<Staff: Staff object>]
Person.objects.filter(trainings_attended=12)
# FieldError: Cannot resolve keyword 'trainings_attended' into field. Choices are: address, comment, contact_for_farmers, email, farmer, first_name, id, last_name, mobile_number, modified_by, modified_timestamp, national_id, passport_number, region, version
# Why would it work for one ManyToMany and not the other?
而在一般的蟒蛇殼,(注意X是Python路徑上),無論什麼兩個導入線的順序,這兩個查詢運行得很好。
>>> from x.models import *
>>> from x import modules
>>> Person.objects.filter(trainings_attended=12)
>>> modules.staff.models.Staff.objects.filter(trainings_taught=12)
這怎麼可能?
你有任何類從繼承培訓? – zsong 2011-03-28 20:17:32
工作人員確實從Person繼承(OneToOne繼承),但它從shell運行的事實似乎排除了模型驗證問題(並且模型確實通過了驗證)。 – Eloff 2011-03-29 00:02:45