1

I'm using Django and Tastypie to create a RESTful web app. I have a model like this

class Picture(models.Model):
    # some other fields
    image = models.ImageField('Image')
    def image_url(self):
        return self.image.url

Tastypie will give the image's path but actually I need its url. How to write a correct resource api to achive this?

reasonsolo
  • 23
  • 9

1 Answers1

0

By default TastyPie is supposed to return URL of ImageField and FileField. See here: https://github.com/toastdriven/django-tastypie/blob/master/tastypie/fields.py#L185

# Try to return the URL if it's a ``File``, falling back to the string
# itself if it's been overridden or is a default.
return getattr(value, 'url', value)

Please make sure that you are using the latest version of TastyPie.

Community
  • 1
  • 1
Irfan
  • 684
  • 5
  • 15
  • I know why Tastypie returns the file's path now. The image field's url attribute returns the its path because my upload_to function returns a full path but not a relative path. – reasonsolo Apr 15 '12 at 07:00
  • is it possible to disable this? – zVictor Jun 18 '12 at 02:34