每当我尝试从 django admin 访问我的模型“Youtube”时,它都会向我显示此错误。我感觉到我在方法YoutubeAdmin内部搞砸了getCountry。我该如何解决这个问题?找不到办法。它 model Youtube doesn't have a filed getCountry在错误中说。
我的模型:
class Youtube(models.Model):
link = models.CharField(max_length=2000)
scrap_interval_hour = models.IntegerField(default=8)
last_scrapped_datetime = models.DateTimeField(blank=True, null=True)
is_feed = models.BooleanField(default=False)
created_date = models.DateField(
auto_now_add=True)
# Foriegn Key
country = models.ForeignKey(Country, on_delete=models.CASCADE)
class Meta:
ordering = ('created_date', )
行政
from django.contrib import admin
from fpn.models import Youtube
from datetime import timedelta
class YoutubeAdmin(admin.ModelAdmin):
def get_fields(self, request, youtube=None):
fields = super(YoutubeAdmin, self).get_fields(request, youtube)
fields.remove('last_scrapped_datetime')
if youtube:
fields.remove('country')
return fields
model = Youtube
list_per_page = 10
list_display = ('link', 'is_feed',
'getCountry', 'last_scrapped_datetime')
list_filter = ('country', 'is_feed', )
def getCountry(self, obj):
return "\n".join([coun.name for coun in obj.country.all()])
烙印99
相关分类