1๐
โ
I think you are getting confused, try this:
class ImageModel(models.Model):
image = models.ImageField()
class MyFirstModel(models.Model):
name = ...
image = models.ForeignKey(Image)
> image_model_instance = ImageModel()
> image_model_instance.save()
> first_model_instance = MyFirstModel(name="foo")
> first_model_instance.image = image_model_instance
> first_model_instance.save()
There is a create()
function, but it is used for creating and saving new instances of a model:
first_model_instance = MyFirstModel.objects.create(Name="foo")
so the same as:
first_model_instance = MyFirstModel()
first_model_instance.save()
๐คTimmy O'Mahony
Source:stackexchange.com