2014-04-04 4 views
1

python/django tastypie로 이미지를 업로드하는 방법 인 angularjs, django 및 tastypie를 사용하고 있습니다. 내 API에 cover: null,이 있습니다.django tastypie 이미지 업로드 angularjs

class InventoryResource(ModelResource): 
    cover = fields.FileField(attribute='cover', null=True, blank=True) 

class Meta: 
    queryset = Inventory.objects.all() 
    resource_name = 'inventory' 
    list_allowed_methods = ['get', 'put', 'post', 'delete', 'copy'] 
    detail_allowed_methods = ['get', 'put', 'post', 'delete', 'copy'] 
    authorization = DjangoAuthorization() 
    authorization = Authorization() 

모델 :

class Inventory(models.Model): 
    manufacturer = models.CharField(max_length=255, help_text="Enter inventory name") 
    cover  = models.FileField(upload_to = 'static/images/', default = 'static/images/no-image.png') 
    created  = models.DateTimeField(auto_now_add=True) 
    ) 

def __unicode__(self): 
    return '%s' % self.manufacturer 

답변

1

업로드 파일이 AngularJS와와 장고 tastypie 불가능합니다. 당신은 angularjs와 tastypie 문맥에서 그것을 할 필요가있다.

업로드 (자세한 내용은 documentation에서 읽기)에 대한 고유 한 장고보기를 만들고 angularjs 지시어를 사용하여 업로드하십시오 (예 : this directive).