django独一无二,即使

问题描述

即使post_type是索引1,我也想一起使用unique。 对于每个部分,只能一次选择文章类型索引1,但可以不受限制地选择索引0。

 class Post(models.Model):
    Article_type = (('news','Het laatste nieuws'),('introduction','Een introductie'))
    post_id = models.AutoField(primary_key=True)
    post_title = models.CharField(max_length=50,null=False)
    post_header = models.TextField(max_length=250,null=True,blank=True)
    post_body = RichTextUploadingField(null=True)
    post_expire_date = models.DateTimeField(null=True,blank=True)
    post_available_date = models.DateTimeField(default=timezone.Now,null=False)
    post_image = models.ImageField(upload_to='post-uploads/',blank=True)
    post_section = models.ForeignKey(Section,on_delete=models.CASCADE,default=1)
    post_type = models.CharField(max_length=30,choices=Article_type,default="news")
    post_author = models.ForeignKey(
        user,limit_choices_to={'is_staff': True},default=user,)
    slug = models.SlugField(unique=True)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)