Tuesday, January 4, 2011

Custom queryset on a ModelForm field

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 links 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!

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment