mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-03-16 22:40:25 +00:00
Fixed example in README. ObjectDownloadView now use 'file_field' argument instead of 'file_attribute', in order to mimic 'slug_field'.
This commit is contained in:
parent
d48a3d9052
commit
7f1801c684
2 changed files with 5 additions and 4 deletions
5
README
5
README
|
|
@ -18,10 +18,11 @@ Example, in some urls.py:
|
|||
from demoproject.download.models import Document # A model with a FileField.
|
||||
|
||||
|
||||
download = ObjectDownloadView.as_view(model=Document, file_attribute='file')
|
||||
# ObjectDownloadView inherits from django.views.generic.BaseDetailView.
|
||||
download = ObjectDownloadView.as_view(model=Document, file_field='file')
|
||||
|
||||
url_patterns = ('',
|
||||
url('^download/file.pdf$', download, name='download'),
|
||||
url('^download/(?P<slug>[A-Za-z0-9_-]+)/$', download, name='download'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ class DownloadView(DownloadMixin, View):
|
|||
|
||||
|
||||
class ObjectDownloadView(DownloadMixin, BaseDetailView):
|
||||
file_attribute = 'file'
|
||||
file_field = 'file'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.file = getattr(self.object, self.file_attribute)
|
||||
self.file = getattr(self.object, self.file_field)
|
||||
return self.render_to_response()
|
||||
|
|
|
|||
Loading…
Reference in a new issue