def pre_save(self, model_instance, add):
     val = super(TranslationField, self).pre_save(model_instance, add)
     if get_default_language() == self.language and not add:
         # Rule is: 3. Assigning a value to a translation field of the
         # default language also updates the original field
         model_instance.__dict__[self.translated_field.name] = val
     return val
    def handle(self, **options):
        default_lang = get_default_language()
        print "Using default language:", default_lang

        for model, trans_opts in translator._registry.items():
            print "Updating data of model '%s'" % model
            for obj in model.objects.all():
                for fieldname in trans_opts.fields:
                    def_lang_fieldname = \
                        build_localized_fieldname(fieldname, default_lang)
                    #print "setting %s from %s to %s." % \
                          #(def_lang_fieldname, fieldname,
                           #obj.__dict__[fieldname])
                    if not getattr(obj, def_lang_fieldname):
                        setattr(obj, def_lang_fieldname,
                                obj.__dict__[fieldname])
                obj.save()
    def patch_translation_field(self, db_field, field, **kwargs):
        trans_opts = translator.get_options_for_model(self.model)

        # Hide the original field by making it non-editable.
        if db_field.name in trans_opts.fields:
            db_field.editable = False

        # For every localized field copy the widget from the original field
        if db_field.name in trans_opts.localized_fieldnames_rev:
            orig_fieldname = trans_opts.localized_fieldnames_rev[db_field.name]
            orig_formfield = self.formfield_for_dbfield( \
                                self.model._meta.get_field(orig_fieldname),
                                                           **kwargs)

            # In case the original form field was required, make the default
            # translation field required instead.
            if db_field.language == get_default_language() and \
               orig_formfield.required:
                orig_formfield.required = False
                orig_formfield.blank = True
                field.required = True
                field.blank = False

            field.widget = copy(orig_formfield.widget)