Sending tags via HTTP Post to Django web api endpoint -
i trying send tags web application, using django rest framework , django taggit. tried adapt approach here, no luck far. here try: models.py:
class tool(models.model): name = models.charfield(max_length=100) tags = taggablemanager(blank=true) created = models.datetimefield(auto_now_add=true) def get_tags_display(self): return self.tags.names()
serializers.py:
class toolserializer(taggitserializer, serializers.modelserializer): name = serializers.charfield(max_length=100) tags = serializers.field(source='get_tags_display') class meta: model = tool fields = ('tool_id', 'name', 'tags')
views.py:
class toollist(generics.listcreateapiview): queryset = tool.objects.all() serializer_class = toolserializer def perform_create(self, serializer): if 'tags' in self.request.data: self.objects.add(*self.request.data['tags']) return super(toollist, self).perform_create(self, serializer)
using httpie:
http --form post http://127.0.0.1:8000/tools/ name="hammer" tags:='["new", "heavy"]'
am going in right direction?
Comments
Post a Comment