[Answer]-Inline_formset missing field

1πŸ‘

βœ…

I think that inlineformset does not include a form for Album Model. You have to create a separate ModelForm for Album and then do something like {{album_form.name}}.

You can associate you formsets with the ForeignKey to the Album with Something like this in you view-

# validation and other code
# ---------------------------
new_album = Album()
new_album_form = AlbumModelForm(request.POST,instance=new_album)
song_formset = AlbumFormset(request.POST)
new_album_form.save()
songs = song_formset.save(comit=False)
for song in songs:
    song.album = new_album
    song.save()

EDIT:

The above solution may work if you want to create one Album and multiple Songs with foreign key to that album. To get what you wanted ie {{form.name}},{{form.title}} and {{form.artist}} use normal formset with name,title and artist fields instead of modelformset.

πŸ‘€machaku

0πŸ‘

There isn’t a name field in the form. The form is for Songs, and they have album, title and artist.

Leave a comment