Hi there Stackers!
I have 2 models in question. JobRecord of which has many Activity(ies), the fk, of course, placed in the Activity model.
To aid data entry, I'd like to default the fk to JobRecord, within a new Activity, to the 'JobRecord fk of the last entered Activity, by the logged in User (bonus points!)'
Here's the model:
class Activity(models.Model):
"""
Record multiple activities against a JobRecord
"""
start = models.TimeField(blank=True, null=True)
end = models.TimeField(blank=True, null=True)
job_record = models.ForeignKey(JobRecord) # editable=False)
task = models.ForeignKey(Task, blank=True, null=True) # show only tasks found in project
flora = models.ManyToManyField(Species, blank=True, null=True, help_text='Optional subject flora.')
memo = models.TextField(blank=True, null=True)
all_operators = models.BooleanField(help_text="Check to include all operators from the parent job record")
operators = models.ManyToManyField(User, null=True, blank=True)
duration = models.DecimalField(blank=True, null=True, max_digits=7, decimal_places=2)
class Meta:
#order_with_respect_to = 'job_record' # not working?
ordering = ['-job_record__date', 'job_record', 'start']
Thanks!