I have the following model in my app, using the content-type django framework in version 1.6.1 :
-- class GenericMedia(models.Model): limit = models.Q(model = 'Image') | models.Q(model = 'Video') | models.Q(model = 'Other') content_type = models.ForeignKey(ContentType, limit_choices_to = limit) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') def __unicode__(self): return u"%s" % os.path.basename(self.content_object.url.name) def instance(self): return self.content_object.__class__.__name__ class Media(models.Model): description = models.CharField(blank = True, max_length = 500) link = models.URLField(blank = True) genericFK = generic.GenericRelation(GenericMedia, content_type_field='content_type', object_id_field='object_id') class Meta: abstract = True def __unicode__(self): return u"%s" % os.path.basename(self.url.name) def save(self, *args, **kwargs): super(Media, self).save(*args, **kwargs) generic_link = GenericMedia(content_object = self) generic_link.save() class Image(Media): imgW = models.PositiveSmallIntegerField() imgH = models.PositiveSmallIntegerField() url = models.ImageField(upload_to = 'mediamanager', height_field = 'imgH', width_field = 'imgW')
Everythings works fine, excepts the GenericRelation in my abstract Media Class.
In django documentation it is said that :
If you delete an object that has a GenericRelation, any objects which have a GenericForeignKey pointing at it will be deleted as well.
But my problem is that when I delete an image (wich extends Media), the GenericMedia pointing to it is not deleted.
If anyone has a solution, thanks !
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9a090654-0298-4cfd-a71b-c815cca53ee0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment