I've got a small app with DefaultRouter used to handle basic operations at certain models.
The problem is, that I need to override the create and update method for standard DefaultRouter, to handle problem without using Django Admin.
Models, etc. are nothing special, but important thing is that I want to override method for all models using specific abstract model as a parent. If I've created save() and update() methods in model, DefaultRouter crashes.
from django.db import models
"""
Class contains common fields for all models
"""
class AbstractOurModel(models.Model):
add_user = models.ForeignKey(
'User',
models.PROTECT,
blank=False,
null=False,
related_name='%(class)s_add_user'
)
add_date = models.DateTimeField(auto_now_add=True)
mod_user = models.ForeignKey(
'User',
models.PROTECT,
blank=False,
null=False,
related_name='%(class)s_mod_user'
)
mod_date = models.DateTimeField(auto_now=True)
def save(request):
self.add_user = request.user
self.mod_user = request.user
def update(request):
self.mod_user = request.user
class Meta:
abstract = True
Thanks for help!