0

I have below django-program--- walk.py

    from django.db import models
    from django_fsm import transition, FSMIntegerField
    from django_fsm import FSMField, transition
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    import django
    django.setup()

    from django.core.management import call_command
    class Order(models.Model):
         STATUS_GO = 0
         STATUS_COME =1
         STATUS_CHOICES = (
          (STATUS_GO, 'GO'),
          (STATUS_COME,'come')
           )
    product = models.CharField(max_length=200)
    status = FSMIntegerField(choices=STATUS_CHOICES, default=STATUS_GO, protected=True)


   @transition(field=status, source=[STATUS_GO],  target=STATUS_COME)
   def walk(self):
       print("Target moved")

Above code is available in c:\Hello folder.

I have referred few blogs & link for creating new django project.

so in cmd window, dragged to above folder by "cd c:\Hello" & executed:

 django-admin startproject mysite

And moved walk.py into mysite folder

And the directory as :

       Hello/
             mysite/
             manage.py
             walk.py
                      mysite/
                      __init__.py
                      settings.py
                      urls.py
                      wsgi.py

And Later executed:

    python manage.py migrate
    python manage.py runserver

Post which i have been stuck now & confused above two steps is required for my project.

Do

    python manage.py startapp polls

is mandate to run now ? If so, what to edit in polls/models.py file ??

Later what do i need to mention in INSTALLED_APPS = [] ???

And keep moving further, where do i place my project walk.py in above directory ?

Now when i run the walk.py , i could see below issue now:

RuntimeError: Model class main.Order doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Pls any help

2 Answers2

1

In INSTALLED_APPS you will have to add the new app like this:

INSTALLED_APPS = [
    // ...
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'polls'
]

Now Django will be aware of your app.

marcanuy
  • 23,118
  • 9
  • 64
  • 113
0

Actual error : RuntimeError: Model class main.Tag doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

my Solution:

run

   django-admin startproject mysite

in the project folder

    Hello/
         mysite/
         manage.py
         walk.py
                  mysite/
                  __init__.py
                  settings.py
                  urls.py
                  wsgi.py

Later added ' main' in INSTALLED_APPS & works fine now