django错误:int()以10为底的无效文字:b'01 / 12/1990'

时间:2018-12-04 14:06:48

标签: django django-models

我在django应用程序中创建了一个Profile和Blog模型。

这是下面的models.py文件:

     from django.db import models


     # Create your models here.

     class Profile(models.Model):
         name = models.CharField(max_length=30)
         description = models.TextField()
         number = models.CharField(max_length=10)
         dob = models.DateField()


     class Blog(models.Model):
         title = models.CharField(max_length=30)
         content = models.TextField()
         blog_document = models.FileField(upload_to='documents/', null=True, blank=True)

在管理面板中,对于配置文件模型:我想查看表中的两个或更多列,如下所示:

enter image description here

但是此行给我错误,因为我不知道如何在Profile表中显示多个列:

        def __str__(self):
             return '%s %s' % (self.name, self.number)

请帮助!在个人资料表(管理面板)中实现两个或多个字段的正确解决方案是什么?预先感谢!

更新:

    class ProfileAdmin(admin.ModelAdmin):
        list_display = ('name', 'description', 'number', 'dob')


    admin.site.register(Profile, ProfileAdmin)


    class BlogAdmin(admin.ModelAdmin):
        list_display = ('title', 'content')


    admin.site.register(Blog, BlogAdmin)

这是引用通告:

标题:/ admin / mysite / profile /

中的ValueError

内容:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/mysite/profile/

Django Version: 2.1.3
Python Version: 3.7.1
Installed Applications:
['mysite',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/contrib/admin/options.py" in wrapper
  604.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/contrib/admin/options.py" in changelist_view
  1792.             'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/query.py" in __len__
  250.         self._fetch_all()

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/query.py" in _fetch_all
  1186.             self._result_cache = list(self._iterable_class(self))

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1097.                 return list(result)

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in cursor_iter
  1466.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in <lambda>
  1466.         for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):

File "/Users/sndtcsi/PycharmProjects/Assignment1/venv/lib/python3.7/site-packages/django/db/utils.py" in inner
  96.                 return func(*args, **kwargs)

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sqlite3/dbapi2.py" in convert_date
  64.         return datetime.date(*map(int, val.split(b"-")))

Exception Type: ValueError at /admin/mysite/profile/
Exception Value: invalid literal for int() with base 10: b'01/12/1990'

0 个答案:

没有答案