{
"info": {
"author": "",
"author_email": "",
"bugtrack_url": null,
"classifiers": [],
"description": "as profile pictures, foto albums etc...\n\nHome-page: https://github.com/bitmazk/django-user-media\nAuthor: Martin Brochhaus\nAuthor-email: martin.brochhaus@bitmazk.com\nLicense: The MIT License\nDescription: Django User Media\n =================\n \n Almost all modern web apps allow their users to upload content such as audio,\n video or images. This raises a number of issues if that content should not be\n visible to the whole world by default.\n \n If you add an ImageField to your user model, you need to come up with a good\n idea on how to save those images. It is probably not a good idea to keep the\n original filenames as they might disturb your server's file system and open\n doors for hackers, who might try to brute-force against your\n ``/media/user_profiles/`` in the hope to steal some valuable files.\n \n Since it seems inevitable to implement a function for Django's FileField's\n ``upload_to`` attribute I thought that this might be a candidate for a reusable\n app.\n \n \n Prerequisites\n -------------\n \n You need at least the following packages in your virtualenv:\n \n * Django\n * django-libs\n * easy_thumbnails\n * django-generic-positions\n * simplejson\n \n \n Installation\n ------------\n \n To get the latest stable release from PyPi::\n \n $ pip install django-user-media\n \n To get the latest commit from GitHub::\n \n $ pip install -e git://github.com/bitmazk/django-user-media.git#egg=user_media\n \n Add the app to your ``INSTALLED_APPS``::\n \n INSTALLED_APPS = [\n ...\n 'user_media',\n 'easy_thumbnails',\n 'django_libs',\n 'generic_positions',\n \n ]\n \n Hook the app into your main ``urls.py``::\n \n urlpatterns += patterns('',\n ...\n url(r'^umedia/', include('user_media.urls')),\n )\n \n Run the migrations to create the app's database tables::\n \n $ ./manage.py migrate user_media\n \n \n Usage\n -----\n \n \n Add generic relation\n ++++++++++++++++++++\n \n Let's assume that you have a ``UserProfile`` model and you want to add an\n ``avatar`` field to that model.\n \n First you might want to add a [``GenericRelation``](https://docs.djangoproject.com/en/1.8/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericRelation) to your ``UserProfile``\n model::\n \n from django.contrib.contenttypes import fields\n \n \n class UserProfile(models.Model):\n ...\n user = models.ForeignKey(\n getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),\n )\n \n avatar = fields.GenericRelation(\n 'user_media.UserMediaImage',\n )\n \n \n Add property\n ++++++++++++\n \n Now you will be able to get all uploaded images that belong to a\n ``UserProfile`` by doing this::\n \n profile = UserProfile.objects.get(pk=1)\n images = profile.avatar.all()\n \n It makes sense to add a convenience method to your ``UserProfile`` model::\n \n class UserProfile(models.Model):\n ...\n @property\n def avatar(self):\n try:\n return self.avatar.all()[0]\n except IndexError:\n return None\n \n \n Add link to update form\n +++++++++++++++++++++++\n \n In your templates you can now provide a link to the image creation view like\n this (assuming that your ``UserProfile`` object is called ``object`` in the\n template's context)::\n \n Upload your picture\n \n Note that ``userprofile`` is the model name that the ``ContentType`` of your\n ``UserProfile`` model would return. You can figure this out with ``./manage.py\n shell`` for example::\n \n $ ./manage.py shell\n In [1]: from django.contrib.contenttypes.models import ContentType\n In [2]: from your_app.models import UserProfile\n In [3]: ContentType.objects.get_for_model(UserProfile).model\n Out [1]: u'userprofile'\n \n When visiting that link, the user will see an image upload form. You might\n want to override that template (``user_media/usermediaimage_form.html``).\n \n After uploading the image the view should redirect back to the absolute url\n of your ``UserProfile``. If you want to redirect to another URL, you can\n provide a ``next`` URL parameter via POST or GET::\n \n Upload your picture\n \n \n Display images\n ++++++++++++++\n \n Now you should have all building blocks that you need to add links or buttons\n to your templates that call the views of this application. On your\n ``UserProfile`` detail view you could display the avatar, if available::\n \n {% if object.avatar %}\n \n {% endif %}\n \n \n Delete and edit images\n ++++++++++++++++++++++\n \n Or in your ``UserProfile`` update view you could display a link to upload a\n new image or to delete the existing image::\n \n {% if form.instance.get_avatar %}\n