First time here? Check out the FAQ!
1

Wing scripts in a django project

I want to write a script to help me do some automation jobs in a django project. There is a model named "Post", I can use the code below to get all the fields:

from . import models

print(models.Post._meta.fields)

How can I use the code in a wing script? I wish I can access the django repl to get the data and use them back in the script. For example:

s = make_useful_string(models.Post._meta.fields)

insert_text(s)

bai's avatar
73
bai
asked 2022-01-08 19:43:40 -0500, updated 2022-01-08 19:44:24 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

Another possibly cleaner way is to write your script as a stand-alone tool that can be run on the command line and outputs the results you need. Then use the AsyncExecute* or ExecuteCommandLine methods on the CAPIApplication in the scripting API to call it and read its output. That way you don't have to match Python version, etc.

Wingware Support's avatar
4.1k
Wingware Support
answered 2022-01-10 14:59:28 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

You may be able to import models by adding directories to sys.path (probably the parent directory of the package models is in and the paths that Django needs) and then importing the module. The code would need work with the version of Python that Wing uses internally (Python 3.9 in Wing 8) and you'd need to restart Wing when your code changes.

Wingware Support's avatar
4.1k
Wingware Support
answered 2022-01-10 09:45:38 -0500
edit flag offensive 0 remove flag delete link

Comments

Thank you for the idea!

bai's avatar bai (2022-01-10 18:40:05 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer