我有以下模型:
class ProjectBudget(models.Model):
它有一个表格和内联:
class ProjectBudgetAdmin(admin.ModelAdmin):
form = ProjectBudgetForm
inlines= [ProjectSpentsInline]
class ProjectSpentsInline(admin.TabularInline):
model = ProjectSpents
在表格上我有一个字段file
。从这个文件我想填充内联对象ProjectSpents
值:
class ProjectBudgetForm(ModelForm):
file = forms.FileField
def clean_file(self):
parse file then populate inline model objects ProjectSpents....
问题是我想从 clean_file 编辑 ProjectSpents 的内联值,但是有一个问题,因为在 clean_file 之前查询集已经被填充并且新的内联值没有显示。也许还有另一种解决方案?