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

Custom m2m field are not handled correctrly #1094

Closed
PiotrKurnik opened this issue Jan 3, 2023 · 1 comment
Closed

Custom m2m field are not handled correctrly #1094

PiotrKurnik opened this issue Jan 3, 2023 · 1 comment

Comments

@PiotrKurnik
Copy link

PiotrKurnik commented Jan 3, 2023

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:
Code snippet below illustrates the issue. There are assumptions to the name of the fields in through tables for m2m tables.
For the default through tables it works, but for the custom ones it does not.

If you try to save object of PageArticle you will see:

django.core.exceptions.FieldError: Cannot resolve keyword 'pagearticle' into field. Choices are: article, article_id, id, tag, tag_id
from django.db import models
from simple_history.models import HistoricalRecords

class Tag(models.Model):
    name = models.CharField(max_length=100)

class ArticleTag(models.Model):
    article = models.ForeignKey("PageArticle", on_delete=models.CASCADE)
    tag = models.ForeignKey(Tag, on_delete=models.CASCADE)

class PageArticle(models.Model):
    title = models.CharField(max_length=100)
    article_tags = models.ManyToManyField(Tag, through=ArticleTag)

    history = HistoricalRecords(m2m_fields=[
        article_tags,
    ])

Expected behavior
A model should be saved without any errors.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Environment (please complete the following information):

  • OS: MacOS, Windows
  • Browser (if applicable): [e.g. chrome, safari]
  • Django Simple History Version: 3.2.0
  • Django Version: 4.1.5

Additional context
Pull request that addresses the issue is #1093

@ddabble
Copy link
Member

ddabble commented Sep 26, 2023

See #1093 (comment).

@ddabble ddabble closed this as completed Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants