I have model(model.py):
class Group(models.Model):
system_id = models.ForeignKey(System)
group_id = models.CharField(max_length=40)
description = models.TextField()
title = models.CharField(max_length=250)
latintitle = models.CharField(max_length=250)
audio = models.CharField(max_length=250)
And i've added custom field for upload file with many groups and then parse it(admin.py):
class GroupModelForm(forms.ModelForm):
file = forms.FileField(required=False)
def save(self, commit=True):
file = self.cleaned_data['file']
if file:
lines = file.readlines()
# ...do something with extra_field here...
return super(GroupModelForm, self).save(commit=commit)
class Meta:
model = Group
fields = ('file',)
class GroupAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'group_id')
form = GroupModelForm
fieldsets = (
('New Group', {
'fields': ('system_id', 'group_id', 'title', 'latintitle', 'description', 'audio')
}),
('Upload JSON file with groups info', {
'fields': ('file',)
}),
)
When I'm uploading file it says other fields needs to be filled.
My question: How to ignore those errors and after processing of file redirect to another page?
UPDATE: I made all fields blank=True
, except one