I have a model
class Item(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
otheritemmodel = models.ForeignKey(Model, on_delete=models.CASCADE)
uuid = models.CharField(max_length=256, unique=True)
floatitem = models.FloatField()
relateditem = models.ForeignKey(RelatedItem, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
subcategory = models.ForeignKey(SubCategory, on_delete=models.CASCADE)
character = models.CharField(max_length=500, null=True, blank=True)
zipcode = models.IntegerField()
city = models.CharField(max_length=100)
state = models.CharField(max_length=100)
active = models.BooleanField(default=True)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
CreateAPIView
class Item_Create_APIView(CreateAPIView):
authentication_classes = [SessionAuthentication, BasicAuthentication, JSONWebTokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = ItemCreateSerializer
queryset = Item.objects.all()
And Serializer
I am trying to test the createView post via curl or http in the terminal but no luck so far. I am using python3.5 and Django==1.8.10 and Django Rest Framework with JWT token authentication. I can login and get a token but I don't know how to format the json data to the baseusrl/create_item endpoint to test the Create Post call via curl to see if the API works.
Anyone with guidance on this? Thanks
I tried this and it didn't work:
curl —X POST H ”Authorization: JWT token” http://localhost:8000/create_item/ ‘{“key”:”val”}’
I have tried this format and got "no url specified" while the url is in the call
curl -X POST -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE0NzEwMjc4MjIsImVtYWlsIjoicGF0b3JlQHByb3Rvbm1haWwuY2giLCJ1c2VybmFtZSI6InBhdG9yZUBwcm90b25tYWlsLmNoIn0.seO6ayMayJ8hwGf3Tlqwu95cZOw5VyFGVqsT5LymdJw" -H "Content-Type: application/json" -d “user=37&otheritmemodel=3&uuid=4454353454983543434&floatitem=40.0&relateditem=28&category=1&subcategory=1&character=jim&zipcode=11111&city=City&state=State” http://localhost:8000/user-api/create_item/
any ideas?