Usage
Creating a model
Subclass authorship.models.Authorship
to create the necessary fields:
class MyModel(Authorship):
pass
Integrating with django.contrib.admin
You can automatically update authorship information when a model is altered in the Django admin interface by using authorship.admin.AuthorshipMixin
:
class MyAdmin(AuthorshipMixin, admin.ModelAdmin):
pass
Hint
This also applies to child inlines if they refer to subclasses of authorship.models.Authorship
.
Integrating with class-based views and ModelForm
s
Use authorship.views.AuthorshipMixin
on your django.views.generic.edit.ModelFormMixin
-based views (django.views.generic.edit.CreateView
, django.views.generic.edit.UpdateView
.etc):
class MyModelCreateView(AuthorshipMixin, CreateView):
form_class = MyModelForm
Then, use authorship.forms.AuthorshipMixin
on your django.forms.ModelForm
-based forms:
class MyModelForm(AuthorshipMixin, ModelForm):
class Meta(object):
model = MyModel
Together, these mixins will—upon a successful form submission—appropriately record request.user
on the target object.
Warning
You must use authorship.views.AuthorshipMixin
on the view and authorship.forms.AuthorshipMixin
on the form for this to work.
Integrating with Django REST Framework
Use authorship.api.views.AuthorshipMixin
on your CreateModelMixin
/ UpdateModelMixin
-based API views.