3

tastypie api does't support upload file, so I have to use normal view function,check out my other question

this is my image resource

 class ImageResource(ModelResource):
     album = fields.ForeignKey(AlbumResource, 'album')
     upload_by = fields.ForeignKey(UserResource, 'upload_by')

     class Meta:
         always_return_data=True
         filtering = {
                 "album": ('exact',),
                  }
         queryset = Image.objects.all()
         cache = SimpleCache(timeout=100)
         resource_name = 'image'
         authorization = ImageAuthorization()

now suppose I upload an image in normal view function, because I set the cache timeout to 100 sec, the browser won't update the query in 100sec.

what I want is browser update the query immediately after the image uploaded, and keep cache timeout to 100 sec if nothing changed.and this have to be done in normal view function.

How can I do this?

Community
  • 1
  • 1
paynestrike
  • 4,348
  • 14
  • 46
  • 70
  • Are you sure that tasty pie doesn't support file upload? [This question](http://stackoverflow.com/questions/12381016/django-tastypie-any-example-on-file-upload-in-post) seems to indicate that it is possible to do so. – NT3RP Jun 05 '13 at 20:24
  • well,I tried every method in [example1](http://stackoverflow.com/questions/12381016/django-tastypie-any-example-on-file-upload-in-post),[example2](http://stackoverflow.com/questions/14119031/how-do-you-upload-a-file-with-a-post-request-on-django-tastypie),and [example3](https://groups.google.com/forum/?fromgroups#!topic/django-tastypie/2blsUptBbm0), I can't get it work, on the other hand upload in normal view is so simple! – paynestrike Jun 06 '13 at 03:28

1 Answers1

0

You can clear the cache manually if you like. Tastypie's cache key looks something like this (if You're using simpleCache)

def generate_cache_key(self, *args, **kwargs):
    """
    Creates a unique-enough cache key.

    This is based off the current api_name/resource_name/args/kwargs.
    """
    smooshed = []

    for key, value in kwargs.items():
        smooshed.append("%s=%s" % (key, value))

    # Use a list plus a ``.join()`` because it's faster than concatenation.
    return "%s:%s:%s:%s" % (self._meta.api_name, self._meta.resource_name, ':'.join(args), ':'.join(smooshed))

(Thats straight from the code currently at line 1031)

You can play around in the shell to make sure you've got an exact hit on the object you're looking for. Once you've got that, simply delete the entry when you're uploading a file.

Gevious
  • 3,214
  • 3
  • 21
  • 42