Tuesday, May 31, 2016

parent: [ 'Invalid pk "0" - object does not exist.' ] and null or blank value not store in mysql

class AccountType(ModelBase):
parent = models.ForeignKey('self',on_delete = models.SET_NULL, null=True, blank=True, default=None )

class AccountTypeSerializer(serializers.ModelSerializer):
parent = serializers.PrimaryKeyRelatedField(queryset=AccountType.objects.all(), required=False,null=True, blank=True)
class Meta:
model = AccountType
fields = ('id','parent','account_type_name')

how to set null and empty value in parent field

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/5c71aa20-6aec-4dc2-a887-5b0b06d63494%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment