小编Mat*_*yne的帖子

'NoneType'对象没有属性'unique'但我没有使用'unique'属性

我在Django 1.8中构建模型,我正在使用抽象继承(我假设这是导致问题的原因).我有抽象模型,然后我有基于那些抽象模型的模型.我也有一些模型之间的ForeignKey和ManyToMany关系.

一切看起来都很好,但是当我尝试syncdb或'makemigrations blog'时,我得到一个AttributeError,其中说'NoneType'对象没有属性'unique'.

我不知道为什么我会得到它,我尝试了不同的模型设置,我读了很多论坛帖子,但是现在我已经碰壁了.

我将在下面发布追溯和我的模型:

楷模:

indie_db

from django.db import models

class URL(models.Model):
    link = models.CharField(max_length=400)
    name = models.CharField(max_length=200)

    def __str__(self):
        return self.name


class Artist(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    link = models.ForeignKey(URL)

    class Meta:
        abstract = True
        ordering = ['name']

    def __str__(self):
        return self.name


class ArtistSingle(Artist):
    birthdate = models.DateField(null=True, blank=True)
    deathdate = models.DateField(null=True, blank=True)


class ArtistGroup(Artist):
    members = models.ManyToManyField(ArtistSingle)
    established = models.DateField(null=True, blank=True)
    disbanded = models.DateField(null=True, blank=True)


class Contributor(models.Model):
    contributing_artist = models.ForeignKey(ArtistSingle, null=True, blank=True)
    alternate_name = …
Run Code Online (Sandbox Code Playgroud)

python django inheritance abstract-class

7
推荐指数
1
解决办法
1635
查看次数

保存Django Form会产生错误:无法解决的类型:int()> str()

我有一个表单,可以成功加载PostgreSQL数据库中的现有数据并填写字段,以便用户可以以可编辑的形式查看自己的信息.但是,当我按下"保存更改"按钮(加载一个被编程为将数据保存回同一数据库条目的视图)时,我收到以下错误:

(为了便于阅读,我在这里将实际的URL改为'/ PATH /')

TypeError at /accounts/update_profile/

unorderable types: int() > str()

Request Method:     POST
Request URL:    http://www.limbs.ca/accounts/update_profile/
Django Version:     1.7.7
Exception Type:     TypeError
Exception Value:    

unorderable types: int() > str()

Exception Location:     /home/pattmayne/webapps/limbs_006/lib/python3.4/Django-1.7.7-py3.4.egg/django/core/validators.py in <lambda>, line 279
Python Executable:  /usr/local/bin/python3
Python Version:     3.4.1
Python Path:    

['/PATH/lib/python3.4/Django-1.7.7-py3.4.egg',
 '/PATH',
 '/PATH/myproject',
 '/PATH/lib/python3.4',
 '/usr/local/lib/python34.zip',
 '/usr/local/lib/python3.4',
 '/usr/local/lib/python3.4/plat-linux',
 '/usr/local/lib/python3.4/lib-dynload',
 '/usr/local/lib/python3.4/site-packages']

Server time:    Sun, 5 Apr 2015 18:46:17 +0000
Traceback Switch to copy-and-paste view

    /PATH/lib/python3.4/Django-1.7.7-py3.4.egg/django/core/handlers/base.py in get_response

                            response = wrapped_callback(request, *callback_args, **callback_kwargs)

         ...
    ? Local vars …
Run Code Online (Sandbox Code Playgroud)

python forms django postgresql

4
推荐指数
1
解决办法
2348
查看次数

Django Admin:TypeError:__str__返回非字符串(类型FieldFile)

我有一个功能正常的Django站点和一个正常运行的管理员,除了我尝试使用管理站点从模型"文章"创建一个新对象.当我尝试创建一个新的"文章"时,我收到此错误:

TypeError at /admin/blog/article/add/

__str__ returned non-string (type FieldFile)
Exception Type:     TypeError
Exception Value:    __str__ returned non-string (type FieldFile)
Exception Location:     /home/USERNAME/webapps/APPNAME/lib/python3.4/Django-1.8.2-py3.4.egg/django/utils/encoding.py in force_text, line 90
Run Code Online (Sandbox Code Playgroud)

这是奇怪的事情:今天早上工作.我尝试安装django-markdown,我开始收到此错误.我无法让它工作,所以我卸载了django-markdown并将所有代码恢复为原始代码(之前的功能)并进行了适当的迁移.

但我仍然得到错误.

这是追溯和渲染错误:

Error during template rendering

In template /home/USERNAME/webapps/APPNAME/lib/python3.4/Django-1.8.2-py3.4.egg/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
__str__ returned non-string (type FieldFile)
9               {% for field in line %}
10                  <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% …
Run Code Online (Sandbox Code Playgroud)

python django

4
推荐指数
1
解决办法
5027
查看次数

标签 统计

django ×3

python ×3

abstract-class ×1

forms ×1

inheritance ×1

postgresql ×1