how to use django model without importing

0 votes
asked Apr 4 by anonymous

I have a django app with following files,, moving forward i am running into curricular imports kind of problem.

I am wondering if it is possible to use my django models without importing them into other .py files.

The closest example of what i want to achieve is something like this.

from django.contrib.auth import get_user_model

1 Answer

0 votes
answered Apr 4 by anonymous
from django.db.models.loading import get_model

model = get_model('app_name', 'ModelName')

#and u can do

model.objects.all() #model is now ModelName instance.

This is working in my django 1.8.x project for me, i am not sure if this is still working in latest release.

Update**: The utilities in django.db.models.loading are deprecated in
favor of the new application loading system. RemovedInDjango19Warning

Welcome , qPocho is an online community for programmers share there knowledge.