From e3787c684c504479196a310449c09e7a40619a7e Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 28 Nov 2016 17:25:57 +0100 Subject: [PATCH] simple reverse relation from Related --- aircox/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aircox/models.py b/aircox/models.py index c653416..584b33c 100755 --- a/aircox/models.py +++ b/aircox/models.py @@ -89,6 +89,13 @@ class Related(models.Model): objects = RelatedManager() + @classmethod + def ReverseField(cl): + """ + Return a GenericRelation object that points to this class + """ + return GenericRelation(cl, 'related_id', 'related_type') + class Meta: abstract = True @@ -791,7 +798,7 @@ class Diffusion(models.Model): start = models.DateTimeField( _('start of the diffusion') ) end = models.DateTimeField( _('end of the diffusion') ) - tracks = GenericRelation(Track, 'related_id', 'related_type') + tracks = Track.ReverseField() @property def duration(self): @@ -929,7 +936,7 @@ class Sound(Nameable): help_text = _('the sound is accessible to the public') ) - tracks = GenericRelation(Track, 'related_id', 'related_type') + tracks = Track.ReverseField() def get_mtime(self): """