I have the following code:
class Album(models.Model):
name = models.CharField(max_length=255, unique=True, null=False)
rating = models.ForeignKey("Rating", null=False)
class Rating(models.Model):
value = models.IntegerField(null=False, default=0)
What is the best way (in the django/python philosophy) to create an object (Album) and it's sub object (Rating) and save it?
I have done this:
a = Album()
a.name = "..."
r = Rating()
r.save()
a.rating = r
a.save()
I don't like this because the part of creating the sub object empty is totally not useful. I'd prefer some simple way like this - the sub-object should be created automatically:
a = Album()
a.name = "..."
a.save()