def __init__(self, user, *args, **kwargs): super(CampaignForm, self).__init__(*args, **kwargs) self.fields['campaign_code'].initial = get_unique_code(length=5) self.fields['description'].widget.attrs['class'] = "input-xlarge" if user: self.fields['ds_user'].initial = user list_pb = [] list_gw = [] list_pb.append((0, '---')) pb_list = field_list("phonebook", user) for i in pb_list: list_pb.append((i[0], i[1])) self.fields['phonebook'].choices = list_pb list_gw.append((0, '---')) gw_list = field_list("gateway", user) for i in gw_list: list_gw.append((i[0], i[1])) self.fields['aleg_gateway'].choices = list_gw from voice_app.models import VoiceApp from survey.models import SurveyApp available_objects = list(VoiceApp.objects.filter(user=user)) available_objects += list(SurveyApp.objects.filter(user=user)) object_choices = [] for obj in available_objects: type_id = ContentType.objects.get_for_model(obj.__class__).id obj_id = obj.id # form_value - e.g."type:12-id:3" form_value = "type:%s-id:%s" % (type_id, obj_id) display_text = str(ContentType.objects\ .get_for_model(obj.__class__)) + ' : ' + str(obj) object_choices.append([form_value, display_text]) self.fields['content_object'].choices = object_choices
def __init__(self, *args, **kwargs): super(CampaignAdminForm, self).__init__(*args, **kwargs) self.fields['campaign_code'].widget.attrs['readonly'] = True self.fields['campaign_code'].initial = get_unique_code(length=5)