[Django] #26380: 'FileField' attribute has no file associated with it

25 views
Skip to first unread message

Django

unread,
Mar 18, 2016, 7:13:42 PM3/18/16
to django-...@googlegroups.com
#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.

Django

unread,
Mar 18, 2016, 7:46:27 PM3/18/16
to django-...@googlegroups.com
#26380: 'FileField' attribute has no file associated with it
-------------------------------------+-------------------------------------
Reporter: mehdyhaghy | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: Null Handling | Triage Stage:
FIleField ImageField | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Reply all
Reply to author
Forward
0 new messages