Monday, September 30, 2019

Re: Problem with safedelete implementation

On 30/09/2019 11:33 pm, Jérôme Le Carrou wrote:
> Hi
>
> I am new on this forum and very, very new user of Django so hope you
> will be uncensorious
>
> I need to implement the safedelete application
> (https://buildmedia.readthedocs.org/media/pdf/django-safedelete/latest/django-safedelete.pdf)
> for my project but I should have miss something in the documentation
> because I did non manage tu use it correctly
>
> I will expose you briefly my problem
> I have 2 classes BiologyAssessment and BiologyExam linked with a
> foreignKey: a biologicalassessment is linked with multiple biologicalexam
>
> When I delete a biologicalassessment, I want related biologicalexamn
> to be 'delete' (but soft delete)
> When I delete a biologicalexam, I want biologicalexam to be delete
> (soft delete)
>
> I have implemented in my project but unfortunetly, when I delete a
> biologicalexam, the linked biologicalasessment is also delete
> I have try different to use _safedelete_policy = SOFT_DELETE for my
> BiologicalExam class but it does not chage anything
>
> could you help me ?
>
> models.py
>
> class BiologicalAssessment(SafeDeleteModel):
>
>     _safedelete_policy = SOFT_DELETE_CASCADE
>     ide = models.AutoField(primary_key=True)
>     vis_ref = models.ForeignKey(Visite, verbose_name='Visite',
> related_name='bilan', on_delete=models.CASCADE)

models.CASCADE will persuade Django to delete related child instances in
a cascade. It means if you delete the parent all related model instances
"below" it will also be deleted.

https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.CASCADE

I don't know what SOFT_DELETE_CASCADE is all about but it is possible
your on_delete choice is defeating it.

Mike

>     bio_prv_dat = models.DateField("Date de prélèvement")
>
> class BiologicalExam(SafeDeleteModel):
>
>     _safedelete_policy = SOFT_DELETE_CASCADE
>     ide = models.AutoField(primary_key=True)
>     bio_ref = models.ForeignKey(BiologicalAssessment,
> verbose_name='Bilans', related_name='examen', on_delete=models.CASCADE)
>     bio_exa_cod = models.CharField("Type d'examen", max_length=3)
>     bio_exa_val = models.FloatField("Résultat de l'examen")
>     bio_exa_uni = models.CharField("Unité", max_length=50)
>     bio_exa_val_inf = models.FloatField("Limite inférieure")
>     bio_exa_val_sup = models.FloatField("Limite supérieure")
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0e88df26-bd24-430d-a432-7094a194183d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0e88df26-bd24-430d-a432-7094a194183d%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8937dc44-a242-75ab-2e09-7b4fadfc368f%40dewhirst.com.au.

No comments:

Post a Comment