class ProjectTimeAllocation(models.Model):
id = models.IntegerField(primary_key=True)
project_id = models.ForeignKey(Projects, models.DO_NOTHING, related_name='pj_id', blank=True, null=True)
project_manager_id = models.ForeignKey(ProjectManagers, models.DO_NOTHING, blank=True, null=True)
hours = models.IntegerField(blank=True, null=True)
week = models.DateTimeField(blank=True, null=True)
date_created = models.DateTimeField(auto_now=True, null=True)
last_updated = models.DateTimeField(blank=True, null=True)
class Meta:
managed = False
db_table = 'project_time_allocation'
视图.py
def timeallocation(request, project_manager_id):
#time_list = ProjectTimeAllocation.objects.order_by('-id')
if request.method == "POST":
form = ProjectTimeAllocationForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
#post.project_manager_id = project_manager_id
post.save()
messages.success(request, "Updated Time!")
return HttpResponseRedirect('/dashboard/')
else:
form = ProjectTimeAllocationForm()
return render(request, 'dashboard/timeallocation.html', {'form':form})
表格.py
class ProjectTimeAllocationForm(forms.ModelForm):
week = forms.DateField(widget=forms.SelectDateWidget())
class Meta:
model = ProjectTimeAllocation
fields = (
'hours',
'week',
'project_manager_id',
'project_id',
)
widgets = {
}
labels = {
}
我收到一个操作错误(1054,“字段列表中的未知列 'project_id_id'。我不明白额外的 _id 来自哪里?我已尝试清除迁移并进行新的迁移。