Limit the dropdowns to only allowed items
This commit is contained in:
parent
f10e4f7800
commit
afff82b423
|
@ -1,7 +1,10 @@
|
|||
import floppyforms.__future__ as forms
|
||||
|
||||
from guardian.shortcuts import get_objects_for_user
|
||||
|
||||
from .models import Computer
|
||||
from customers.models import Customer
|
||||
from users.models import User
|
||||
|
||||
|
||||
class ComputerCreateForm(forms.ModelForm):
|
||||
|
@ -33,4 +36,15 @@ class ComputerUpdateForm(forms.ModelForm):
|
|||
'location',
|
||||
'user',
|
||||
'installation_date',
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, user=None, *args, **kwargs):
|
||||
super(ComputerUpdateForm, self).__init__(*args, **kwargs)
|
||||
if not user.is_superuser:
|
||||
customers = get_objects_for_user(user,
|
||||
'customers.view_customer',
|
||||
klass=Customer)
|
||||
|
||||
self.fields['customer'].queryset = customers
|
||||
self.fields['user'].queryset = User.objects.filter(
|
||||
customer__in=customers)
|
||||
|
|
Loading…
Reference in New Issue