Hi Xavier,

Serializer is :

class MetametadataSerializer(serializers.ModelSerializer):

    class Meta:
        model = Metametadata
        fields = tuple([getattr(x, 'name') for x in Metametadata._meta.fields]) 
+ tuple( ['leaf'] )


Regards,

Priyanka


On Tuesday, 20 June 2017 14:47:30 UTC+5:30, Xavier Ordoquy wrote:
>
> Hi,
>
> We can’t provide any meaningful answer here as you don’t provide any hint 
> about how you wrote the serializer.
>
> Regards,
> Xavier Ordoquy,
> Linovia.
>
> Le 20 juin 2017 à 08:25, Priyanka Thakur <[email protected] 
> <javascript:>> a écrit :
>
> Hi,
>
> I have defined a custom field instead of BooleanField in my project.
>
> Custom field is defined in model with  no default value , example:
>
> class MyModel(models.Model):
>        is_folder = HibernateBooleanField()
>
>
> where HibernateBooleanField is the custom calss for overriding 
> "to_python", "from_db_value" methods.
>
> When making a POST request, the object is getting saved by invoking the 
> proper methods from Custom field implementation. 
>
> But when getting the serialized object , "is_folder" value is returned as 
> "None" .
>
> Though I understand that default value for BooleanField is "None", does 
> that mean with DRF 3.6 we have to mandatorily define default values for 
> Boolean Field, if i want to use "False" and "True" ?
>
> Also , why isn't any method invoked from Custom field implementation?
>
> This is custom field implementation:
>
> from django.db import models
>
> # #
> # This is for dealing with BIT (boolean) type of Hibernate
> # #
> 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
>
> Regards,
> Priyanka
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to