本文介绍了Django,无法分配None,不允许空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个models.py

i have this models.py

import datetime
from django.db import models
from tinymce import models as tinymce_models
from filebrowser.fields import FileBrowseField

class ItemWithMedia(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

class Actual(ItemWithMedia):
    published = models.DateField('Published')
    title_hr = models.CharField('(hr)', max_length=200)
    title_en = models.CharField('(en)', max_length=200)
    body_text_hr = models.TextField('(hr)')
    body_text_en = models.TextField('(en)')

    def __unicode__(self):
        return self.title_hr

    class Meta:
        verbose_name = "Aktualno"
        verbose_name_plural = "Aktualni"
        ordering = ['-published']

当我尝试创建n时我得到这个错误管理网站中的ew项目:
无法分配无:Actual.published不允许空值。

and i get this error when i try to create new item in admin site:Cannot assign None: "Actual.published" does not allow null values.

可能是什么问题?

推荐答案

 #for sql 'now()' value use
 published = models.DateField('Published', auto_now_add=True)
 #to allow sql null
 published = models.DateField('Published', null=True, blank=True)

这篇关于Django,无法分配None,不允许空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 07:30