Coder Social home page Coder Social logo

comments's Introduction

#django-ajax-comments Comments

Coverage Status

Build Status

django-ajax-comments is a commenting application for Django-powered websites.

It allows you to integrate commenting functionality to any model you have eg. blogs, pictures, etc...

List of actions you can do:

  • Add a comment
  • Edit a comment you posted (Authenticated)
  • Delete a comment you posted (Authenticated)
  • Like a comment (Authenticated)

####All actions are done through ajax

##Installation

via source on github

$ git clone https://github.com/trDjango/Comments.git
$ cd Comments
$ python setup.py install

Add 'comments' to your installed_apps in your settings.py file. It should look like the following. Note that you should add it after django.contrib.auth:

INSTALLED_APPS = (
	'django.contrib.admin',
	'django.contrib.auth',
	...
	'comments',
	..
)

In your urls.py:

urlpatterns = [
    ...
    url(r'^comments/', include('comments.urls')),
    ...
]

##Migrations for Django 1.11

Migrate comments:

$ python manage.py migrate comments

##Setup

###Step 1 In your models.py add the field comments to the model for which comments should be added (e.g. Blog) and the appropriate imports as shown below

from django.contrib.contenttypes.fields import GenericRelation
from comments.models import Comment

class Blog(models.Model):
	author = models.ForeignKey(User)
	title = models.CharField(max_length=256)
	body = models.TextField()
	comments = GenericRelation(Comment)

###Step 2 In your template (e.g. blog-detail.html) add the following template tags where object is the instance of blog.

{% load comments_tags %}  # Loading the template tag
{% get_comments object request.user %}  # Include all the comments belonging to a certain object
{% comment_form object request.user %}  # Include the form for adding comments
{% get_comment_count object %}  # Include the number of comments on a certain object

The last template tag {% get_comment_count object %} is already included in {% get_comments %}, however you could include it seperately anywhere you want.


This requires jQuery. If you're not already including it, we have a template tag that you can include in your html. ######It should be added after {% load comments_tags %} directly.

{% load comments_tags %}
{% include_jQuery %}

##Settings In settings.py you could set some settings for the application

####COMMENTS_ALLOW_ANONYMOUS

Its default is False.
If set to True, anonymous users will be allowed to post comments.

To set it to True, add the following to settings.py:

COMMENTS_ALLOW_ANONYMOUS = True

####COMMENTS_ALLOW_LIKES

Its default is True.
It allows authenticated users to like/unlike comments.

To change the default, add the following to settings.py:

COMMENTS_ALLOW_LIKES = False

##Styling If you want to customize the way your comments look follow the following steps:

  • In your template directory, create a folder and call it comments
  • Retrieve the html templates for the comments application from its directory which can be found in your sitepackages and github as well.
  • Manipulate those templates as you see fit by adding css classes and such.

and you're done.

comments's People

Contributors

alyakan avatar mostafa93 avatar ranael-garem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.