Create a Form Using Two Models

Can someone direct me to the documentation on how to incorporate two models in one form?

I want an initial User to be able to create both a music album and a review for that album at the same time. I was told I need to have a separate Album model and my Review model in order to aggregate the average of ratings I’ll have in a Review.

class Album(models.Model):
   artist = models.CharField(max_length=255)
   title = models.CharField(max_length=255)
   updated = models.DateTimeField(auto_now=True)
   created = models.DateTimeField(

class Review(models.Model):
   reviewer = models.ForeignKey(User, on_delete=models.CASCADE)
   album = models.ForeignKey(Album, on_delete=models.CASCADE)
   rating = models.IntegerField(
      validators=[MinValueValidator(1), MaxValueValidator(10)],
   comment = models.TextField()
   updated = models.DateTimeField(auto_now=True)
   created = models.DateTimeField(

The key point here is that you won’t be able to use a ModelForm, but a normal Form instead.

So let’s say that you want to create a Album and Music on the same form, your Form can look like:

On this example, assume that your Album and Music models has only one field (name)

# some_app/

from django import forms

class CreateAlbumMusicForm(forms.Form):
  album_name = forms.CharField()
  music_name = forms.CharField()

Then on your view, you can:

# some_app/
from . import forms, models

def create_album_music(request):
  if request.method == "GET":
    # render the form here
    form = forms.CreateAlbumMusicForm()
    return render(request, "some_template.html", context={"form": form})

  form = forms.CreateAlbumMusicForm(request.POST)
  if not form.is_valid():
    # do something here
  album = models.Album.objects.create(name=form.cleaned_data['album_name'])
  music = models.Music.objects.create(album=album, name=form.cleaned_data['music_name'])
  # do some more stuff

This also can be done directly on the save method of the form. Depends on what you’re trying to do. We usually keep business logic outside forms.

Why does everyone always want to change my model names? Basically what I want is for an initial user to be able to create a review for an album, adding all the information for an album (“artist”, “title”, “image” [eventually]), then add a review for that album at the same time (“rating”, “comment”) in the same form.
Then other Users will be able to visit that initial review and add their own reviews (just a “rating” and a “comment”).
I had to change the models because initially I had a “rating” field on the Album (named Review previously) and the Review (named AddedReview previously) but I couldn’t aggregate the average of the ratings from the two models.
So someone told me I had to create the two models as I posted above in order to be able to aggregate the averages of the "rating"s.

I don’t want you to change your model names, i just give it you a example with a basic scenario.

Your question how can you create two models using the same form:
You can create an Album, Artist, Review, anything you want using the same form, you should see that from the reply. But how you’re going to do that, is up to you.


Note: This rarely is necessary the way you have worded it here. You can render two Django forms within one HTML form tag. Each of those two forms can be ModelForms for the two models.
You just want to ensure that you use the prefix attribute on one (or both) to ensure that Django knows how to separate the data between the two.

Also, because of the dependency between the two, you will want to save the form for Album first, and use the object it returns to update the instance of the form for Reviewer before saving it.