Not_Linked_In

Work flow of adding and updating content

Adding new content:

Using Django shell, create a new Content table object, then assign basic meta data to the object.
Recall that tags and content attributes are serialized using JSON, in form of [<row type tag>, <row content>]. Prepare the content in a text editor first, then copy/paste to the object attribute.

Updating existing content:

Content is stored using JSON. First use JSON loads method to convert the JSON string into a Python object, and access the particular list element using index and slicing.

Using consistent naming of objects and variables will make this more manageable, particularly because IPython will remember previous entries. But that is all for naught if the variable names are meaningless.

Example: Using c6 as arbitrary reference to id=6. Added helper functions (Jan 2023) to assist in content creation and updating.

Code Block Code Desc
from _helpers import *
print_pretty_content(<id>) Returns pretty version of content by id
import json
objs = get_objs()
c6 = objs[6]
c6_json = c6.content
c6_cont = json.load(c6_json) Identify the element in the nested lists to update
Use append(), insert(), replace() or slicing to upate
c6_json = json.dumps(c6_cont)
c6.content = c6_json
c6.save

Older workflow: For reference only, remove in future.

Code Block Code Desc
import json
c6 = Content.objects.get(id=6)
c6_cont_list = json.loads(c6.content)
c6_cont_list[n][n] = 'something different'
c6_cont_json = json.dumps(c6_cont_list)
c6.content = c6_cont_json
c6.save()

Note that inside the Django template, using pipe safe ('|safe') so that html tags render correctly. Because of this we must escape certain characters:
(Ironically the escapes render when I write them, so using underscores to prevent this - do not include them.)

& = &_amp;
< = &_lt;
> = &_gt;
double quotes = &_quot;
single quote = &_#39;