zelsky
@zelsky

Убрать каскадное удаление Generic Relation?

Две модели
AModel
    field_custom_id  = models.PositiveIntegerField(
        blank=True,
        null=True,
        db_index=True
    )
    field_custom_type = models.ForeignKey(
        'contenttypes.ContentType',
        on_delete=models.SET_NULL,
        blank=True,
        null=True,
        db_index=True
    )
    field_custom  = GenericForeignKey('field_custom_type', 'field_custom_id')

BModel
    fidl_fild = GenericRelation(
        AModel,
        related_query_name='customqueryname',
        content_type_field='field_cusntom_type_one',
        object_id_field='field_cusnto_id_one',
    )

Так вот при удалении инстанса модели Б удаляеться и инстанс модели А. Как в сигнале избежать удаления модели А ?
В доках только такое
Unlike ForeignKey, GenericForeignKey does not accept an on_delete argument to customize this behavior; if desired, you can avoid the cascade-deletion simply by not using GenericRelation, and alternate behavior can be provided via the pre_delete signal.
  • Вопрос задан
  • 124 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы