18

これは非常に奇妙なエラーです。herokuサーバーでのみ受信します。

私のモデルは次のとおりです。

# 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

運用サーバーの管理サイトからニュース項目にアクセスしようとすると、次のエラーが表示されます (開発サーバーではすべて正常に動作します)。

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)))

実稼働環境と開発環境で同じバージョンの django (1.5.4) と python (2.7.2) を実行しています。

私の本番サーバーは Heroku です

エラーを引き起こす可能性のあるアイデアはありますか?

更新

admin.py の設定は次のとおりです。

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)
4

6 に答える 6

7

これが発生する可能性のある状況に追加します。どのモデルにも見つからなかったフィールドを検索しました。

コードを検索すると、クエリセットにそのようなフィールドで注釈を付けてから、そのクエリセット__inを別の検索として (他の複雑なクエリに沿って) フィードしていることがわかりました。

私の回避策は、その注釈付きクエリセットを変更して ID を返し、それを使用することでした。この特定のケースでは、結果は常に小さいため、ID のリストを渡すことは問題ではありませんでした。

于 2015-06-02T08:01:00.890 に答える