These are chat archives for CharlesGust/django-imagr
I finally was able to make the Album ModelForm work. Turns out that a M2M field can't be given data upon the instantiation of an instance. Rather, you need to create the instance (via the view function) and then assign relationships to that field, using the instance.fieldname.add(data) method syntax. Furthermore, since the .add() method only takes a single, non-iterable item for an argument, you need to add each photo one at a time. In our case, this all looks something like:
form = AlbumForm(request.POST) if form.is_valid(): new_album = Album.objects.create(user=<userObject>, title=form.cleaned_data['title']...other keyword arguments except photos...) photos = form.cleaned_data['photos'] for photo in photos: new_album.photos.add(photo) new_album.save()
Everything has been pushed to my branch of the repo. I'm really relieved that something as straightforward as injecting data into a M2M field doesn't require something as complicated as an overwrite of the ModelForm's ...init... function.