Wednesday, 2 October 2019

How to prevent “RecursionError: maximum recursion depth exceeded” when using Django Signals.

As we grow in web application development, it comes to a point when we want to be able to carry out some tasks just before saving an object to the database or right after saving an object to the database.
In Django, this can be done using a feature called Signals. According to the documentation, Signals allow certain senders to notify a set of receivers that some action has taken place and that they’re especially useful when many pieces of code may be interested in the same events.
An example of an instance when using signals can be helpful is when you are trying to create an object after saving another one. Like when you try to create a Profile object immediately after creating a User object. Following the steps in the documentation would work smoothly.
However, in a case whereby you need to make changes to an object/objects of the same model, then you could have a challenge. In our example, we have a Favorites model and a Category model. A Favorite object is an item that has a name, category and rank in numbers. A Category object is just a category a Favorite object can belong to.
class Category(models.Model):
name = models.CharField('Name', max_length=30)
description = models.TextField('Description', blank=True)

class Favourite(models.Model):
title = models.CharField('Title', max_length=20)
description = models.TextField('Description', blank=True)
rank = models.SmallIntegerField('Ranking',)
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='categories')
Above, we have the 2 models, Category and Favorites. In this little project, we want to adjust the ranks of our Favorites if there is a new Favorite with the same category and rank that already exists. For example, if we have a Favorite with name ‘Jordans’ in the ‘Shoes’ category with a rank of 1 and we want to add another Favorite with the name ‘Air Force One’ in the ‘Shoes’ category and rank of 1. We would want to update the rank of the ‘Jordans’ to 2 so that we can have the ‘Air Force One’ in rank 1. This way we would always have a unique Favorite every time.
One way to do this would be to add ‘unique-together’ as a meta property in the Favorite model and set it to rank and category. However, what this would do is to raise an error when we have a new Favorite with the same category and rank but would not make any changes. To resolve this, we can use a pre-save signal that would check the Favorite, before its saved if there already exists a Favorite with the same category and rank. If this is true, we then update the all existing Favorites with same category and rank that is equal or greater than that of the incoming Favorite to have 1 added to their rank.
def save_favorite(sender, instance, **kwargs):
   fav = instance
       favs = Favourite.objects.filter(rank__lte=fav.rank, category=fav.category)
       for f in favs:
           f.rank += 1
   except Favourite.DoesNotExist:
       passpre_save.connect(save_favorite, sender=Favourite)

But then, when you do this, you get this error:
RecursionError: maximum recursion depth exceeded while calling a Python object

This error occurs because we have modified the process of saving a Favorite object — the method will always call the save_favorite() and will result in an unending recursion which raises the above error.
To resolve this error, we will follow a different approach to saving our Favorite objects.
def save_favorite(sender, instance, **kwargs):
   fav = instance
   Favourite.objects.filter(rank__lte=fav.rank, category=fav.category).update(rank=F('rank') + 1)pre_save.connect(save_favorite, sender=Favourite)
Now, we see that we are no longer using the save() method which will result in the recursion. The update() works very well when you want to make updates to an object or objects of a model as we have done for the Favorite model.
I hope this article was helpful. Please comment below if you have any questions and I will reach out as soon as I can.

Tuesday, 17 September 2019

PyLadies Movie Night - Hidden Figures

Since my participation at the maiden PyCon Africa hosted in Ghana, Accra, I was so eager and moved to commit more of myself as a member / volunteer in the PyLadies Ghana community. The zeal, selflessness, sacrifice and ultimately hard work put in by the organizers of the community especially the PyLadies Ghana team led by Abigail Mesrenyame Dogbe inspired me to do more and stay connected. 

You can imagine my alacrity when I saw the Movie Night post on social media in collaboration with HackLab Foundation, within some few minutes I had registered for the event and was wondering how it was going to be and how I could be of help. A day to the program, I was contacted by the team whether I will be present at the meeting, this was a form of check since many people tend to register for an event but due to unforeseen circumstances could not be there on the ‘D’ day. My response to the call was affirmative and I was requested to come an hour earlier to help in the organization of the movie night.

Subsequent to the Movie post on social media, I discovered the movie to be aired had already made it to my ‘Watched List’, so it kept me wondering how different would it be to watch it again as a community. I got super excited when I saw the movie will come along with popcorn, the whole cinema feeling? Of course, I will be there. This was my first ever Tech Movie Night and I was very expectant.

