i want to get object that is Maximum length/count of ManyToMany Field
class Member(models.Model):
pass
class Chatroom(models.Model):
...
members = models.ManyToMany(Member)
...
chatRoom = Chatroom.objects.aggregate(Max('members'))
### {'members__max':15}
this code does not return an object like:class <QuerySet [object]> but i want to take an object to do something so i did do this
room = ChatRoom.objects.aggregate(max_value=Max('members')).get(members__count=max_value)
its got an Error : it says there is no __count look up.. could you help me please...
ChatRoomwith the most members? Note thatMax('members')will not do what you assume it does, it will only give the maximum id of theMembertable.