Re-examine the Data Programmatically:

  • Use the command python manage.py shell to explore the data in the project database.
1python manage.py shell
2>>> from code_journals.models import Topic
3>>> Topic.objects.all()
4<QuerySet [<Topic: Data_Types>, <Topic: Lists>, <Topic: Dictionaries>]>
  • In the second line, we import the model Topic from the code_journals.models module.
  • The method Topic.objects.all() is then used to get all the instances of the model Topic
  • The updated QuerySet list is returned showing the additional topic, Dictionaries

Delete a Topic from the QuerySet:

  • We can delete a specific Topic from the queryset using the delete() method.
  • Example: To delete the Dictionaries topic, we can refer to it’s ID value, which in this case is three (3):
1>>> topic = Topic.objects.get(id=3)
2>>> topic.delete()                 
3(2, {'code_journals.Entry': 1, 'code_journals.Topic': 1})
  • Re-running Topic.objects.all() would then display the updated QuerySet with just the two Topics: Data_Types and Lists as shown below:
1>>> Topic.objects.all()
2<QuerySet [<Topic: Data_Types>, <Topic: Lists>]>