Under the existing system, a log audit needs to be added.
Existing environment: Django Mongodb.
Then I want to use logging directly to process logs, but how to store them in the database?
I saw some people discussing signals processing on the Internet. I am not very familiar with this block. I would like to ask if it is okay to only process views, because the existing environment does not have the processing of models. Thanks
黄舟2017-05-18 11:01:11
If you want to record changes in models, it is recommended to use django-reversion.
Update:
You can redirect the user to the view you use to record the user's login time, IP, and username after logging in. Then redirect to another view.
from ipware.ip import get_ip
import datetime
class UserLoginLogView(View, LoginRequiredMixin):
def get(self, request, pk):
ip = get_ip(request)
user = self.request.user
time = datetime.datetime.now()
url = reverse(home)
login_log = UserLoginLogModel.objects.create(user=user, ip=ip, time=time)
return HttpResponseRedirect(url)