Saturday finally arrived and I arrived an hour earlier at the Stanbic Incubator located in Accra. Preparations had already started as ladies and men who support our initiative trooped in. I helped to get the room ready, which was settled for use, a while ago, as the prior venue was too big and didn’t have the “cinema feels”. Shortly after our guest speaker, Stephanie Sher came by. The few people around had the chance to share some views on the Chinese investments within Africa as she wanted to know our takes on it, before her introductory session. When the room was quite filled, our guest speaker proceeded to share her journey in the tech space, this inspired us and even sparked some innovative ideas, other members were working on. I got to take something along, which still resonates in my heart, that no matter the idea or project you are working, always reach out to people with in-depth knowledge and experience. You will be surprised how quickly and better you solve it. You know what they say “A problem shared is a problem halved”.

Next on our line-up of events was the showing of Hidden Figures with some pop-corn and ice-cream to go with. Throughout the movie, I felt goosebumps all over, like it was the first time seeing it. The movie tackled a story about a trio of African-American women, who were tagged as “COMPUTERS” whilst working in NASA. They contributed tremendously to getting the first man to space. Although they all faced setbacks, they took great strides to fight the status quo within the very system that seemed to be pressing them down, pushing back with their skill, talent and determination. 

Hidden Figures serves as both entertaining and inspiring. It acknowledges from the beginning the racial divisions while insisting and portraying that “there is more than one way of killing a cat” – of fixing things. The ladies were fully aware of the racism that circled their lives but instead of resisting with violence and protests they asked for their rights with a sense of skill, grace, humility and patience. The movie depicted female empowerment which culminated in a discussion of such and the modern dose of feminism. At the end of the day the passion to be a change maker still continues. 

Big thanks to PyLadies Ghana and HackLab Foundation for putting up such an educative and interactive movie night. Another special thanks to Foster Awintiti Akugri and the SB Incubator for providing the venue. I am particularly looking forward to upcoming movie nights.

This blog was written by Yaa Nuamah Kusi-Fordjour

Tuesday, 27 August 2019

Girls Trip to Zlitch Technologies Limited

Even though it was a nice meeting, only four ladies were able to make it to Zlitch Technologies Limited. Being curious and having the intention of learning new stuff,  I was the first to arrive at Zlitch Technologies Limited, about 30 minutes to the  scheduled time on 26th of July, 2019. I must say it was my first time being  to a company with such flexibility. The atmosphere was conducive and the most surprising thing is that they were all youngsters. I expected to see workers in tie and suit but I thought wrongly. I was warmly welcomed and as I waited for the rest, I enjoyed some videos from YouTube. 

One by one the workers stopped by to say hi and chat a bit with me. In no time, the remaining three ladies showed up and we started the session.. The amazing thing is the name of the company; Zero + Glitch(error) = Zlitch technologies Ltd. No wonder the staff knew what to do at the right time... Everything went on very well right from the introduction session to the closing remarks.. 

We were warmly welcomed by the Director of Operations, Kweku Ankrah who later on took us through how the company came into being. 

