Attached new patch to ticket that should make the behaviour as
expected.
On 20 Feb, 20:15, Øyvind Saltvik <[email protected]> wrote:
> The problem is, it is impossible to make a FileField None.
>
> >>> from django.db import connection
> >>> from app.models import Model
> >>> instance = Model.objects.all()[0]
> >>> instance.filefield = None
> >>> instance.save()
> >>> print connection.queries[-1]
>
> On 20 Feb, 19:06, Collin Grady <[email protected]> wrote:
>
> > It will only store NULL if you set it to None - if you leave the field
> > blank in a form or admin, there's still an empty string posted for
> > most string field types, so it stores that empty string.
>
> > On Fri, Feb 20, 2009 at 4:57 AM, [email protected]
>
> > <[email protected]> wrote:
>
> > > If a FileField with null=True is set to None, the db stores '' in the
> > > db and not NULL as I would expect.
>
> > > Also, if a FileField has both blank=True and null=True a ModelForm
> > > without a file will save '' in the db, not sure if this is the desired
> > > behaviour.
>
> > > So the question is should the behaviour be as-is and if not is the
> > > correct place to solve it in get_db_prep_value?
>
> > > Example of code that this issue affects:
>
> > > Model.objects.filter(filefield=u'') seems wrong as compared to
> > > Model.objects.filter(filefield__isnull=True)
>
> > > Model.objects.aggregate(Count('filefield')) i would expect this to
> > > count objects with a file and not those without a file.
>
> > > This may relate to other fields aswell, if a field has both blank=True
> > > and null=True should it not store NULL in the db?
>
> > --
> > Collin Grady
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---