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
.
π€Daniel Roseman
- [Answer]-Django database and information history
- [Answer]-What *exactly* is the relationship with the models when using ForeignKey or ManyToMany
- [Answer]-Remove NULL in desc date ordering
- [Answer]-Django Ajax Validation
- [Answer]-Django WeekArchiveView: Have urls start at 1
Source:stackexchange.com