On Tuesday, January 4, 2011 7:42:16 PM UTC, mrmclovin wrote: > > Hi, > > I have a 'project' model > > class Project(models.Model): > title = models.CharField(max_length=100) > links = models.ManyToManyField('Link', related_name='link') > > and a 'link' model > > class Link(models.Model): > label = models.CharField(max_length=50) > url = models.URLField(max_length=100) > project = models.ForeignKey(Project) > > I want the user to edit his project properties. I'm using ModelForm class > and a UpdateView to put everything together. But I have a problems: > > I want the form to only show those *link*s who are owned by the project in > the MultipleChoisesWidget, hence the ForeignKey in the Link model. > > Any help on how to achieve this? Thanks! > > P.S why isn't there a proper API documentation on django like doxygen? I > find the django documentation full of content but awful structure! >
class ProjectForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ProjectForm, self).__init__(*args, **kwargs) if self.instance and self.instance.pk: self.fields['links'].queryset = Link.objects.filter(project=self.instance) class Meta: model = Project -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.