1
0

ticket_list.py 966 B

12345678910111213141516171819202122232425262728293031323334
  1. from django import forms
  2. from django.contrib.auth.models import Group
  3. from tickets.models import TicketList
  4. class TicketListForm(forms.ModelForm):
  5. def __init__(self, user, *args, **kwargs):
  6. super(TicketListForm, self).__init__(*args, **kwargs)
  7. groups = Group.objects.all()
  8. if not user.is_superuser:
  9. self.fields['group'].queryset = groups.filter(user=user)
  10. self.fields['group'].empty_label = "Select a group"
  11. class Meta:
  12. model = TicketList
  13. fields = "__all__"
  14. labels = {
  15. 'name': 'List Name',
  16. 'group': 'Group',
  17. }
  18. widgets = {
  19. 'name': forms.TextInput(attrs={
  20. 'class': 'form-control',
  21. 'placeholder': 'The full display name for this list',
  22. 'autofocus': True
  23. }),
  24. 'group': forms.Select(attrs={
  25. 'class': 'form-control',
  26. }),
  27. }