1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
STATUS_CODES = (
(1, 'Open'),
(2, 'Working'),
(3, 'Closed'),
)
PRIORITY_CODES = (
(1, 'Now'),
(2, 'Soon'),
(3, 'Someday'),
)
apps = [app for app in settings.INSTALLED_APPS if not app.startswith('django.')]
class Ticket(models.Model):
"""Trouble tickets"""
title = models.CharField(maxlength=100)
project = models.CharField(blank=True, maxlength=100, choices= list(enumerate(apps)))
submitted_date = models.DateField(auto_now_add=True)
modified_date = models.DateField(auto_now=True)
submitter = models.ForeignKey(User, related_name="submitter")
assigned_to = models.ForeignKey(User)
description = models.TextField(blank=True)
status = models.IntegerField(default=1, choices=STATUS_CODES)
priority = models.IntegerField(default=1, choices=PRIORITY_CODES)
class Admin:
list_display = ('title', 'status', 'priority', 'submitter',
'submitted_date', 'modified_date')
list_filter = ('priority', 'status', 'submitted_date')
search_fields = ('title', 'description',)
class Meta:
ordering = ('status', 'priority', 'submitted_date', 'title')
def __str__(self):
return self.title
|
Comments
bug: two submitted_date in list_display.
#
Thanks -- fixed!
I added a couple refinements that I've been using too.
#
Instead of
from YOURPROJECT import settingsyou should usefrom django.conf import settings#
Good catch, fixed.
#
Could probably do with updating this to the v1.0 admin stuff. If I get a moment, I'll post up some code.
#