Need help understanding why the below is happening.
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I've attempted to get help in the #django IRC but with no luck. I hope you can assist.
""" How is this possible ??? Every time I refresh the page more 'same' choices get added to the fields choice options. That is: First time I will get: a b Second refresh a b a b and so on.... ??? I don't get how this is happening. """ ### in view form = AdForm(instance=ad) AdTargetFormSet = modelformset_factory(AdTarget, form=AdTargetForm, can_delete=True) AdTargetFormSet.form = staticmethod(curry(AdTargetForm, objects=[Competition.objects.all()])) adtarget_formset = AdTargetFormSet(queryset=AdTarget.objects.filter(ad=ad)) ### my form class AdTargetForm(ModelForm): ''' Creates and AdTargetForm Takes an argument that is a list of objects to generate the url pattern - the object must have a valid get_absolute_url defined. for example AdTargetForm(objects=[Competition.objects.all(), Team.objects.all()] ''' # create the ad tragets lists AD_TARGETS = [ ('', '...'), ('.*', 'The Entire Site'), ('^/$', 'Home Landing Page'), ] def __init__(self, objects=None, *args, **kwargs): super(AdTargetForm, self).__init__(*args, **kwargs) if (objects): for object_list in objects: # @TODO: add the object landing page for obj in object_list: self.AD_TARGETS.append(('^%s$' % obj.get_absolute_url(), str(obj))) self.fields['url_pattern'].choices = self.AD_TARGETS url_pattern = forms.ChoiceField(label='Target', choices = AD_TARGETS) class Meta: model = AdTarget fields = () # show these fields from model exclude = ('ad') # exclude these fields from model