11👍
✅
class ItemSerializer(serializers.HyperlinkedModelSerializer):
user = UserDetailsSerializer()
category = CategorySerializer(many=True)
thecomments = CommentSerializer(many=True)
timestamp = serializers.SerializerMethodField('get_mytimestamp')
def get_mytimestamp(self, obj):
return time.mktime(datetime.datetime.now().timetuple())
class Meta:
model = Item
fields = [
"url",
"user",
"timestamp",
"categories",
"thecomments",
]
extra_kwargs = {'user': {'required': False}}
add extra_kwargs = {'user': {'required': False}}
to your serializer Meta
👤Ykh
0👍
i had the same issue.
added extra_kwargs = {'user': {'required': False}}
to serializer Meta class and it worked
- [Django]-OneToMany Relationship for more generic django apps
- [Django]-DRF Serializer – OrderDict instead of JSON
- [Django]-Django on Strato webspace
- [Django]-How should I upgrade from bradjasper's django-jsonfield to Django's built-in jsonfield?
- [Django]-Many to many relationship in django database model
Source:stackexchange.com