diff --git a/polls/models.py b/polls/models.py index a309939..118bbb5 100644 --- a/polls/models.py +++ b/polls/models.py @@ -4,7 +4,7 @@ import datetime from django.contrib.auth.models import User from django.db import models -from dashboard.models import Group +from dashboard.models import Group, Group_user VERIFY_CODE_TYPE_CHOICES = ( (0, 'register'), @@ -101,7 +101,8 @@ class Task(models.Model): return TaskRecord.objects.filter(task=self).count() def records(self): - return TaskRecord.objects.filter(task=self) + group_ids = [group.id for group in self.groups.all()] + return Group_user.objects.filter(group__in=group_ids) def add_task_message(self, user_id): for group in self.groups.all(): diff --git a/polls/views/__pycache__/task.cpython-38.pyc b/polls/views/__pycache__/task.cpython-38.pyc index b816768..0d8d741 100644 Binary files a/polls/views/__pycache__/task.cpython-38.pyc and b/polls/views/__pycache__/task.cpython-38.pyc differ diff --git a/polls/views/task.py b/polls/views/task.py index f883d39..583ac06 100644 --- a/polls/views/task.py +++ b/polls/views/task.py @@ -4,7 +4,7 @@ from django.views.decorators.csrf import csrf_exempt import datetime from polls.decorators import polls_login_required -from polls.models import Message, Notice, Task, TaskAddition +from polls.models import Message, Notice, Task, TaskAddition, TaskRecord from django.core.exceptions import ObjectDoesNotExist from polls.utils import model_to_dict, queryset_to_list, parse from dashboard.models import Group, Group_user, Userprofile @@ -98,9 +98,9 @@ def get_task(request): n = [] for r in records: p = dict() - p['id'] = r.id - p['added'] = task.added.strftime("%Y-%m-%d %H:%M:%S") - p['status'] = r.status + p['id'] = r.user_id + is_finished = TaskRecord.objects.filter(user_id=r.user_id, task_id=task_id) + p['status'] = '完成' if is_finished else '未完成' profile = Userprofile.objects.filter(user_id=r.user_id).first() p['name'] = profile.name p['organization'] = profile.organization.name