Schlabonski 9 years ago
commit f9d85d0337

@ -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. 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 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, ... 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."

@ -1,4 +1,6 @@
from django.contrib import admin 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 from .models import MaterialPart, Ownership
@ -13,10 +15,30 @@ class OwnershipInline(admin.StackedInline):
extra = 0 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): class MaterialAdmin(admin.ModelAdmin):
"""Edit view of a MaterialPart""" """Edit view of a MaterialPart"""
list_display = ('name', 'buy_date', 'lifetime', 'not_too_old', 'photo') list_display = ('name', 'buy_date', 'lifetime', 'not_too_old', 'photo')
inlines = [OwnershipInline] inlines = [OwnershipInline]
list_filter = (NotTooOldFilter,)
admin.site.register(MaterialPart, MaterialAdmin) admin.site.register(MaterialPart, MaterialAdmin)

@ -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"
}
}
]
Loading…
Cancel
Save