Conversation
| def get_project_ordered_by_last_report_creation_date(self) -> QuerySet: | ||
| return self.projects.annotate( | ||
| last_report_creation_date=Coalesce( | ||
| Max("report__creation_date", filter=Q(report__author=self)), Value("1970-01-01 00:00:00") |
There was a problem hiding this comment.
I am not sure if I understand why we need Coalesce and Max here... Could you please explain?
There was a problem hiding this comment.
If given project has no reports created for current user, the returned value from Max() is None, which then is being put at the beginning of the list (because we use DESC ordering). So to avoid that I am using Coalesce to replace None with oldest date known to human civilization and get the desired order.
|
|
||
|
|
||
| class TestGetProjectOrderedByLastReportCreationDate(TestCase): | ||
| def setUp(self): |
There was a problem hiding this comment.
personally I would prefer having projects build with ProjectFactory, i.e
project1 = ProjectFactory()and then have reports named like
self.project1_report1 = ReportFactory(author=self.user, project=self.project1)this way the tests would be easier to grasp in my opinion.
There was a problem hiding this comment.
👍 done, more code, but as you have said, easier to read :)
edc0405 to
fc11a46
Compare
fc11a46 to
5b2a28d
Compare
5b2a28d to
4269ecf
Compare


Resolves #29
TODO: Add test that ReportForm.projects field sets initial to project in which last report was created after #296 is merged.