Đây là một lỗi rất lạ. Tôi chỉ nhận được nó trên máy chủ heroku của tôi.FieldError: Không thể giải quyết từ khóa 'XXXX' vào trường
Sau đây là cách mô hình của tôi là:
# Abstract Model
class CommonInfo(models.Model):
active = models.BooleanField('Enabled?', default=False)
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class Country(CommonInfo):
name = models.CharField('Country Name', db_index=True, max_length=200, help_text='e.g. France')
official_name = models.CharField('Official Name', max_length=400, blank=True, help_text='e.g. French Republic')
population = models.IntegerField('Population', help_text='Population must be entered as numbers with no commas or separators, e.g. 39456123', null=True, blank=True)
alpha2 = models.CharField('ISO ALPHA-2 Code', max_length=2, blank=True)
class News(CommonInfo):
title = models.CharField('Title', max_length=250)
slug = models.CharField('slug', max_length=255, unique=True)
body = models.TextField('Body', null=True, blank=True)
excerpt = models.TextField('Excerpt', null=True, blank=True)
author = models.ForeignKey(Author)
country = models.ManyToManyField(Country, null=True, blank=True)
def __unicode__(self):
return self.title
Khi tôi cố gắng truy cập vào mục Tin tức từ quản trị trang web trên máy chủ sản xuất của tôi, tôi nhận được lỗi này (tất cả mọi thứ hoạt động tốt trên máy chủ dev của tôi):
FieldError: Cannot resolve keyword 'news' into field. Choices are: active, alpha2, date_created, date_updated, id, name, official_name, population
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 687, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1271, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1139, in add_filter
process_extras=process_extras)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1337, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
Tôi chạy cùng phiên bản django (1.5.4) và python (2.7.2) trên môi trường sản xuất và phát triển của mình.
máy chủ sản xuất của tôi là Heroku
Bất kỳ ý tưởng những gì có thể kích hoạt lỗi?
CẬP NHẬT:
admin.py cấu hình như sau:
from django.contrib import admin
from APP.models import Country, News
class NewsForm(ModelForm):
class Meta:
model = News
class NewsAdmin(ModelAdmin):
form = NewsForm
search_fields = ['title',
'country__name']
list_filter = ('country',
'active'
)
list_per_page = 30
list_editable = ('active',)
list_display = ('title',
'active'
)
list_select_related = True
prepopulated_fields = {"slug": ("title",)}
admin.site.register(Country)
admin.site.register(News, NewsAdmin)
Điều này xảy ra khi bạn truy cập quản trị viên? Bạn có thể đăng mã tập tin admin.py của mình không? – jproffitt
Bất cứ nơi nào tôi cần truy cập vào mối quan hệ ManyToMany. – AlirezaJ
Bạn có thể đăng mã có liên quan tạo ra lỗi không? – jproffitt