# Path: audit/models.py
# class PageviewRecord(models.Model):
# 
#     HTTP_METHODS = ['GET', 'POST', 'HEAD', 'PUT', 'PATCH', 'DELETE',
#                     'CONNECT', 'OPTIONS', 'TRACE']
# 
#     user = models.ForeignKey(User, blank=True, null=True)
#     user_ip = models.GenericIPAddressField()
#     role = models.ForeignKey(core_models.ProviderType,
#                              blank=True, null=True)
# 
#     method = models.CharField(
#         max_length=max(len(v) for v in HTTP_METHODS),
#         choices=[(v, v) for v in HTTP_METHODS])
# 
#     url = models.URLField(max_length=256)
#     referrer = models.URLField(max_length=256, blank=True, null=True)
# 
#     status_code = models.PositiveSmallIntegerField()
# 
#     timestamp = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return '%s by %s to %s at %s' % (self.method, self.user, self.url,
#                                          self.timestamp)


from django.contrib import admin
from .models import PageviewRecord
        'timestamp',
    )

    search_fields = (
        'user__username', 'user__first_name', 'user__last_name', 'user__email',
        'url', 'role__short_name'
    )

    # change_list_template = 'admin/pageview-log-summary.html'
    # date_hierarchy = 'timestamp'

    # We cannot call super().get_fields(request, obj) because that method calls
    # get_readonly_fields(request, obj), causing infinite recursion. Ditto for
    # super().get_form(request, obj). So we  assume the default ModelForm.
    def get_readonly_fields(self, request, obj=None):
        return self.fields or [f.name for f in self.model._meta.fields]

    def has_add_permission(self, request):
        return False

    # Allow viewing objects but not actually changing them.
    def has_change_permission(self, request, obj=None):
        return (request.method in ['GET', 'HEAD'] and
                super(admin.ModelAdmin, self).has_change_permission(
                    request, obj))

    def has_delete_permission(self, request, obj=None):
        return False



# Path: audit/models.py
# class PageviewRecord(models.Model):
# 
#     HTTP_METHODS = ['GET', 'POST', 'HEAD', 'PUT', 'PATCH', 'DELETE',
#                     'CONNECT', 'OPTIONS', 'TRACE']
# 
#     user = models.ForeignKey(User, blank=True, null=True)
#     user_ip = models.GenericIPAddressField()
#     role = models.ForeignKey(core_models.ProviderType,
#                              blank=True, null=True)
# 
#     method = models.CharField(
#         max_length=max(len(v) for v in HTTP_METHODS),
#         choices=[(v, v) for v in HTTP_METHODS])
# 
#     url = models.URLField(max_length=256)
#     referrer = models.URLField(max_length=256, blank=True, null=True)
# 
#     status_code = models.PositiveSmallIntegerField()
# 
#     timestamp = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return '%s by %s to %s at %s' % (self.method, self.user, self.url,
#                                          self.timestamp)


# Path: audit/admin.py
from django.contrib import admin
from .models import PageviewRecord

        'timestamp',
    )

    search_fields = (
        'user__username', 'user__first_name', 'user__last_name', 'user__email',
        'url', 'role__short_name'
    )

    # change_list_template = 'admin/pageview-log-summary.html'
    # date_hierarchy = 'timestamp'

    # We cannot call super().get_fields(request, obj) because that method calls
    # get_readonly_fields(request, obj), causing infinite recursion. Ditto for
    # super().get_form(request, obj). So we  assume the default ModelForm.
    def get_readonly_fields(self, request, obj=None):
        return self.fields or [f.name for f in self.model._meta.fields]

    def has_add_permission(self, request):
        return False

    # Allow viewing objects but not actually changing them.
    def has_change_permission(self, request, obj=None):
        return (request.method in ['GET', 'HEAD'] and
                super(admin.ModelAdmin, self).has_change_permission(
                    request, obj))

    def has_delete_permission(self, request, obj=None):
        return False



admin.site.register(PageviewRecord, PageviewRecordAdmin)