def Translation(model):
 class Inner(models.Model, ):
  parent = models.ForeignKey(model, related_name=u'translations', on_delete=models.CASCADE)
  language_code = models.CharField(_(u'language'), max_length=10, choices=settings.LANGUAGES, default=settings.LANGUAGES[0][0], editable=(len(settings.LANGUAGES) > 1))
  class Meta:
   unique_together = (u'parent', u'language_code')
   abstract = True
  def short_language_code(self):
   return short_language_code(self.language_code)
  def save(self, *args, **kwargs):
   super(Inner, self).save(*args, **kwargs)
   self.parent.purge_translation_cache()
  save.alters_data = True
  def delete(self, *args, **kwargs):
   super(Inner, self).delete(*args, **kwargs)
   self.parent.purge_translation_cache()
  delete.alters_data = True
 return Inner

def Translation ( model ) : class Inner ( models . Model , ) : parent = models . ForeignKey ( model , related_name = u'translations' , on_delete = models . CASCADE ) language_code = models . CharField ( _ ( u'language' ) , max_length = 10 , choices = settings . LANGUAGES , default = settings . LANGUAGES [ 0 ] [ 0 ] , editable = ( len ( settings . LANGUAGES ) > 1 ) ) class Meta : unique_together = ( u'parent' , u'language_code' ) abstract = True def short_language_code ( self ) : return short_language_code ( self . language_code ) def save ( self , * args , ** kwargs ) : super ( Inner , self ) . save ( * args , ** kwargs ) self . parent . purge_translation_cache ( ) save . alters_data = True def delete ( self , * args , ** kwargs ) : super ( Inner , self ) . delete ( * args , ** kwargs ) self . parent . purge_translation_cache ( ) delete . alters_data = True return Inner
return a class which can be used as inheritance base for translation models .