开发者

Customize Django comments framework so that the comment does not have to be unique

I'm customizing the comments model per the Django documentation.

In my specific use case, however, comments are allowed to be blank. The trouble I get into then is that the Comment model is setup with an unique_together:

unique_together = [('user', 'comment', 'flag')]

Any ideas on how I coul开发者_如何学God go about overriding this?

(...or did I start off on the wrong track with using the Comments framework altogether? :)


Doesn't look like the Comment model has a unique constraint.

Code for models.py for contrib.comments.

It looks like the CommentFlag model has the uniqueness constraint which shouldn't effect you having blank comments.

Your problem must lie elsewhere.


I'm not very familiar with the comments app but here are some ideas you can look at to get around your problem.

Warning I haven't used either of these methods on the comments app so I'm not sure if using these will break any downstream functions of the comments framework. Be sure to look into/test if you decide to use either of these.

That being said, I can think of 2 ways you can approach this.

  1. Override the unique together:

    class NonUniqueComment(Comment): class Meta(Comment.Meta): unique_together = []

  2. Make the comments field store Null instead of empty string in the db.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