Search Posts

Category: django

Increment integer field dynamically – Django

So I have the following model: from django.db import models class Person(models.Model): name = models.CharField(max_length=254) image_url = models.CharField(max_length=254) title = models.CharField(max_length=254) bio = models.CharField(max_length=20000) vote = models.IntegerField(default=0) def __str__(self): return self.name Where Vote is the attribute that I want to increment by one on every click. The following Views: import json from rest_framework.views import APIView from rest_framework.response import Response from urllib.request import urlopen from .models import Person from .serializers import PersonSerializer from django.views.generic import ListView […]

Django restful api can not get file content

I use Django restful api + angularjs . Now ,I append to use angularjs upload file to server by Django restful api On the web front-end ,The Html is: <input type=”file” data-upload-file id=”uploadInputFile”> The angularjs’s code is : omapp.directive(“uploadFile”,function(httpPostFactory){ return { restrict:”A”, scope:true, link:function(scope,element,attr){ element.bind(‘change’,function(){ var formData = new FormData(); formData.append(‘file’, element[0].files[0]); console.log(formData.get(‘file’)) httpPostFactory(‘/api/uploadfile/’,formData.get(‘file’),function (callback) { console.log(callback); }) }) } }; }); omapp.factory(‘httpPostFactory’, function ($http,$cookies) { return function (file, data, callback) { var req = […]