mirror of
https://github.com/Nebucatnetzer/network_inventory.git
synced 2024-07-02 14:11:03 +02:00
19eae6768a
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.
34 lines
881 B
Python
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')
|