I have several files with names like: mod1.py, mod2.py, mod3.py, etc.
They consist of unique Models and Fields.
mod1.py:
from django.db import models
class Report(models.Model):
text = models.TextField()
...
models.py:
import random.random
id_part = random(1,10)
__import__('apps.reports.mod%s' % id_part)
When I try import it, the class is not found.
from models import Report
Is it possible to add another model in the model file with a variable name?
The problem is that your models aren’t imported in the scope of
models.pySo you need to somehow implementfrom foo import *dynamically. Here you can find a solution (not very elegant).Anyway it’s very strange approach.