Skip to content

Tag: python

Django NotEqual custom lookup on related field

I registered a custom lookup base on this answer and official documentation. I registered the custom lookup in my app config. Then i use it in the exclude method this way. The idea here is to get all the customers where user is info.context.user (with private is False or True) OR user is NOT info.context.user…

How to remove white space in between ascii and nonascii chars?

For example: I want to find at least 3 ascii chars, followed by a space, then followed by a nonascii char, and replace the white space with empty string. My code has two issues: How to write the replacement string for (s)? How to make it also work for the reverse order of s2?: [^a-zA-Z0-9] Answer Put the stri…

Shorter way to make colliderect in if statement work?

I have two objects: And I want to make an if statement if they collide with a third object. This code actually works but is too long: And there’s an error when I try to write: So, what is wrong? Is there a shorter way to write it? Answer The first thing you can do is use shorter variable names,

Merge Dataframe rows based on the date

I have a dataframe that looks like this, It has the name of the company, the date and the title of a headline that was published regarding that company on that day. There are multiple headlines published on that single day and every single one of those headlines take up a different row even for the same date.…