python - django and executing a separate .py to manipute a database -


I want to execute a random .py file, foo.py for myproject / myapp folder using the crawlbox for some time Say

My model for the app is the original model in py.

  class Mymodel (models.Model): content = models.TextField ()  I have to say whether this is in my foos, I want to see if any is a Mymodel object in which the content is similar to the meteite in the form of field, if any new mammals Do not make with Maytekst as AOL Content, then before you do nothing existed. 

  & lt; Do dangoango import & gt; Mytext = "Here are some" if MyModel.filter (content = mytext) == faucet: newitem = Mymodel (content = mytext) newitem.save () Other: pass  

So here's my Question, what am I doing to import the demo? Besides how can I check that there is no item in the query (I do not know if MyModel.filter (content = mytext) == faucet will work. I do not even know that this is an effective way of achieving my goal.

Thanks

You have two separate questions - dividing them Would be better for you.

To run a different script, you are doing the best to create the ./ management.py command.

For the second question, the code you provided is not a valid Python, because there is no 'zero' value - you do not mean any . Still the code will not work, because it does not You write that query using the Django ORM. You want something like this:

  If not MyModel.objects.filter (content = mytext) .count ():  

that asks the database how many items are with content = mytext, and if none, then it is true.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -