Rocky Holms Rocky Holms - 1 month ago 8x
Python Question

bypass validation for form field django

class PostForm(forms.ModelForm):
description = forms.CharField(widget=PagedownWidget(show_preview=False))
class Meta:
model = Post
fields = [

I am trying to bypass the required field for 'video' but having difficulty doing so. Any suggestions would be appreciated.

this is my, hopefully is should help with knowing how to go on this.

from django.db import models

from django.db.models import Count, QuerySet, F
from django.utils import timezone
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models.signals import pre_save
from django.utils.text import slugify
from markdown_deux import markdown
from django.utils.safestring import mark_safe
from embed_video.fields import EmbedVideoField
from taggit.managers import TaggableManager

from comments.models import Comment

def upload_location(instance, filename):
return "%s/%s" %(instance.slug, filename)

class Post(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1 )
title = models.CharField(max_length=75)
slug = models.SlugField(unique=True)
video = EmbedVideoField()
image = models.ImageField(
height_field = models.IntegerField(default=0)
width_field = models.IntegerField(default=0)
description = models.TextField()
tags = TaggableManager()
public = models.BooleanField(default=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
created = models.DateTimeField(auto_now_add=True, auto_now=False)

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse("posts:detail", kwargs={"slug": self.slug})

class Meta:
ordering = ["-created", "-updated" ]

def get_markdown(self):
description = self.description
markdown_text = markdown(description)
return mark_safe(markdown_text)

def comments(self):
instance = self
qs = Comment.objects.filter_by_instance(instance)
return qs

def get_content_type(self):
instance = self
content_type = ContentType.objects.get_for_model(instance.__class__)
return content_type

def create_slug(instance, new_slug=None):
slug = slugify(instance.title)
if new_slug is not None:
slug = new_slug
qs = Post.objects.filter(slug=slug).order_by("-id")
exists = qs.exists()
if exists:
new_slug = "%s-%s" %(slug, qs.first().id)
return create_slug(instance, new_slug=new_slug)
return slug

def pre_save_post_receiver(sender, instance, *args, **kwargs):
if not instance.slug:
instance.slug = create_slug(instance)

pre_save.connect(pre_save_post_receiver, sender=Post)


from the docs it looks like it should support empty now since version 0.3, i would suggest trying

video = EmbedVideoField(null=True,blank=True)

the docs say it should function like a URL field, so just the standard notation should be all you need.

good luck!