From f2bee50968a9a1833ebf4d95c0ab435527eb24b5 Mon Sep 17 00:00:00 2001 From: "F. Malina" Date: Mon, 16 Sep 2024 14:29:26 +0200 Subject: [PATCH] Update README.md --- README.md | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 070d69e..bbdd5a3 100644 --- a/README.md +++ b/README.md @@ -23,30 +23,30 @@ upload.js uses the W3C File API ## Installation (into a Django project) To get the latest version from GitHub - - pip3 install -e git+git://github.com/fmalina/upload.git#egg=upload - +```bash +pip3 install -e git+git://github.com/fmalina/upload.git#egg=upload +``` Add `upload` to your `INSTALLED_APPS` - - INSTALLED_APPS = ( - ..., - 'upload', - ) - +```python +INSTALLED_APPS = ( + ..., + 'upload', +) +``` Configure your settings to suit, see upload/app_settings.py. You can use the collection model provided. Add the `upload` URLs to your `urls.py` - - urlpatterns = [ - ... - url(r'^upload/', include('upload.urls')), - ] - +```python +urlpatterns = [ + ... + url(r'^upload/', include('upload.urls')), +] +``` Create your tables - - ./manage.py migrate upload - +```bash +./manage.py migrate upload +``` ## Usage ### Setup a collection @@ -76,37 +76,37 @@ Simple integration works out of the box. To upload files for any model taking advantage of generic foreign key, link: - - Upload - +```html +Upload +``` So a profile picture upload link might look like: - - Upload - +```html +Upload +``` An important view to reuse or use as inspiration in a custom integration is `views_post.FilesEditView`. ### Example settings ```python - import os +import os - APP_ROOT = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..')) +APP_ROOT = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..')) - STATIC_URL = '/static/' - MEDIA_URL = '/media/' - STATIC_ROOT = APP_ROOT + STATIC_URL - MEDIA_ROOT = STATIC_ROOT + 'media/' +STATIC_URL = '/static/' +MEDIA_URL = '/media/' +STATIC_ROOT = APP_ROOT + STATIC_URL +MEDIA_ROOT = STATIC_ROOT + 'media/' ``` ### Access control You can control editing access by implementing `is_editable_by` method on your collection model such as: ```python - def is_editable_by(self, user): - if user.pk == self.user_id or user.is_staff: - return True - return False +def is_editable_by(self, user): + if user.pk == self.user_id or user.is_staff: + return True + return False ``` The above ensures that a collection is only editable by its user and staff.