In my database I have a table with items who's titles can start with a letter or a non-letter-character. For example a number or an "@" or a "#". The model looks like this:
class Items(models.Model):
title = models.CharField(max_length=255)
body = models.TextField
In my view I would like to separate the model into two objects. One objects that contains all the item with a title starting with a letter and an other object with all the other items:
class ItemsView(TemplateView):
template_name = "index.html"
def get_context_data(self, **kwargs):
alpha_list = Items.objects.filter(title__startswith=<a letter>)
other_list = Items.objects.filter(title__startswith=<not a letter>)
context = {
"list_a": alpha_list,
"list_b": other_list
}
return context
I have been consulting the documents, stackoverflow and the holy google, but so far I have not been able to find a solution.
Any help is very much appreciated.