A noob question, I’m afraid. I have a database with several classes, among them the class picture and page:
class Picture(models.Model):
picture_uuid = models.CharField(max_length=36)
class Page(models.Model):
page_uuid = models.CharField(max_length=36)
pictures = models.ManyToManyField(Picture)
Creating new pictures entries in my database is straight forward:
newPic = Picture.objects.create(picture_uuid="SAMPLE-UUID")
newPic2 = Picture.objects.create(picture_uuid="SAMPLE2-UUID")
newPic3 = Picture.objects.create(picture_uuid="SAMPLE3-UUID")
etc.
However, I have no idea how to add these pictures to a certain page:
newPage = Page.objects.create(page_uuid="SAMPLE-PAGE-UUID", pictures= … )
What if I wanted to achieve this programatically, i.e. adding my three pictures to this newPage?
Just do it in the next statement:
In the docs