There are models of Network and ARM

class ARM (models.Model): class Meta(): db_table = 'arm' arm_configuration_name = models.TextField() arm_network = models.ManyToManyField(Network) class Server (models.Model): class Meta(): db_table = 'server' server_name = models.TextField() 

Task: In the template you need to display only those workstations that are associated with the Network.

Tried to do it in the template itself:

  {% for net in networks %} <div> {% for obj in net_id.arm_set %} <p>{{ obj.arm_configuration_name }}</p> {% endfor %} </div> {% endfor %} 

I also tried to write my own filter to use in the template. Created a file

 from django import template from django.template.defaultfilters import stringfilter from test_app.models import Network register = template.Library() @register.filter @stringfilter def arms_in_network(value): network = Network.objects.get(id = value) arms = network.arm_set.all() return arms' 

But there is another problem - at startup it gives an error: django.core.exceptions.AppRegistryNotReady: Apps are not loaded yet. In this case, the application is written in settings INSTALLED_APPS. And I found out that this error was due to the import of the Network.

Please tell me how to solve the problem. I would be glad if you offer other solutions.

  • If someone is interested: AppRegistryNotReady may appear due to the fact that you specified the application in INSTALLED_APPS and refer to the model that has not yet been created. In my case, the file ALREADY was in the application and it was not necessary to register it. - Evgeny Vasilyev

1 answer 1

Try this pattern:

 {% for net in networks %} <div> {% for arm in net.arm_set.all %} <p>{{ arm.arm_configuration_name }}</p> {% endfor %} </div> {% endfor %}