mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Added contrib.admin.models.admin, which contains LogEntry (from models.auth). It still exists in models.auth, temporarily
git-svn-id: http://code.djangoproject.com/svn/django/trunk@945 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
30d7e62828
commit
0dc843b3c6
1
django/contrib/admin/models/__init__.py
Normal file
1
django/contrib/admin/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__all__ = ['admin']
|
48
django/contrib/admin/models/admin.py
Normal file
48
django/contrib/admin/models/admin.py
Normal file
@ -0,0 +1,48 @@
|
||||
from django.core import meta
|
||||
from django.models import auth, core
|
||||
|
||||
class LogEntry(meta.Model):
|
||||
action_time = meta.DateTimeField(auto_now=True)
|
||||
user = meta.ForeignKey(auth.User)
|
||||
content_type = meta.ForeignKey(core.ContentType, blank=True, null=True)
|
||||
object_id = meta.TextField(blank=True, null=True)
|
||||
object_repr = meta.CharField(maxlength=200)
|
||||
action_flag = meta.PositiveSmallIntegerField()
|
||||
change_message = meta.TextField(blank=True)
|
||||
class META:
|
||||
module_name = 'log'
|
||||
verbose_name_plural = 'log entries'
|
||||
db_table = 'django_admin_log'
|
||||
ordering = ('-action_time',)
|
||||
module_constants = {
|
||||
'ADDITION': 1,
|
||||
'CHANGE': 2,
|
||||
'DELETION': 3,
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.action_time)
|
||||
|
||||
def is_addition(self):
|
||||
return self.action_flag == ADDITION
|
||||
|
||||
def is_change(self):
|
||||
return self.action_flag == CHANGE
|
||||
|
||||
def is_deletion(self):
|
||||
return self.action_flag == DELETION
|
||||
|
||||
def get_edited_object(self):
|
||||
"Returns the edited object represented by this log entry"
|
||||
return self.get_content_type().get_object_for_this_type(pk=self.object_id)
|
||||
|
||||
def get_admin_url(self):
|
||||
"""
|
||||
Returns the admin URL to edit the object represented by this log entry.
|
||||
This is relative to the Django admin index page.
|
||||
"""
|
||||
return "%s/%s/%s/" % (self.get_content_type().package, self.get_content_type().python_module_name, self.object_id)
|
||||
|
||||
def _module_log_action(user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):
|
||||
e = LogEntry(None, None, user_id, content_type_id, object_id, object_repr[:200], action_flag, change_message)
|
||||
e.save()
|
Loading…
Reference in New Issue
Block a user