Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Added moderators to Forum
Browse files Browse the repository at this point in the history
  • Loading branch information
nylar committed May 20, 2015
1 parent 1f1dc42 commit 220955f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions forums/migrations/0003_forum_moderators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('forums', '0002_forum_active'),
]

operations = [
migrations.AddField(
model_name='forum',
name='moderators',
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
),
]
6 changes: 6 additions & 0 deletions forums/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Forum(models.Model):
objects = models.Manager()
visible = VisibleManager()

# Foreign Keys
moderators = models.ManyToManyField('users.User')

def __str__(self):
return self.name

Expand All @@ -29,3 +32,6 @@ def save(self, *args, **kwargs):

def threads(self):
return self.thread_set.all()

def moderator_list(self):
return self.moderators.all()
14 changes: 14 additions & 0 deletions forums/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.auth import get_user_model
from fora.tests.base import BaseTestCase
from forums.models import Forum
from threads.models import Thread
Expand Down Expand Up @@ -55,3 +56,16 @@ def test_threads(self):
threads = self.forum.threads()
self.assertEqual(len(threads), 2)
self.assertEqual(list(threads), [t1, t2])

def test_moderator_list_empty(self):
mods = self.forum.moderator_list()
self.assertEqual(len(mods), 0)
self.assertEqual(list(mods), [])

def test_moderator_list(self):
u = get_user_model().objects.create(username='mod1', password='p')
self.forum.moderators.add(u)

mods = self.forum.moderator_list()
self.assertEqual(len(mods), 1)
self.assertEqual(list(mods), [u])

0 comments on commit 220955f

Please sign in to comment.