GenericForeignKey field can't be set on init of model
|Reported by:||dpantele||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If we are trying to set GenericForeignKey to non-saved object during model initialization, it is not set.
class A(models.model): pass class B(models.model): object_id = models.PositiveIntegerField() content_type = models.ForeignKey(ContentType) obj = generic.GenericForeignKey() ... a = A() b = B(obj=a) b.obj # None b.obj.save() # 'NoneType' object has no attribute 'save'
Change History (9)
comment:1 Changed 4 years ago by dpantele
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from GenericForeignKey field can't be set on init of moel to GenericForeignKey field can't be set on init of model