我有一个模特:
class BroadcastingTable(models.Model):
tv_programm = models.CharField(max_length=50, choices=tv_programm_list)
brd_date = models.DateField()
brd_start = models.CharField(max_length=12)
brd_stop = models.CharField(max_length=12)
brd_duration = models.CharField(max_length=12)
brd_duration_day = models.CharField(max_length=12)
brd_duration_mounth = models.CharField(max_length=12)
我的表格.py:
class TableChoiseForm(forms.ModelForm):
class Meta:
model = BroadcastingTable
和视图:
def index(request):
broadcastingtable = BroadcastingTable.objects.all()
return render(request, 'BroadcastingJournal/broadcastingPage.html',
locals(),)
def edit(request, pk):
instance = get_object_or_404(BroadcastingTable, id=pk)
edit_form = TableChoiseForm(request.POST or None, instance=instance)
try:
if edit_form.is_valid():
instance = edit_form.save(commit=False)
instance.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
else:
edit_form = TableChoiseForm(instance=instance)
return render(request, 'BroadcastingTableChoise/choisePage.html',
{"form": edit_form,})
except BroadcastingTable.DoesNotExist:
return HttpResponseNotFound("<h2>Запись не найдена</h2>")
在表格中,用户每天根据开始时间和结束时间输入日期,开始时间和结束时间。计算该月的持续时间。持续时间挂载时间是一个月中每天的持续时间的总和。 viwes.py 中有一个“编辑” 功能,用于通过表单更改数据。有时有必要更改前几天的旧条目,但是在更改中间的一个对象之后,不会重新计算以下对象,并且该月的广播时间仍然不正确。更改对象后如何重新计算该模型的所有下一个对象的持续时间月份时间?