Make ProgressUpdate attached to a readthrough

This commit is contained in:
Joel Bradshaw 2020-11-16 23:53:17 -08:00
parent 13229ea937
commit 00b8608a50
2 changed files with 2 additions and 4 deletions

View file

@ -336,7 +336,7 @@ class ProgressMode(models.TextChoices):
class ProgressUpdate(BookWyrmModel): class ProgressUpdate(BookWyrmModel):
''' Store progress through a book in the database. ''' ''' Store progress through a book in the database. '''
user = models.ForeignKey('User', on_delete=models.PROTECT) user = models.ForeignKey('User', on_delete=models.PROTECT)
book = models.ForeignKey('Book', on_delete=models.PROTECT) readthrough = models.ForeignKey('ReadThrough', on_delete=models.PROTECT)
progress = models.IntegerField() progress = models.IntegerField()
mode = models.CharField(max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE) mode = models.CharField(max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE)
date = models.DateTimeField(auto_now_add=True) date = models.DateTimeField(auto_now_add=True)

View file

@ -428,12 +428,10 @@ def edit_readthrough(request):
# record the progress update individually # record the progress update individually
# use default now for date field # use default now for date field
progress_update = models.ProgressUpdate( readthrough.progressupdate_set.create(
user=request.user, user=request.user,
book=readthrough.book,
progress=readthrough.pages_read, progress=readthrough.pages_read,
mode=models.ProgressMode.PAGE) mode=models.ProgressMode.PAGE)
progress_update.save()
return redirect(request.headers.get('Referer', '/')) return redirect(request.headers.get('Referer', '/'))