The second speaker, Clifford took us through the varieties of technologies available ; artificial intelligence (using Mark Zuggerberg's house AI), machine learning, robotic processing automation, virtual reality and argumented reality, cyber security, and data science. For me, I was the happiest woman on earth because I learnt a lot. Most of the sessions were new to me but thanks to the videos attached to the presentations,  I could easily understand.

The presentations were so great because they attached videos to it and they made it interactive. In fact, this field trip is one of my best ever trip attended. The CEO gave the closing remarks with some words of encouragement. 

This blog was written by Comfort Olatunde.

Wednesday, 3 July 2019

PyLadies Night with Febisola Olanipekun

Febisola Olanipekun is a Graduate of Economics from Achievers University in Ondo State, Nigeria.
She started her career working as a payroll analyst in a startup while she was learning Data Analysis. After 2 years, she got a Data Analyst job but it was not what she wanted.
In 2018, a friend who knows how much she was fascinated about ‘hacking’ told her about She Secures bootcamp which she attended. And there, her journey began. At the moment, she works as a Security Operation Center (SOC) Analyst in a Cyber Security firm in Lagos, Nigeria.

We've heard quite a number of things about you, but can you please describe yourself to the house in 3 words?
Haha!  This question had me doing self-survey...I will say curious, resourceful and adventurous.

Okay, I’m particular about one word you chose, “adventurous”, why?
I know some describe me as polymathic, but nah …lol. Being adventurous got me into Cyber Security! But aside that, I love to travel explore, climb rocks, learn new things and do things differently

Interesting, but are you trying to say that if someone is not adventurous, they can’t venture into cyber security?
I have met many who think it is daring to have studied Economics and end up in Cyber Security. for me, it is fun!

Why did you leave your Economics background to pursue Cybersecurity?
First, I wanted to do investment banking. I could use Microsoft excel very well and build basic models but I hated accounting. I was not interested in all the cash flow and other jargons. Secondly, I wanted to do Economic Research. I think it is one of the hardest fields to get in as an entry -level job seeker. So, I had always been a lover of tech from my undergraduate days and I told anyone around me who cares to listen. I had a friend list out the path in tech and guess which fascinated me the most? Hacking

So, when did the urge for hacking start? Was it in the university?
I used to assist the guy that fixes things at the ICT department of my university. Getting things to work by passing the screws and holding things for him. He said I could be in a position to help people "secure" and "break" into things on the internet. I was really marveled. Actually, the discussion died down. Months later, he sent me a link to attend a boot camp organized by She Secures.

So Febi, will you say that this guy was, or is your mentor, because it’s clear he laid down the path for you to follow, and here you are. Or did you have another mentor(s) in tech?
So, being a friend is different from being a mentor, right? but both can happen.
He is a programmer. At the bootcamp, I met new people and I ensured to retain and maintain the network of people. Someone said I was very tenacious and picked interest in me to mentor me. I have him as a mentor and 2 other people as accountability partner.

That’s great opportunity for you in there. Would you like to be a mentor to anyone interested?
It is, really
I will be happy to. One person for starters.

What is your portfolio at your current workplace, how is the experience in there like, are there ladies too or it’s a man’s world?
I work as a SOC (Security Operation Center) Analyst and it has been an interesting experience so far. There is so much to learn.  I have 4 amazing female colleagues but it is a ratio of 1:10. One amazing thing in the field that I have observed is that arms are wide open from the male folks to teach and help you grow.

That’s encouraging. Febisola do you have any words of motivation for the young cyber security enthusiasts?
I used to bring myself down in my thoughts that I am old (I clocked 27 this year and I got in here at 26) ….my former team lead was 24 and I had to play a lot of emotional intelligence (EL).
Do not tear yourself down. If you don’t know it, you are not dumb. Google will never laugh at you, I promise. Ask questions, good questions. Research, be confident. Your soft skills outside of cyber security matter a lot, you will find them handy sometimes. e.g. I shine in preparing reports because of data analysis skills
You can get overwhelmed, learn in bits. Work with timeline for yourself


What should I learn for cybersecurity?
GitHub link where different people shared about getting into cyber security (
I also took a course on Edx after the bootcamp. It really helped me when I had conversations during interviews.(

How can one enter the cybersecurity field with no experience?
Read!  update your CV, self-improvement / personal development. The reality is that there are so many free resources out there. Don’t let the ones that you can’t afford slow you down. You will get them later.

The way hacking and security is portrayed in our movies and society it looks like it’s for some kind of geeks and smart people. Is that the case or it’s just a stereotype?
Far from what you see in movies, they did not bring the skills from mama’s womb. It was all learnt. So, all you need to do is learn … dazzal!!

Big thank you on behalf of PyLadies Ghana, for honoring our invitation and sharing with us your experiences. We have learnt a lot and are equally motivated as well!

Thursday, 20 June 2019

PyLadies Night with Isaac Sesi

Isaac Sesi is an entrepreneur, software developer and embedded systems engineer. He is the co-founder of Sesi Technologies, an AgriTech company which develops hardware and software solutions for farmers and agribusinesses in Africa. He has also co-founded 2 other startups in the past; Invent Electronics and GravyCode.

Isaac Sessi

He has a degree in Electrical and Electronics Engineering from the Kwame Nkrumah University of Science and Technology (KNUST). Isaac is a Tony Elumelu Fellow a Next Einstein Forum finalist and a World Summit Awards National Winner. He was recently selected as one of the 50 most influential young Ghanaians for 2018.

His passion for STEM led him to cofound Nsesa Foundation, a non-profit whose vision is to inspire an Innovation revolution in Africa and get young Africans solving problems using science and technology. Nsesa Foundation's programs have trained hundreds of high school students and have reached over 300,000 people across the world since 2013.

Isaac has had the opportunity to showcase his work to several heads of states including the president and vice president of Ghana, the Chancellor of Germany, Angela Merkel and Prince Charles of Wales. In his free time, Isaac writes on entrepreneurship on his blog,, hosts The African Entrepreneur Podcast and plays the piano.

From your bio, you have a lot of outstanding achievements. Will you add anymore descriptions?
Err...well outstanding achievements may be a bit overkill. But hey, we are doing our best and trying to make impact. Whatever recognition that comes along the way is only validation of the good work you are doing. So i prefer to focus on the work rather than the fanfare.

When did you decide to go into tech? Was it in Senior High School (SHS), or Junior High School (JHS)? Do you have a sibling in that area of expertise?
Well i have been in tech all my life.   I started destroying radios and stuff very early I built battery powered boats in JHS. I built dishwashers, robots, cloth drying machines, communication systems etc in SHS.
I built apps and websites , and did more  complex embedded systems engineering stuff. After University, I started translating all of these tech and engineering i have been doing into products and devices and making them commercially available to have real impact in the lives of the underprivileged. So yes, I have been in tech for a long time.

Did you use Robots with Arduino NXT/EV3? (P.S : NXT and EV3 are robotics kits used to also teach robotics mostly in JHS and SHS in Ghana)
Well it depends on you. NXT/EV3 is more structured. Easy to follow. Arduino is more freestyle. So it depends on the individual and how they are learning or being taught. Each has their own advantage or disadvantage. Personally i prefer arduino because it allows for more creativity. I wouldnt put one above the other

Your company, Invent Electronics imports hardware components that constitute IoT kits? How and Why did you come up with that?
It was simple. I was in University doing electrical engineering.We needed to do projects and finding components for it was difficult. So i decided to fix that. Invent electronics was born.

I keep seeing a product of Sesi Tech, called Grainmate. What was the inspiration for this?
So GrainMate is a flagship product of my startup, Sesi Technologies. It is an affordable grain moisture which makes it easy for farmers to accurately monitor the moisture content in their grains before storage to help prevent post harvest losses.

What setbacks did you encounter on your journey? Few examples? Was funding a big problem?
Funding: Unlike software where all you need to develop an MVP is a laptop and internet, .developing hardware is expensive. You need money to develop a prototype.

You need equipment to refine your prototype. All of these cost money. You need a larger skill set to successfully develop a hardware prototype. You need a maker (the engineer who designs and prototypes the product.) then you need the software guy who will develop supporting mobile applications.  These do not come cheap. So you need to have the cash to prototype

Technical Know-how: Developing hardware requires a lot of specialized skills. Unfortunately, it is difficult to find people with -that skill set in Africa. Either they are already working somewhere or they are so expensive that you cannot afford them initially if you don’t have funding.

Scaling to mass manufacturing: It is very difficult to scale to mass manufacturing in Africa. Setting up manufacturing processes, getting the right equipment, finding casing/enclosure for your products, etc are some of the challenges you will face when trying to scale your manufacturing

Any links, GitHub account or resources that you’ve used that aids in acquiring some of the skills you have?
well, i learn a lot. I take a bunch of online courses all the time. Almost every point in time, i am taking at least one or two online courses. And my go to places for online courses are and I look at where i am going, my career objectives and then i list the skills i need to thrive in those places. The ones i do not have, i go and acquire...

Currently my company is running a number of projects so i am taking a course in Project management. Education has been democratized, thanks to the internet. you don't need to pay so much to learn anything anymore, just grab your laptop, and anything you want to learn, you can find.
I love to read too. Because i am running a company, i love reading a lot about startups, growing your business, fundraising, etc. I have a cache of hundreds of digital books that I read regularly.
Also, I invest a lot in buying books on amazon kindle and audible in areas that are of importance to me. I love LinkedIn too, it helps me connect with people i believe can catalyze my development in other areas.
So hey, whatever resources you need are out there, just google.

Lastly, do you have any contact info or email that anyone can reach you on for project advice , idea contribution, internship ,etc at Sesi Tech?
If it is a personal email unrelated to my work that you want to send, please send it to Also i blog at where i write about entrepreneurship, personal development and productivity.

This session was moderated by Abigail Afi Gbadago the current Robotics Lead for PyLadies Ghana.