19 lines
		
	
	
		
			624 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			624 B
		
	
	
	
		
			Python
		
	
	
	
from django.db import models
 | 
						|
 | 
						|
def get_child_queryset(checkQueryset,fatherQueryset,noneQueryset,hasParent=True):
 | 
						|
    """
 | 
						|
    获取所有子集
 | 
						|
    查checkQueryset
 | 
						|
    父fatherQueryset
 | 
						|
    空noneQueryset
 | 
						|
    是否包含父默认False
 | 
						|
    """
 | 
						|
    if fatherQueryset is None:
 | 
						|
        return noneQueryset
 | 
						|
    if hasParent:
 | 
						|
        noneQueryset = noneQueryset|fatherQueryset
 | 
						|
    child_queryset = checkQueryset.filter(pid=fatherQueryset.first())
 | 
						|
    while child_queryset:
 | 
						|
        noneQueryset = noneQueryset|child_queryset
 | 
						|
        child_queryset = checkQueryset.filter(pid__in=child_queryset)
 | 
						|
    return noneQueryset.distinct() |