diff --git a/README.md b/README.md index 8af14bd..2088544 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,15 @@ This repository has the purpose to develop a webapplication that can be used by JDAV to send newsletters, manage user lists and keep material lists up to date. As this repository is also meant to be a base for exchange during development, feel free to contribute ideas in form of edits to this README, issues, landmarks, projects, wiki entries, ... + +# Useful stuff + +## Reset database for certain app + +The following can be useful in case that automatic migrations throw errors. + +1. delete everything in the migrations folder except for __init__.py. +2. drop into my MySQL console and do: DELETE FROM django_migrations WHERE app='my_app' +3. while at the MySQL console, drop all of the tables associated with my_app. +4. re-run ./manage.py makemigrations my_app - this generates a 0001_initial.py file in my migrations folder. +5. run ./manage migrate my_app - I expect this command to re-build all my tables, but instead it says: "No migrations to apply." diff --git a/jdav_web/material/admin.py b/jdav_web/material/admin.py index 782b960..986ab8d 100644 --- a/jdav_web/material/admin.py +++ b/jdav_web/material/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin +from django.utils. translation import ugettext_lazy as translate +from django.contrib.admin import SimpleListFilter from .models import MaterialPart, Ownership @@ -13,10 +15,30 @@ class OwnershipInline(admin.StackedInline): extra = 0 +class NotTooOldFilter(SimpleListFilter): + title = translate('Age') + parameter_name = 'age' + + def lookups(self, request, model_admin): + return ( + ('too_old', translate('Not Too Old')), + ('not_too_old', translate('Too old')), + ) + + def queryset(self, request, queryset): + if self.value() == 'too_old': + return queryset.filter(pk__in=[x.pk for x in queryset.all() if x.not_too_old()]) + if self.value() == 'not_too_old': + return queryset.filter(pk__in=[x.pk for x in queryset.all() if not x.not_too_old()]) + + + class MaterialAdmin(admin.ModelAdmin): """Edit view of a MaterialPart""" list_display = ('name', 'buy_date', 'lifetime', 'not_too_old', 'photo') inlines = [OwnershipInline] + list_filter = (NotTooOldFilter,) + -admin.site.register(MaterialPart, MaterialAdmin) +admin.site.register(MaterialPart, MaterialAdmin) \ No newline at end of file diff --git a/jdav_web/material/materials.json b/jdav_web/material/materials.json new file mode 100644 index 0000000..32c2bac --- /dev/null +++ b/jdav_web/material/materials.json @@ -0,0 +1,38 @@ +[ + { + "model": "material.MaterialPart", + "pk": "1", + "fields": { + "name": "Seil 40m grĂ¼n", + "buy_date": "2016-01-01", + "lifetime": "3" + } + }, + { + "model": "material.MaterialPart", + "pk": "2", + "fields": { + "name": "Seil 40m blau", + "buy_date": "2012-01-01", + "lifetime": "3" + } + }, + { + "model": "material.MaterialPart", + "pk": "3", + "fields": { + "name": "Seil 60m gelb", + "buy_date": "2013-01-01", + "lifetime": "3" + } + }, + { + "model": "material.MaterialPart", + "pk": "4", + "fields": { + "name": "Seil 60m blau", + "buy_date": "2016-01-01", + "lifetime": "3" + } + } +] \ No newline at end of file