I have models with GenricForeigKey and GenericRelation fields.
class Datasheet(models.Model):
package1 = GenericRelation('PackageInstance')
...
class PackageInstance(models.Model):
content_object = GenericForeignKey()
object_id = models.PositiveIntegerField(null=True)
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.CASCADE)
....
I am migrating from another models, inside my migration I want to create new instance.
for ds in Datasheet.objects.all():
pi = PackageInstance.objects.create(content_object=ds)
However this fails
TypeError: DesignInstance() got an unexpected keyword argument 'content_object'
Additionally, ds.package1.all()
will also fail.
AttributeError: 'Datasheet' object has no attribute 'package1'
How do I solve this?