Opened 9 years ago

Closed 9 years ago

#26380 closed Cleanup/optimization (duplicate)

'FileField' attribute has no file associated with it

Reported by: Mehdy Haghy Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords: Null Handling FIleField ImageField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've a FileField in a model which is marked as nullable but when I want to serialize the model

instead of null value it throws an exception:
'profile_img' attribute has no file associated with it

How can I get null or blank when the value of FileFiled is null?
I've seen a few workaround to handle this in template but since
I'm using this in DRF so there's no way to handle.

class UserProfile(models.Model):
  owner = models.OneToOneField('auth.User', related_name='userprofile', default=-1)
  profile_img= models.FileField(upload_to='profiles', blank=True, null=True)


class UserProfileSerializer(serializers.ModelSerializer):

    owner = UserSerializer()
    class Meta:
        model = UserProfile
        fields=('pk','profile_img')

Change History (1)

comment:1 by Tim Graham, 9 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed
Type: UncategorizedCleanup/optimization

Duplicate of #13327

Note: See TracTickets for help on using tickets.
Back to Top