I have a model that contains the newly added ListField class in DRF.
I am trying to store a List of strings so the output would look like so:
{
"hashtags":["something", "new"],
}
I'm pretty new to working with DRF but I seem to be having some trouble serializing the result. When I run the request I received a
HashField() is not JSON serializable error. Again I'm new to working with the the framework and Python in general but any suggestions, point in the right direction would be a help.
models.py
class HashField(serializers.ListField):
child = serializers.CharField(max_length=100)
class Mention(models.Model):
author = models.ForeignKey(User)
hashtags = HashField()
placename = models.CharField(max_length=140, default='SOME STRING')
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.placename
serializers.py
class MentionSerializer(serializers.ModelSerializer):
class Meta:
model = Mention