You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_django/containers/forms.py

35 lines
1.1 KiB
Python

from django.forms import ModelForm
from containers.models import Container
class ContainerBaseForm(ModelForm):
class Meta:
model = Container
fields = '__all__'
class ContainerReceiveForm(ContainerBaseForm):
"""
Form for creating a new Container instance.
Inherits from ContainerBaseForm.
"""
class Meta(ContainerBaseForm.Meta):
fields = ['number', 'receive_vehicle', 'damages', 'heavy_damaged', 'position',]
class ContainerExpeditionForm(ContainerBaseForm):
"""
Form for updating an existing Container instance.
Inherits from ContainerBaseForm.
"""
class Meta(ContainerBaseForm.Meta):
fields = ['number', 'expedition_vehicle', 'position', 'line', 'container_type', 'damages', 'heavy_damaged']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
readonly_fields = ['number', 'position', 'line', 'container_type', 'damages', 'heavy_damaged']
for field in readonly_fields:
self.fields[field].widget.attrs['readonly'] = True
self.fields[field].disabled = True