Hi Melvyn,
I am checking for None in the last if condition in to_python method :
--copy--
> if value in ('f', 'False', 'false', '0', '\x00', *None*): return
> False
--copy--
Thanks for checking and replying !!
Regards,
Priyanka
On Friday, 16 June 2017 20:03:22 UTC+5:30, Priyanka Thakur wrote:
>
> Hi,
>
> I am doing migration from Django 1.7 to 1.10 version and has a custom
> django field.
>
> Below is the custom class for the field:
>
> ----
>
> from django.db import models
>
>
>
> class HibernateBooleanField(models.BooleanField):
>
> def from_db_value(self, value, expression, connection, context):
>
> return self.to_python(value)
>
>
> def get_internal_type(self):
>
> return "HibernateBooleanField"
>
>
> def db_type(self, connection):
>
> return 'bit(1)'
>
>
> def to_python(self, value):
>
> if value in (True, False):
>
> return value
>
> if value in ('t', 'True', 'true', '1', '\x01'): return True
>
> if value in ('f', 'False', 'false', '0', '\x00', None): return
> False
>
>
> def get_db_prep_value(self, value, connection, prepared=False):
>
> return 0x01 if value else 0x00
>
>
> def get_db_prep_save(self, value, connection):
>
> return 0x01 if value else 0x00
>
>
> def get_prep_value(self, value):
>
> return self.to_python(value)
>
> ---
>
>
> I have defined a field in the model as:
>
>
>
> class MetaMetadata(models.Model):
>
> is_folder = HibernateBooleanField()
>
>
>
> When I invoke a POST request on API in my test case , I get the value for
> this field as "None" in response.
>
>
> The API is :
>
>
> response = self._client.post('/xyz/api/metametadatas/',
> {'edit_view': "TestEditView",
> 'grid_view': "TestGridView",
> 'name': "Test Metametadata",
> 'sort_key': 9000,
> 'parentid': 0,
> 'version':0,
> 'id': 100}, format='json')
>
>
>
> Please explain , what is it that I'm doing wrong. Why isn't to_python method
> getting invoked ? Am I missing something?
>
>
> Regards,
>
> Priyanka
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" 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].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/c89377a1-78cb-4b76-9518-39cd5181dcb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.