models.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.db import models
  2. from django.utils.translation import gettext_lazy as _
  3. class AccessBase(models.Model):
  4. user_agent = models.CharField(_("User Agent"), max_length=255, db_index=True)
  5. ip_address = models.GenericIPAddressField(_("IP Address"), null=True, db_index=True)
  6. username = models.CharField(_("Username"), max_length=255, null=True, db_index=True)
  7. http_accept = models.CharField(_("HTTP Accept"), max_length=1025)
  8. path_info = models.CharField(_("Path"), max_length=255)
  9. attempt_time = models.DateTimeField(_("Attempt Time"), auto_now_add=True)
  10. class Meta:
  11. app_label = "axes"
  12. abstract = True
  13. ordering = ["-attempt_time"]
  14. class AccessAttempt(AccessBase):
  15. get_data = models.TextField(_("GET Data"))
  16. post_data = models.TextField(_("POST Data"))
  17. failures_since_start = models.PositiveIntegerField(_("Failed Logins"))
  18. def __str__(self):
  19. return f"Attempted Access: {self.attempt_time}"
  20. class Meta:
  21. verbose_name = _("access attempt")
  22. verbose_name_plural = _("access attempts")
  23. class AccessLog(AccessBase):
  24. logout_time = models.DateTimeField(_("Logout Time"), null=True, blank=True)
  25. def __str__(self):
  26. return f"Access Log for {self.username} @ {self.attempt_time}"
  27. class Meta:
  28. verbose_name = _("access log")
  29. verbose_name_plural = _("access logs")