from actstream import registry
class Characterictic(models.Model):
...
registry.register(Characterictic)
def my_handler(sender, instance, created, **kwargs):
action.send(instance, verb='was saved')
post_save.connect(my_handler, sender=Сharacterictic)
AttributeError: 'Project' object has no attribute 'usercharacteristic'.
def order_by(p):
created = max(
p.project_created
)if(
p.project_created
)else project.project_created
if created is not None:
return created
projects_annotated = list(filter(
lambda p: ***первый и вторые критерии***, p.project_created,
Project.objects.annotate(
****
project_created = Max('creation_date') <-- Третий последний критерий
)
))
Traceback (most recent call last):
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\el_pagination\decorators.py", line 88, in decorated
return view(request, *args, **kwargs)
File "C:\Users\Nurzhan\PycharmProjects\RMS\RMS\views.py", line 56, in home
reverse=True
File "C:\Users\Nurzhan\PycharmProjects\RMS\RMS\views.py", line 36, in order_by
p.project_created
TypeError: 'datetime.datetime' object is not iterable
[31/May/2017 19:50:25] "GET /ru/ HTTP/1.1" 500 79848
Traceback (most recent call last):
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35\lib\site-packages\el_pagination\decorators.py", line 88, in decorated
return view(request, *args, **kwargs)
File "C:\Users\Nurzhan\PycharmProjects\RMS\RMS\views.py", line 21, in home
for project_code, characteristic_time, task_time in latest_comments_by_section
File "C:\Users\Nurzhan\PycharmProjects\RMS\RMS\views.py", line 21, in <listcomp>
for project_code, characteristic_time, task_time in latest_comments_by_section
TypeError: unorderable types: NoneType() > NoneType()
import operator
from django.db.models import Max
latest_comments_by_section = Project.objects.values_list('code').annotate(
Max('characteristic__comments__created'),
Max('task__comments__created'),
)
latest_comments = [
(project_code, max(characteristic_time, task_time))
for project_code, characteristic_time, task_time in latest_comments_by_section
]
projects = [
Project.objects.get(code=project_code, status='open')
for project_code, _ in sorted(latest_comments, key=operator.itemgetter(1), reverse=True)
]
code = models.UUIDField(_('Code'), primary_key=True, default=uuid.uuid4, editable=False)
comments = models.ManyToManyField("Comment")
. Использования именно такого подхода к хранению комментариев с использованием ManyToManyField, обусловлено потребностями другой задачи, которую он решает. Есть ли у вас другие идеи по данному вопросу?) <a href="/ru/?page=2" data-el-querystring-key="page" class="endless_page_link">></a>