Checklist Extension template model
Review Request #6078 — Created July 8, 2014 and discarded — Latest diff uploaded
Created a new model to hold templates for the checklist extension. The model contains a name for the list, and a collection of template items. Items can be added, edited and removed from the model.
I followed the same schema as ReviewChecklist model.
Diff Revision 2
This is not the most recent revision of the diff. The latest diff is revision 4. See what's changed.
orig
1
2
3
4
checklist/checklist/models.py | |||
---|---|---|---|
Revision 866f55d5108082fc17fb8f57f098170c61c02a24 | New Change | ||
44 lines | |||
def toggle_item_status(self, itemID):
|
|||
45 | 45 | ||
46 |
def delete_item(self, itemID): |
46 |
def delete_item(self, itemID): |
47 |
if (str(itemID) in self.checklist_items): |
47 |
if (str(itemID) in self.checklist_items): |
48 |
self.checklist_items.pop(str(itemID)) |
48 |
self.checklist_items.pop(str(itemID)) |
49 |
self.save() |
49 |
self.save() |
50 | |||
1 | 51 |
class ChecklistTemplateList(models.Model): |
|
1 | 52 |
"""A ChecklistTemplateList is a list of templates items created by user. """ |
|
53 | |||
54 |
# The user making the review.
|
||
55 |
user = models.ForeignKey(User) |
||
56 | |||
57 |
# The title of the template list.
|
||
58 |
title = models.CharField(max_length=30) |
||
59 | |||
60 |
# Keeps track of the number of items in the template
|
||
61 |
# list, not the current number of items in it. This
|
||
62 |
# allows us to give unique IDs to new items.
|
||
63 |
items_counter = models.IntegerField(default=0) |
||
64 | |||
65 |
# A JSON of all the items in the list.
|
||
66 |
# Value = { id, description }
|
||
67 |
temp_items = JSONField() |
||
68 | |||
69 |
def add_item(self, item_description): |
||
70 |
self.items_counter += 1 |
||
71 |
self.temp_items[self.items_counter] = { |
||
72 |
'id': self.items_counter, |
||
73 |
'description': item_description |
||
74 |
}
|
||
75 |
self.save() |
||
76 | |||
77 |
def edit_item_desc(self, itemID, item_description): |
||
78 |
if (str(itemID) in self.temp_items): |
||
79 |
itemDict = self.temp_items.get(str(itemID)) |
||
80 |
itemDict['description'] = item_description |
||
81 |
self.save() |
||
82 | |||
83 |
def delete_item(self, itemID): |
||
84 |
if (str(itemID) in self.temp_items): |
||
85 |
self.temp_items.pop(str(itemID)) |
||
86 |
self.save() |