class RoomAdmin(admin.ModelAdmin):
list_display = ('name', 'created', 'last_activity_formatted', 'description', 'description_modified')
+ readonly_fields = ('created', 'description_modified', 'content_type', 'object_id')
+ # As we've set some fields to be read-only, they will automatically appear at the end
+ # of the list. Manually order the fields to be as they are defined in the model.
+ fieldsets = (
+ (None, {
+ 'fields': ('name', 'created', 'description', 'description_modified',
+ 'content_type', 'object_id')
+ }),
+ )
# When changing a description, we need to know the request.user as an attribute
# of the room instance. This snippet below adds it.
--- /dev/null
+{% extends "admin/change_form.html" %}
+{% load i18n admin_modify adminmedia %}
+
+{% block extrastyle %}
+ {{ block.super }}
+ <style type="text/css">
+ #chat-room-messages div {
+ margin-left: 10em;
+ }
+ </style>
+{% endblock %}
+
+{% block after_field_sets %}
+<fieldset class="module aligned">
+ <div class="form-row">
+ <label>Last activity:</label> {{ original.last_activity_datetime }}
+ </div>
+ <div class="form-row" id="chat-room-messages">
+ <label>Messages:</label>
+ <div>
+ {% for m in original.message_set.all %}
+ {{ m.created|time:"H:i:s" }} {{ m.text|safe }}
+ {% endfor %}
+ </div>
+ </div>
+</fieldset>
+{% endblock %}
+