Models.py for 'Accomm':
class Accomm(models.Model):
mapped_location=models.ForeignKey(Location,related_name='l_accomms',null=True,blank=True,on_delete=models.SET_NULL)
description=models.CharField(max_length=1000,null=True,blank=True)
creator=models.OneToOneField(accountmodels.UserProfileModel,related_name='u_creator',null=True,on_delete=models.SET_NULL,blank=True)
slug_key=models.SlugField(unique=True)
is_active=models.BooleanField(default=False)
Views.py:
def home(request):
user = request.user
accomm = Accomm.objects.annotate(img_count=models.Count('a_image')).filter(img_count__gte=1)[:6]
return render(request, 'home.html', {'accomm':accomm})
Any other ideas besides the solutions proposed here?