~fo0bar/turku/bionic

« back to all changes in this revision

Viewing changes to turku_api/admin.py

  • Committer: Ryan Finnie
  • Date: 2020-03-24 21:50:17 UTC
  • Revision ID: ryan@finnie.org-20200324215017-6ojkdzl1mbq2jlqp
Add compatibility for Django 1.8~1.11 (xenial/bionic)

- Disable admin form "related links" (form children links) -- broken as of
  1.8, would be nice to have back if someone can figure out a replacement
- Add "fields = '__all__'" to admin forms
- Remove south migrations
- Port TEMPLATE_DIRS to TEMPLATES
- Change urlpatterns from patterns() to url() list
  
Changes have been tested as being backwards compatible to 1.6 (trusty).

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
    def render_change_form(self, request, context, *args, **kwargs):
61
61
        related_links = []
62
 
        if 'object_id' in context:
63
 
            for obj in self.model._meta.get_all_related_objects():
64
 
                count = obj.model.objects.filter(**{obj.field.name: context['object_id']}).count()
65
 
                related_links.append((obj, count))
 
62
        # Broken in Django 1.8+; see if related_links can be re-implemented
 
63
        #if 'object_id' in context:
 
64
        #    for obj in self.model._meta.get_all_related_objects():
 
65
        #        count = obj.model.objects.filter(**{obj.field.name: context['object_id']}).count()
 
66
        #        related_links.append((obj, count))
66
67
        context.update({'related_links': related_links})
67
68
 
68
69
        return super(CustomModelAdmin, self).render_change_form(request, context, *args, **kwargs)
71
72
class MachineAdminForm(forms.ModelForm):
72
73
    class Meta:
73
74
        model = Machine
 
75
        fields = '__all__'
74
76
 
75
77
    def __init__(self, *args, **kwargs):
76
78
        super(MachineAdminForm, self).__init__(*args, **kwargs)
80
82
class StorageAdminForm(forms.ModelForm):
81
83
    class Meta:
82
84
        model = Storage
 
85
        fields = '__all__'
83
86
 
84
87
    def __init__(self, *args, **kwargs):
85
88
        super(StorageAdminForm, self).__init__(*args, **kwargs)