poulpe/equipment/admin.py

36 lines
1,017 B
Python
Raw Normal View History

2018-07-26 15:53:42 +02:00
from django.contrib import admin
2018-08-02 17:55:27 +02:00
from django import forms
2018-07-26 15:53:42 +02:00
from .models import Equipment, EquipmentRemark
2018-08-02 17:55:27 +02:00
from .fields import IdField, IdWidget
class IdForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
print("looooooooooooooooooooool")
if 'min_value' in kwargs:
kwargs.pop('min_value')
super(IdForm, self).__init__(*args, **kwargs)
for field in self.instance._meta.fields:
if isinstance(field, IdField):
self.fields[field.name].choices = list(range(1, 12))
self.fields[field.name].widget = IdWidget()
print(self.fields[field.name].choices)
print(self.fields.values())
2018-07-26 15:53:42 +02:00
class EquipmentRemarkExtraInline(admin.TabularInline):
model = EquipmentRemark
extra = 0
2018-08-02 17:55:27 +02:00
form = IdForm
2018-07-26 15:53:42 +02:00
class EquipmentAdmin(admin.ModelAdmin):
list_display = ['name', 'stock']
ordering = ['name']
inlines = [EquipmentRemarkExtraInline]
admin.site.register(Equipment, EquipmentAdmin)
2018-08-02 17:55:27 +02:00