On Friday, August 12, 2016 at 1:19:17 PM UTC-6, Todor Velichkov wrote:
>
> Some more code will be helpful, for example the model structure, how do 
> you define the the `ForeignKey`? How do you subscribe for the signal?
> You are saying that with sleep(1) the code works fine, is this mean that 
> you can reproduce the problem at any time?
> However test it without fetching the blob object, this would probably fix 
> the problem:
>
> if widget.blob_id is not None and Widget.objects.filter(blob_id=widget.
> blob_id).count() == 0:
>     Blob.objects.filter(id=widget.blob_id).delete()
>
>
Hello Todor,

Your solution worked like a charm. It was fetching the blob object causing 
the failure, thank you very much! For the sake of completion, here is the 
code you asked for:

class Widget(models.Model):
    client = models.ForeignKey(Client, related_name="layers")
    label = models.TextField()
    blob = models.ForeignKey(Blob, blank=True, null=True)
    date_created = models.DateTimeField(auto_now_add=True, blank=True, null=
True)

And the connection is made using 
signals.post_delete.connect(postDeleteWidget, sender=Widget).
 

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ea379e82-a7e5-455e-9018-007af3c7c435%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to