Created
June 8, 2015 12:31
-
-
Save acuros/4d16d87405c5580bda05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AutoBrAdmin(admin.ModelAdmin): | |
br_attrs = tuple() | |
def get_object(self, request, object_id): | |
obj = super(AutoBrAdmin, self).get_object(request, object_id) | |
for attr in self.br_attrs: | |
value = getattr(obj, attr) | |
setattr(obj, attr, value.replace('\r\n', '').replace('<br>', '\r\n')) | |
return obj | |
def save_model(self, request, obj, form, change): | |
for attr in self.br_attrs: | |
value = getattr(obj, attr) | |
setattr(obj, attr, value.replace('\r\n', '<br>')) | |
super(AutoBrAdmin, self).save_model(request, obj, form, change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment