On Feb 24, 5:09 am, Margie <margierogin...@yahoo.com> wrote: > Ok - I think I should actually be using initial - but still haven't > gotten that to actually work. I'm trying something like this: > > In models.py > class Book(models.Model): > title = models.CharField(max_length=100) > authors = models.ManyToManyField(Author) > pulisher = models.ForeignKey(Publisher, blank=True, null=True) > > In forms.py > class BookForm(forms.modelForm): > def __init__(self, myQueryset, *args, **kwargs): > self.fields['authors'].queryset = myQuerySet > > in views.py: > > bookObj = ... some prexisting book object > authorChoices=Author.objects.filter(somefilter) > bookForm = BookForm(authorChoices, initial={'authors':bookObj.authors} > > Should this work? > > Margie
Maybe (although there are some issues with the order of the arguments in your __init__), but it's unnecessary. if you're using a ModelForm to edit an existing instance, you should pass it in when you instantiate the form. bookObj = whatever bookForm = BookForm(instance=bookObj) And that way, when you save the form, it will save the changes to the instance, rather than creating a new one. -- 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-users@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 -~----------~----~----~----~------~----~------~--~---