Hello, I want to execute a random .py file, say foo.py on the myproject/myapp folder by using crobjob by some periods
I have this basic model in my model.py for the app:
class Mymodel(models.Model):
content = models.TextField()
Say I have this in my foo.py, I want to check if there is any Mymodel object that has a content field as same as mytext, if not make a new Mymodel with the mytext as content, if already existing do nothing.
<do django importings>
mytext = "something here"
if Mymodel.filter(content=mytext) == null:
newitem = Mymodel(content=mytext)
newitem.save()
else:
pass
So here is my question, what django imports shall I be doing? Also how can I check if the query has no item (don't know if if Mymodel.filter(content=mytext) == null would work. Also I don't know if this is an efficient way to achieve my goal as the amount of Mymodel will be high.
Thanks