I have a problem inserting NULL in Django. I mean i don't know how to do this.
I have function, lets call it find_position, then i have field in model like position (IntegerField, null=True, blank=True). This function inspect some html code, and if it match with some regex, it returns integer, but if it doesn't find - have to return NULL or None or something that I can put in database.
 def find_position(self, to_find, something): 
   ...
       if re.search(to_find, something): 
           return i + (page * 10) + 1 
    return NULL # or what i have to return here?
And i have this:
_position = find_position(to_find, something)
p = Result(position=_position, ...)
r.save()
Previously i user CharField for position, and returned '-' if not find the result. But i had problems counting total results, like position__lte=10 (because it's not integer and it messed up with numbers and strings -. 
What can I do with this?
Make the function return None (or not returning anything, it's the same as returning None), in database it will be saved Null:
 def find_position(self, to_find, something): 
   ...
       if re.search(to_find, something): 
           return i + (page * 10) + 1 
    return None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With