Is it possible to get django info without running it

I have a django model, the whole code is completed. but I want to access my model info. a code like this to get field names.

for f in myModel._meta.fields:

is it possible to do it from an external python script without running django server?

other possible automated ways of doing this and saving results to a file are also appreciated.

thanks to @klaus D and management command documentation I made this structure


and in I did

from import BaseCommand, CommandError
from users import views2
def savelisttxtfile(the_list, path_, type_='w', encoding="utf-8"):
    with open(path_, type_, encoding=encoding) as file_handler:
        for item in the_list:
class Command(BaseCommand):
    def handle(self, *args, **options):
        for f in views2.ChertModel._meta.fields:

and to run it I went to location and executed python modelInfo to launch it.

Regarding your "try1" it seems to be a little bit trickier to start a python shell like python shell than what you propose there.

Fortunately you can do this:

python shell <

and your script will be executed as if typed directly into the "django shell". Keep in mind that you still need to import your models relative to your project, i.e. from myapp.models import mymodel.

Back to Top