Я написал определенную функцию, которую я хотел бы иметь во всех моих моделях Django. Какой лучший способ заставить все мои модели наследоваться от определенного класса?
То, что я попробовал, не сработало. Я сделал новый класс, как это:
from django.db import models
class McifModel(models.Model):
pass
А потом я сделал это в другой модели:
from django.db import models, connection, transaction
from mcif.models.mcif_model import McifModel
class Customer(mcif.models.McifModel):
id = models.BigIntegerField(primary_key=True)
customer_number = models.CharField(unique=True, max_length=255)
social_security_number = models.CharField(unique=True, max_length=33)
name = models.CharField(unique=True, max_length=255)
phone = models.CharField(unique=True, max_length=255)
deceased = models.IntegerField(unique=True, null=True, blank=True)
do_not_mail = models.IntegerField(null=True, blank=True)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
Но я получил эту ошибку:
Traceback (most recent call last):
File "./import.py", line 6, in <module>
from mcif.models import GenericImport, Customer, CSVRow
File "/home/jason/projects/mcifdjango/mcif/models/__init__.py", line 4, in <module>
from mcif.models.account_address import AccountAddress
File "/home/jason/projects/mcifdjango/mcif/models/account_address.py", line 2, in <module>
from mcif.models.account import Account
File "/home/jason/projects/mcifdjango/mcif/models/account.py", line 2, in <module>
from mcif.models.customer import Customer
File "/home/jason/projects/mcifdjango/mcif/models/customer.py", line 4, in <module>
class Customer(mcif.models.McifModel):
NameError: name 'mcif' is not defined