from django import forms from .models import Organization class NetworkForm(forms.Form): name = forms.CharField(label="Common Name", max_length=64) intip = forms.GenericIPAddressField(label="Internal IP Address", protocol="ipv4") extip = forms.GenericIPAddressField(label="External IP Address", protocol="ipv4") orgas = forms.MultipleChoiceField(label="Assigned Organizations", choices=[(orga.id, str(orga)) for orga in Organization.objects.all()]) def __init__(self, user, *args, **kwargs): super(NetworkForm, self).__init__(*args, **kwargs) self.fields['orgas'].choices = [(orga.id, str(orga)) for orga in user.organization_set.all()] class OrgaForm(forms.Form): name = forms.CharField(label="Common Name", max_length=64) users = forms.IntegerField(label="User Limit", required=False)