{"action":"created","issue":{"url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/59","repository_url":"https://api.github.com/repos/theatlantic/django-nested-admin","labels_url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/59/comments","events_url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/59/events","html_url":"https://github.com/theatlantic/django-nested-admin/issues/59","id":181350392,"number":59,"title":"Multiplied inlines when ManyToManyField used","user":{"login":"adi-","id":340741,"avatar_url":"https://avatars.githubusercontent.com/u/340741?v=3","gravatar_id":"","url":"https://api.github.com/users/adi-","html_url":"https://github.com/adi-","followers_url":"https://api.github.com/users/adi-/followers","following_url":"https://api.github.com/users/adi-/following{/other_user}","gists_url":"https://api.github.com/users/adi-/gists{/gist_id}","starred_url":"https://api.github.com/users/adi-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adi-/subscriptions","organizations_url":"https://api.github.com/users/adi-/orgs","repos_url":"https://api.github.com/users/adi-/repos","events_url":"https://api.github.com/users/adi-/events{/privacy}","received_events_url":"https://api.github.com/users/adi-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-06T08:14:57Z","updated_at":"2016-10-06T15:45:55Z","closed_at":null,"body":"Models:\r\n\r\n```python\r\n\r\nclass One(models.Model):\r\n    ...\r\n\r\nclass Two(models.Model):\r\n  one = models.ForeignKey(One)\r\n\r\nclass Three(models.Model):\r\n  two = models.ForeignKey(Two)\r\n  additional = models.ManyToManyField(SomeModel)\r\n```\r\n\r\nAdmin:\r\n```python\r\nclass OneAdmin():\r\n    inlines = [TwoInline]\r\n\r\nclass TwoInline(nested_admin.NestedTabularInline):\r\n    model = Two\r\n    extra = 0\r\n    inlines = [ThreeInline]\r\n\r\nclass ThreeInline(nested_admin.NestedStackedInline):\r\n    model = Three\r\n    extra = 0\r\n```\r\n\r\nHaving above, I am selecting more than one `additional` in Django Admin. In result, Three model is multiplied by how many rows I have selected in `additional`. Is there any hack for that or it is a bug?"},"comment":{"url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/comments/252003480","html_url":"https://github.com/theatlantic/django-nested-admin/issues/59#issuecomment-252003480","issue_url":"https://api.github.com/repos/theatlantic/django-nested-admin/issues/59","id":252003480,"user":{"login":"fdintino","id":451612,"avatar_url":"https://avatars.githubusercontent.com/u/451612?v=3","gravatar_id":"","url":"https://api.github.com/users/fdintino","html_url":"https://github.com/fdintino","followers_url":"https://api.github.com/users/fdintino/followers","following_url":"https://api.github.com/users/fdintino/following{/other_user}","gists_url":"https://api.github.com/users/fdintino/gists{/gist_id}","starred_url":"https://api.github.com/users/fdintino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdintino/subscriptions","organizations_url":"https://api.github.com/users/fdintino/orgs","repos_url":"https://api.github.com/users/fdintino/repos","events_url":"https://api.github.com/users/fdintino/events{/privacy}","received_events_url":"https://api.github.com/users/fdintino/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T15:45:55Z","updated_at":"2016-10-06T15:45:55Z","body":"It really depends on what specifically you are ordering by. Most likely though you don't actually want to sort by a column on all rows on the related model, but just by the maximum or minimum value of that column. In which case you would do something like:\r\n\r\n```python\r\nclass SomeModel(models.Model):\r\n\tdate = models.DateTimeField()\r\n\r\n# ...\r\n\r\nclass ThreeManager(models.Manager):\r\n\r\n\tdef get_queryset(self):\r\n\t\tqset = super(ThreeManager, self).get_queryset()\r\n\t\treturn qset.annotate(max_date=models.Max('additional__date'))\r\n\r\n\r\nclass Three(models.Model):\r\n    two = models.ForeignKey(Two)\r\n    additional = models.ManyToManyField(SomeModel)\r\n\r\n    objects = ThreeManager()\r\n\r\n    class Meta:\r\n        ordering = ('-max_date', )\r\n```"}}
{"actor":{"display_login":"fdintino"}}