network_inventory/computers/forms.py
Andreas Zweili 19eae6768a remove the various formsets from the computer forms
The formsets are currently just too much of a hasle. I can do 90% of the
functionality I want without them and don't have problems with adding a new
relationship everytime I'm updating the computer object.
2020-05-26 23:25:21 +02:00

34 lines
881 B
Python

import floppyforms.__future__ as forms
from core import utils
from computers.models import Computer
class ComputerCreateForm(forms.ModelForm):
class Meta:
model = Computer
fields = (
'name',
'customer',
)
def __init__(self, user=None, *args, **kwargs):
"""
If the user is not a superuser it's always assigned to a customer which
we can use to assign to the field.
"""
super(ComputerCreateForm, self).__init__(*args, **kwargs)
if not user.is_superuser:
self.fields['customer'].queryset = utils.get_customers(user)
class ComputerUpdateForm(forms.ModelForm):
"""
Basic form class to use crispies HTML5 forms.
"""
class Meta:
model = Computer
fields = '__all__'
exclude = ('net', 'cpu', 'ram', 'gpu', 'disks', 'software')