The updown object doesn't removed after related object was deleted
Opened this issue · 2 comments
agusmakmun commented
hello @dbanck, I have a little problem. Let say, I have a Post
model:
@python_2_unicode_compatible
class Post(TimeStampedModel):
author = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(_('Title'), max_length=200)
....
rating = RatingField(can_change_vote=True)
After I deleted the object of post, and I check at updown.models it still exist. But the content_object
is blank. Why the Vote
object doesn't deleted also?
>>> from updown.models import Vote
>>>
>>> Vote.objects.filter(content_type__model='post', user__username='yogesh_pagal')
<QuerySet [<Vote: yogesh_pagal voted 1 on None>]>
>>>
>>> v = Vote.objects.filter(content_type__model='post', user__username='yogesh_pagal').first()
>>> v.content_object
>>>
If I check at these lines, the content_type
field already using on_delete=models.CASCADE
.
content_type = models.ForeignKey(ContentType, related_name="updown_votes",
on_delete=models.CASCADE)
or, maybe this case?
content_object = GenericForeignKey()
should change to:
content_object = GenericForeignKey('content_type', 'object_id')
I was tried this method, but still doesn't work properly.
dbanck commented
Hi there again!
Thanks for the PR! But I'm not entire sure if the change fixes your problem. Did you try it and it's working properly?
agusmakmun commented
hello @dbanck, not yet. I am also looking a solution for this issue.