This class tracks changes in Django Admin. When a save action is performed, it stores the value of the old object using the Memento model.
Example of code for a model in **admin.py** for a custom 'app':
from app.memento.models import Memento
def save_model(self, request, obj, form, change):
obj.save()
data = serializers.serialize("json", [obj, ])
m = Memento(app="Unidade",model=modelName,data=data, user=request.user)
m.save()
class UnidadeAdmin(admin.ModelAdmin):
pass
UnidadeAdmin.save_model = save_model
This stores the former values of 'Unidade' model on 'Memento' model data.
Not tested on previous versions of Django, but could work on them too.
- admin
- register
- changes
- persistence
- tracking
Just extends your models from this One... is abstract so, it will not generate a table.
Now, in your urls.py do this:
from django.conf.urls.defaults import *
from animals.models import Dog, Cat, Bird
urlpatterns = patterns('animals.views',
url(r'^$', 'index', {},Dog._meta.app_label),
)
dog=Dog()
cat=Cat()
bird=Bird()
urlpatterns+=dog.build_generic_CRUD_urls(Dog)
urlpatterns+=cat.build_generic_CRUD_urls(Cat)
urlpatterns+=bird.build_generic_CRUD_urls(Bird)
then you can create the templates, and get the urls like this:
{{ object.get_absolute_url }} View
{{ object.get_update_url }} Edit
{{ object.get_delete_url }} Delete
{{ dummy_object.get_create_url }} Create
dummy_object is a quick and dirty solution until I find some better...
With all these you can create 54 functional and low detail CRUDS in one hour. :D
Enjoy!