question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get values from ManyToManyRelationManager objects

See original GitHub issue
# Model like this
class Permission(Model):
    id = IntField(pk=True)
    name = CharField(max_length=160)

    def __str__(self):
        return self.name


class Role(Model):
    id = IntField(pk=True)
    name = CharField(max_length=160)
    permissions = ManyToManyField('models.Permission', related_name='perm')
    create_time = DatetimeField(auto_now=True)

    def __str__(self):
        return self.name
# Handler like this

class RoleHandler(RequestHandler):
    async def get(self, *args, **kwargs):
        role = await Role.all()
        for r in role:
            print(i.permissions)

<tortoise.fields.ManyToManyRelationManager object at 0x7fcb78126668>

How to get values from ManyToManyRelationManager objects ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, Feb 11, 2019

Sorry, await i.permissions._query without ()

0reactions
grigicommented, Feb 21, 2019

Hi, can you please check if your issue has been resolved with v0.11.4? The documentation has also been updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django DetailView getting values of ManyToMany ...
You can get the post tags with self.object.tags.all() so it will be something like :
Read more >
Many-to-many relationships
To define a many-to-many relationship, use ManyToManyField . In this example, an Article can be published in multiple Publication objects, and a Publication ......
Read more >
The right way to use a ManyToManyField in Django
To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references...
Read more >
Tips for Using Django's ManyToManyField
Tips for Using Django's ManyToManyField · Both objects must exist in the database · To retrieve the stuff in a ManyToManyField , you...
Read more >
Related objects reference — Django 4.1.4 documentation
You can use the bulk=False argument to instead have the related manager perform the update by calling e.save() . Using add() with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found