aca el error
Column 'user_id' cannot be null
aca el codigo:
Código Python:
Ver original
el forms.py class addPostForm(forms.ModelForm): class Meta: model = posts exclude = {'slug','user', 'creado'} el view.py def addPosts(request): if request.method == "POST": form = addPostForm(request.POST) if form.is_valid(): add = form.save(commit=False) add.save() form.save_m2m() return HttpResponseRedirect('/') else: form = addPostForm () ctx = {'form': form} return render_to_response('posts/add.html', ctx, context_instance=RequestContext(request)) y finalmente el modelo class posts(models.Model): titulo = models.CharField(max_length=180, unique=True) slug = models.SlugField(max_length=180, editable=False) contenido = models.TextField() categoria = models.ForeignKey(categorias) user = models.OneToOneField(User) tags = models.CharField(max_length=200) creado = models.DateTimeField(auto_now_add=True) modificado = models.DateTimeField(auto_now=True) def save(self, *args, **kwargs): self.slug = slugify(self.titulo) super(posts, self).save(*args, **kwargs) def __str__(self): return self.titulo