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.
{{{#!python
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')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26380>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
Comment:
Duplicate of #13327
--
Ticket URL: <https://code.djangoproject.com/ticket/26380#comment:1>