Models
In [1]:
Copied!
from django.db import models
from django.db import models
In [2]:
Copied!
class Aluno(models.Model):
nome = models.CharField(max_length=100)
matricula = models.CharField(max_length=10, unique=True)
idade = models.PositiveIntegerField()
curso = models.CharField(max_length=100)
data_matricula = models.DateField()
def __str__(self):
return f"{self.nome}"
class Aluno(models.Model):
nome = models.CharField(max_length=100)
matricula = models.CharField(max_length=10, unique=True)
idade = models.PositiveIntegerField()
curso = models.CharField(max_length=100)
data_matricula = models.DateField()
def __str__(self):
return f"{self.nome}"
--------------------------------------------------------------------------- ImproperlyConfigured Traceback (most recent call last) Cell In[2], line 1 ----> 1 class Aluno(models.Model): 2 nome = models.CharField(max_length=100) 3 matricula = models.CharField(max_length=10, unique=True) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\db\models\base.py:129, in ModelBase.__new__(cls, name, bases, attrs, **kwargs) 126 app_label = None 128 # Look for an application configuration to attach the model to. --> 129 app_config = apps.get_containing_app_config(module) 131 if getattr(meta, "app_label", None) is None: 132 if app_config is None: File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\apps\registry.py:260, in Apps.get_containing_app_config(self, object_name) 251 def get_containing_app_config(self, object_name): 252 """ 253 Look for an app config containing a given object. 254 (...) 258 Return None if the object isn't in any registered app config. 259 """ --> 260 self.check_apps_ready() 261 candidates = [] 262 for app_config in self.app_configs.values(): File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\apps\registry.py:137, in Apps.check_apps_ready(self) 132 from django.conf import settings 134 # If "not ready" is due to unconfigured settings, accessing 135 # INSTALLED_APPS raises a more helpful ImproperlyConfigured 136 # exception. --> 137 settings.INSTALLED_APPS 138 raise AppRegistryNotReady("Apps aren't loaded yet.") File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:81, in LazySettings.__getattr__(self, name) 79 """Return the value of a setting and cache it in self.__dict__.""" 80 if (_wrapped := self._wrapped) is empty: ---> 81 self._setup(name) 82 _wrapped = self._wrapped 83 val = getattr(_wrapped, name) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:61, in LazySettings._setup(self, name) 59 if not settings_module: 60 desc = ("setting %s" % name) if name else "settings" ---> 61 raise ImproperlyConfigured( 62 "Requested %s, but settings are not configured. " 63 "You must either define the environment variable %s " 64 "or call settings.configure() before accessing settings." 65 % (desc, ENVIRONMENT_VARIABLE) 66 ) 68 self._wrapped = Settings(settings_module) ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
In [3]:
Copied!
class Department(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Department(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
--------------------------------------------------------------------------- ImproperlyConfigured Traceback (most recent call last) Cell In[3], line 1 ----> 1 class Department(models.Model): 2 name = models.CharField(max_length=100) 4 def __str__(self): File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\db\models\base.py:129, in ModelBase.__new__(cls, name, bases, attrs, **kwargs) 126 app_label = None 128 # Look for an application configuration to attach the model to. --> 129 app_config = apps.get_containing_app_config(module) 131 if getattr(meta, "app_label", None) is None: 132 if app_config is None: File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\apps\registry.py:260, in Apps.get_containing_app_config(self, object_name) 251 def get_containing_app_config(self, object_name): 252 """ 253 Look for an app config containing a given object. 254 (...) 258 Return None if the object isn't in any registered app config. 259 """ --> 260 self.check_apps_ready() 261 candidates = [] 262 for app_config in self.app_configs.values(): File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\apps\registry.py:137, in Apps.check_apps_ready(self) 132 from django.conf import settings 134 # If "not ready" is due to unconfigured settings, accessing 135 # INSTALLED_APPS raises a more helpful ImproperlyConfigured 136 # exception. --> 137 settings.INSTALLED_APPS 138 raise AppRegistryNotReady("Apps aren't loaded yet.") File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:81, in LazySettings.__getattr__(self, name) 79 """Return the value of a setting and cache it in self.__dict__.""" 80 if (_wrapped := self._wrapped) is empty: ---> 81 self._setup(name) 82 _wrapped = self._wrapped 83 val = getattr(_wrapped, name) File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\django\conf\__init__.py:61, in LazySettings._setup(self, name) 59 if not settings_module: 60 desc = ("setting %s" % name) if name else "settings" ---> 61 raise ImproperlyConfigured( 62 "Requested %s, but settings are not configured. " 63 "You must either define the environment variable %s " 64 "or call settings.configure() before accessing settings." 65 % (desc, ENVIRONMENT_VARIABLE) 66 ) 68 self._wrapped = Settings(settings_module) ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
In [4]:
Copied!
class Employee(models.Model):
name = models.CharField(max_length=100)
role = models.CharField(max_length=100)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
def __str__(self):
return self.name
class Employee(models.Model):
name = models.CharField(max_length=100)
role = models.CharField(max_length=100)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
def __str__(self):
return self.name
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 1 ----> 1 class Employee(models.Model): 2 name = models.CharField(max_length=100) 3 role = models.CharField(max_length=100) Cell In[4], line 4, in Employee() 2 name = models.CharField(max_length=100) 3 role = models.CharField(max_length=100) ----> 4 department = models.ForeignKey(Department, on_delete=models.CASCADE) 6 def __str__(self): 7 return self.name NameError: name 'Department' is not defined