Skip to content

Commit 45f1985

Browse files
WIP; Hide inactive users from the blog post author dropdown
1 parent 985605b commit 45f1985

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

democracy_club/apps/hermes/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ class Post(TimestampedModel):
193193

194194
category = models.ForeignKey(Category, on_delete=models.CASCADE)
195195
author = models.ManyToManyField(
196-
django_settings.AUTH_USER_MODEL, verbose_name="Authors"
196+
django_settings.AUTH_USER_MODEL,
197+
verbose_name="Authors",
198+
limit_choices_to={"is_active": True},
197199
)
198200
tags = ArrayField(models.CharField(max_length=30), blank=True, default=list)
199201

democracy_club/apps/hermes/tests/test_post_model.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import HermesTestCase
22
from .. import settings
33
from hermes import models
4+
from django.contrib.auth.models import User
45

56

67
class PostTestCase(HermesTestCase):
@@ -232,3 +233,16 @@ def test_published(self):
232233
self.post1,
233234
]
234235
self.assertEqual(expected, list(models.Post.objects.published()))
236+
237+
def test_active_users_only(self):
238+
"""The UserQuerySet should only return active users"""
239+
author_6 = User.objects.create(
240+
username="eleven",
241+
242+
first_name="Jane",
243+
last_name="Hopper",
244+
is_staff=False,
245+
is_active=False,
246+
)
247+
expected = [author_6]
248+
self.assertNotEqual(expected, list(User.objects.filter(is_active=True)))

0 commit comments

Comments
 (0)