0

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?

enter image description here

UPDATE: I made all fields blank=True, except one

Volodymyr B.
  • 3,369
  • 2
  • 30
  • 48

1 Answers1

0

You need to set your fields as null=True as well, since you need to allow NULL in the database in order to allow blank fields in forms.

About the difference between blank=True and null=True and how they interact with forms and fields, here's a very clear explanation: https://stackoverflow.com/a/8609425/2926113

Community
  • 1
  • 1
Railslide
  • 5,344
  • 2
  • 27
  • 34