Erick
Erick

Reputation: 250

django tastypie image upload angularjs

I am using angularjs, django, and a tastypie,how to upload image with python/django tastypie. I get cover: null, in my api.

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()

models:

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

Upvotes: 1

Views: 468

Answers (1)

adityasdarma1
adityasdarma1

Reputation: 325

Uploading file is not possible with angularjs and django tastypie. You need to do it out of the angularjs and tastypie context.

Create your own Django view specific for uploading (read more at documentation), and use angularjs directive to upload, for example: this directive.

Upvotes: 1

Related Questions