My Model:
class Account(models.Model):
"""
An account is for a team of users, or a single customer
"""
name = models.CharField(max_length=100, unique=True)
admins = models.ManyToManyField('AccountUser', related_name=' ', blank=True)
metadata = models.JSONField(default=dict, blank=True)
def __str__(self):
return self.name
@property
def customers(self):
"""Accounts linked to this account"""
return self.linked_accounts.linked_accounts.all()
and my code:
>>>account = Account.objects.get(id=1)
>>> print(account)
Bramble CFD
>>> print(account.name)
Bramble CFD
when I try to get the admins many_to_many field I get the following empty queryset:
>>> print(account.admins.all())
<QuerySet []>
but the admins field is not empty as demonstrate by the following screen shot from the django admin interface:
CodePudding user response:
There are Admins, and your Account exists, but none of the Admins are linked to that specific Account. The widget shows all Admins.
You thus can link Admins to an account by selecting these in the widget. In that case account.admins.all() will return the Admin objects selected for that account.

