4
You need to assign the Group
instance to the Group_Cover
one. More or less so:
if form.is_valid():
from myapp.models import Group
new_group = Group()
new_group.group_name = form.cleaned_data['group_name']
new_group.save()
from myapp.models import Group_Cover
new_cover = Group_Cover()
new_cover.group_cover = request.FILES['group_cover']
new_cover.group = new_group # This line assigns it
new_cover.save()
2
You have not specified the group while initializing Group_Cover
.
Instead of following code:
new_cover = Group_Cover()
Use the following:
new_cover = Group_Cover(group=new_group)
- [Django]-How can I combine two views and two forms into one single template?
- [Django]-Django – Create a dropdown list from database
- [Django]-Django templates loops
- [Django]-How to redirect to a newly created object in Django without a Generic View's post_save_redirect argument
2
new_cover = Group_Cover(group=new_group)
new_cover.group_cover = request.FILES['group_cover']
new_cover.save()
Need to tell Django what group you are refering to (see group=new_group
)
Source:stackexchange.com