implement image upload for material app

v1-0-stable
Schlabonski 9 years ago
parent dd7d98dacf
commit 0a5f4f74e1

4
.gitignore vendored

@ -92,3 +92,7 @@ jdav_web/db.sqlite3
# django database migrations
*/*/migrations/*
# test images for file upload
*.jpeg
*.png

@ -27,6 +27,9 @@ DEBUG = True
ALLOWED_HOSTS = []
# Define media paths e.g. for image storage
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Application definition

@ -15,8 +15,12 @@ Including another URLconf
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', include('startpage.urls'))
]
url(r'^$', include('startpage.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# TODO: django serving from MEDIA_URL should be disabled in production stage
# see http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example

@ -15,8 +15,8 @@ class OwnershipInline(admin.StackedInline):
class MaterialAdmin(admin.ModelAdmin):
"""Edit view of a MaterialPart"""
fields = ['name', 'buy_date', 'lifetime']
list_display = ('name', 'buy_date', 'lifetime', 'not_too_old')
fields = ['name', 'buy_date', 'lifetime', 'photo']
list_display = ('name', 'buy_date', 'lifetime', 'not_too_old', 'photo')
inlines = [OwnershipInline]
admin.site.register(MaterialPart, MaterialAdmin)

@ -1,5 +1,6 @@
from datetime import datetime
from decimal import Decimal
from django.db import models
from django.utils import timezone
@ -15,7 +16,9 @@ class MaterialPart(models.Model):
"""
name = models.CharField(max_length=30)
buy_date = models.DateField('purchase date', editable=True)
lifetime = models.DecimalField('lifetime (years)', decimal_places=0, max_digits=3)
lifetime = models.DecimalField('lifetime (years)', decimal_places=0,
max_digits=3)
photo = models.ImageField('photo', upload_to='images', blank=True)
def __str__(self):
"""String representation"""

Loading…
Cancel
Save