Home > Software design >  Import models function
Import models function

Time:11-23

I created a models within my page but when I attempted to run the page I received an error response

celery_beat_1    |     class ClassManager(models.Manager):
celery_beat_1    | NameError: name 'models' is not defined

I searched for fixes to this error online and most of the responses said to implement the

import from django.db import models

function. However, this is something I already have configured in my models page. Any idea on how to proceed forward?

CodePudding user response:

You should import models from django in models.py.

from django.db import models

class MyModel(models.Model):
    pass

You can check more information in django documentation itself: https://docs.djangoproject.com/en/3.2/topics/db/models/#quick-example

CodePudding user response:

You are importing the models in wrong way format, so you have to use -

from django.db import models

rather than using

import from django.db import models
  • Related