gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
in a django project, 2 apps created named common and user respectively, abstract model…
- User
in a django project, 2 apps created named common and user respectively, abstract model placed in common, how to extend the abstract model in user app
- Assistant
To extend the abstract model placed in the common app in the user app, you can simply create a new model in the user app that inherits from the abstract model in the common app.
Here is an example of how you can extend the abstract model in the user app:
- In the common app, create an abstract model named
BaseModel:
common/models.py:
from django.db import models class BaseModel(models.Model): name = models.CharField(max_length=100) class Meta: abstract = True- In the user app, create a new model named
UserModelthat extends theBaseModelfrom the common app:
user/models.py:
from django.db import models from common.models import BaseModel class UserModel(BaseModel): age = models.IntegerField()- Don't forget to add both apps to the
INSTALLED_APPSsetting in your Django project's settings.py file:
settings.py:
INSTALLED_APPS = [ ... 'common', 'user', ]By following these steps, you have successfully extended the abstract model placed in the common app in the user app using Django.
- In the common app, create an abstract model named