Skip to content

Instantly share code, notes, and snippets.

@luanvuhlu
Created July 21, 2016 09:52
Show Gist options
  • Save luanvuhlu/0ced713c3fad2668f007fc91392d2dff to your computer and use it in GitHub Desktop.
Save luanvuhlu/0ced713c3fad2668f007fc91392d2dff to your computer and use it in GitHub Desktop.
from models import BaseModel
class BaseAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if not change:
obj.created_by = request.user
obj.last_updated_by = request.user
obj.save()
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
if isinstance(instance, BaseModel): #Check if it is the correct type of inline
if not instance.created_by_id:
instance.created_by = request.user
instance.last_updated_by = request.user
instance.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment