Skip to content

Instantly share code, notes, and snippets.

@madzak
Created December 11, 2011 05:30
Show Gist options
  • Save madzak/1458592 to your computer and use it in GitHub Desktop.
Save madzak/1458592 to your computer and use it in GitHub Desktop.
class AdminHostingForm(forms.ModelForm):
total_users = ReadOnlyField()
def __init__(self, *args, **kwargs):
super(AdminHostingForm, self).__init__(*args, **kwargs)
instance = getattr(self, 'instance', None)
self.fields['account_manager'] = forms.ChoiceField(required=False)
try:
accountManagers = OeUsers("datalogicaccountmgr")
if instance and instance.id:
if instance.contract_type == 'SA':
accountManagers = OeUsers("sagesalesrepresentatives")
self.fields['account_manager'].choices = [('', '----------')] + [(user["id"], user["fullname"]) for user in accountManagers.users]
except:
self.fields['account_manager'].choices = [('', '----------')]
self.fields['technician'].choices = [('', '--------')] + [(user.id, user.get_full_name()) for user in User.objects.filter(groups__name='technician')]
class Meta:
model = Hosting
fields = (
'total_users',
'status',
'account_manager',
'technician',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment