Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: '_TaggableManager' object has no attribute 'field' with django-simple-history #918

Open
leplatrem opened this issue Aug 20, 2024 · 0 comments
Labels

Comments

@leplatrem
Copy link

leplatrem commented Aug 20, 2024

I suppose that django-taggit and django-simple-history can work together, but can't figure it out, and can't find a full working example :(

I would like to enable history on the m2m relationship that django-taggit adds to my model, but the TaggableManager does not seem to have the necessary fields (?).

Using the following model definition:

from simple_history.models import HistoricalRecords
from taggit.managers import TaggableManager

class MyModel(models.Model):
    tags = TaggableManager()
    history = HistoricalRecords(m2m_fields=[tags])

I get this error:

  File "/Users/mathieu/Code/Perso/collect/.venv/lib/python3.12/site-packages/simple_history/models.py", line 794, in get_m2m_fields_from_model
    return [getattr(model, field_name).field for field_name in field_names]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_TaggableManager' object has no attribute 'field'

Although it looks very similar to what django-simple-history shows in the docs:

class Category(models.Model):
    name = models.CharField(max_length=200)

class Poll(models.Model):
    question = models.CharField(max_length=200)
    categories = models.ManyToManyField(Category)
    history = HistoricalRecords(m2m_fields=[categories])

What makes the TaggableManager different from a normal ManyToMany field?
What could I do to "trick" simple_history's HistoricalRecords m2m fields inspection?

Thank you for your support and great lib 🙏

Related #501

@rtpg rtpg added the bug label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants