遇到下面的错误,不太确定是什么问题。在运行 python manage.py migrate 之前我没有注意到模式中缺少电话字段。现在,当我尝试运行服务器时,出现以下错误。我确实对模态进行了更改(添加了电话字段)并尝试运行 python manage.py migrate。我以为它会重新迁移,但没有运气。得到与下面相同的错误。
contacts - models.py:
from django.db import models
from datetime import datetime
# Create your models here.
class Contact(models.Model):
listing = models.CharField(max_length=200)
listing_id = models.IntegerField()
name = models.CharField(max_length=200)
email = models.CharField(max_length=200)
phone = models.CharField(max_length=200)
message = models.TextField(blank=True)
contact_date = models.DateField(default = datetime.now, blank = True)
user_id = models.IntegerField(blank=True)
def __str__(self):
return self.name
contacts - admin.py -
from django.contrib import admin
# Register your models here.
from .models import Contact
class ContactAdmin(admin.ModelAdmin):
list_display =('id', 'name', 'listing', 'email' 'contact_date')
list_diplay_links=('id','name')
search_fields = ('name', 'email', 'listing')
list_per_page=25
admin.site.register(Contact, ContactAdmin)
Error logs:
(venv) User-MBP:btre_project user$ python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapperat 0x110c651e0>
Traceback (most recent call last):
File "/Users/rizwanrenesa/Desktop/btre_project/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/rizwanrenesa/Desktop/btre_project/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Users/rizwanrenesa/Desktop/btre_project/venv/lib/python3.7/site-packages/django/core/management/base.py", line 425, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'contacts.admin.ContactAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'emailcontact_date', which is not a callable, an attribute of 'ContactAdmin', or an attribute or method on 'contacts.Contact'.
您在此处email
和contact_date
此处之间缺少逗号:
list_display =('id', 'name', 'listing', 'email' 'contact_date')
如果字符串文字之间没有运算符,则可以在 Python 中连接它们,因此这是有效的
list_display = ('id', 'name', 'listing', 'emailcontact_date')
这就是错误消息所暗示的。
添加逗号,例如
list_display = ('id', 'name', 'listing', 'email', 'contact_date')
然后你就要去比赛了。
(顺便说一句:该user_id
列可能应该是 ForeignKey to user
,而不是原始 ID ......)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句