Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion democracy_club/apps/hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ class Post(TimestampedModel):

category = models.ForeignKey(Category, on_delete=models.CASCADE)
author = models.ManyToManyField(
django_settings.AUTH_USER_MODEL, verbose_name="Authors"
django_settings.AUTH_USER_MODEL,
verbose_name="Authors",
limit_choices_to={"is_active": True},
)
tags = ArrayField(models.CharField(max_length=30), blank=True, default=list)

Expand Down
14 changes: 14 additions & 0 deletions democracy_club/apps/hermes/tests/test_post_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import HermesTestCase
from .. import settings
from hermes import models
from django.contrib.auth.models import User


class PostTestCase(HermesTestCase):
Expand Down Expand Up @@ -232,3 +233,16 @@ def test_published(self):
self.post1,
]
self.assertEqual(expected, list(models.Post.objects.published()))

def test_active_users_only(self):
"""The UserQuerySet should only return active users"""
author_6 = User.objects.create(
username="eleven",
email="[email protected]",
first_name="Jane",
last_name="Hopper",
is_staff=False,
is_active=False,
)
expected = [author_6]
self.assertNotEqual(expected, list(User.objects.filter(is_active=True)))