35 lines
1,017 B
Python
35 lines
1,017 B
Python
from django.contrib import admin
|
|
from django import forms
|
|
|
|
from .models import Equipment, EquipmentRemark
|
|
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())
|
|
|
|
|
|
class EquipmentRemarkExtraInline(admin.TabularInline):
|
|
model = EquipmentRemark
|
|
extra = 0
|
|
form = IdForm
|
|
|
|
|
|
class EquipmentAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'stock']
|
|
ordering = ['name']
|
|
inlines = [EquipmentRemarkExtraInline]
|
|
|
|
|
|
admin.site.register(Equipment, EquipmentAdmin)
|
|
|