사용되지 않는 개체/선택되지 않은 개체를 새로 만들려고합니다. 사용 된 개체와 사용되지 않은 개체를 템플릿에 표시 할 수 있습니다.목록에 개체 제외
내 모델 :
class Benefit(models.Model):
name = models.CharField(max_length=200)
class Profile(models.Model):
benefits = models.ManyToManyField(Benefit, blank=True, null=True, related_name="used_benefit")
내보기 : 'ReverseManyRelatedObjectsDescriptor' object has no attribute 'all'
그때 all
없이 시도했지만 한 :
class Profile(TemplateView):
template_name = "profile/benefits.html"
def get_context_data(self, **kwargs):
context = super(Profile, self).get_context_data(**kwargs)
context['unused_benefits'] = Profile.objects.exclude(pk__in=Profile.benefits.all())
return context
그것은 내가이 오류가 있기 때문에, 임 못하고 뭔가 오류가 발생합니다. 'ReverseManyRelatedObjectsDescriptor' object is not itterable
누구가 잘못된 일을하는지 알아?
귀하의 질문은 나에게 분명하지 않다 : 당신이 그들에 첨부 된 프로필이없는 장점의 목록을 단순히 시도하는 경우
는, 당신은 실제로 프로필, 혜택 모델을하지 쿼리해야합니다. 사용하지 않거나 선택하지 않은 물체는 무엇을 의미합니까? –
혜택이없는 곳에서 Profile 개체를 가져 보았습니까? 일치하는 것을 제외하는 대신에? – mconlin