I need an image upload directive, here is how my code looks like:
# Model
class transporter(models.Model):
company_name = models.CharField(max_length=100)
address = models.CharField(max_length=100)
image = models.FileField(upload_to=upload_path,blank=True, null=True)
def upload_path(self, filename):
return 'photos/%s/%s' % (self.company_name, filename)
# Serializer
class transporterSerializer (serializers.HyperlinkedModelSerializer):
username = serializers.Field(source='username.username')
class Meta:
model = transporter
fields = ('id','company_name','address','image')
it works with only django rest framework but i get Bad request error if I post the transporter model with angularjs. I need to upload the image and set the image field with the image URL. thank you