#26380: 'FileField' attribute has no file associated with it
--------------------------+------------------------------------------------
Reporter: | Owner: nobody
mehdyhaghy |
Type: | Status: new
Uncategorized |
Component: | Version: 1.9
Uncategorized |
Severity: Normal | Keywords: Null Handling FIleField ImageField
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
--------------------------+------------------------------------------------
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.
{{{#!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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.d08597bd4ef099d373fe640010918a9e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.