Django GenericRelation fields not available during South migration

前端 未结 1 1455
陌清茗
陌清茗 2021-01-22 18:03

In a Django project, I have models defined like this :

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contri         


        
相关标签:
1条回答
  • 2021-01-22 18:43

    I've found a workaround filtering File's object with the appropriate content_type_id and object_id:

    from django.contrib.contenttypes.models import ContentType
    # ...
    folder_contenttype = ContentType.objects.get(name="folder")
    for folder in orm.Folder.objects.all():
        for f in orm.File.objects.filter(content_type_id = folder_contenttype.id, object_id = folder.id): # replaces folder.files.iterator():
            # ...
    

    This works but is less readable.

    0 讨论(0)
提交回复
热议问题