Skip to content

Commit

Permalink
WIP; Hide inactive users from the blog post author dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Jul 4, 2022
1 parent 303a31b commit 24d6fc9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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)))

0 comments on commit 24d6fc9

Please sign in to comment.