On Thu, Oct 2, 2008 at 8:46 AM, oversize <[EMAIL PROTECTED]> wrote: > > Hello > > in a ModelForm based Form, i have a ManyToManyField. I want only > specific objects of the Relation to be shown in the Forms > ModelMultipleChoiceField. > For my example, Motive and Textile belong to the same Project, and i > want only the Motives to Show in the ModelMultipleChoiceField that are > related to the same project as the Textile Instance is. > > > Models and the Form : > > class Motive(models.Model): > # ... > project = models.ForeignKey(Project) > > class Textile(models.Model): > # ... > project = models.ForeignKey(Project) > motives = models.ManyToManyField('Motive', blank=True) > > class TextileForm(forms.ModelForm): > def __init__(self, project_id): > super(TextileForm, self).__init__() > self.motives.queryset = > Motive.objects.filter(project=project_id) > > class Meta: > model = Textile > exclude = ('project', 'last_modified', 'trashed') > > > When i create the Form i get the Exception: 'TextileForm' object has > no attribute 'motives' > > How could access the ModelMultipelChoiceField to alter the QuerySet? >
Try: self.fields['motives'].queryset = your_custom_queryset in your __init__ method instead of what you have. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---