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

Tags Issue #285

Open
ryaustin opened this issue Jun 24, 2024 · 2 comments
Open

Tags Issue #285

ryaustin opened this issue Jun 24, 2024 · 2 comments

Comments

@ryaustin
Copy link
Collaborator

I've added a Tag model, which is a many-to-many field on the RepertoireTune model. There are no errors, tags I create in the admin show up for selection in the relevant form, and using a debugger I've confirmed that the selected tags do get saved in both the form and view. But for some reason after the page renders the saved tags disappear. I've looked around and found a lot of resources saying to use save_m2m(), but that doesn't seem to help. Here is a link to the branch: https://github.com/jwjacobson/jazztunes/tree/tags
The relevant parts of the code are the Tag and RepertoireTune models, the RepertoireTuneForm, and the tune_edit view.

@ryaustin
Copy link
Collaborator Author

Hey Jeff, I pulled the branch and immediately had to deal with db migration issues. It appears that your through model might have had a conflict with a field/table that already existed.

I tried to troubleshoot the migration but as my db only has test data I decided to blow away(delete) my db and run migrations again to rebuild. After I did that your code worked fine. Tags weren't rendered in your list (displayed None) due to the syntax which you would've figured out anyway.

You can fix that by rendering m2ms in the list.html template like so:

    <td>
        {% for tag in tune.tags.all %}
        <span class="badge bg-primary">{{ tag.name }}</span>
        {% endfor %}
    </td>

Let me know if this helps. I believe you already had some scripts created to repopulate your db data so hopefully rebuilding the db is an option for you. If not, you will need to figure out which migration operation caused things to go ary and nuke it by commenting it out. This is a bit of an iterative process with the side-effect of getting a good grasp on how Django orm migrations work.

@jwjacobson
Copy link
Owner

Thanks! What threw me on the tags not displaying it that they also don't show up in the Django admin as associated in any way with a RepertoireTune, so I assumed the None in the template was just that, a None.

As for the database migrations, I ran into issues when I tried to use django-taggit and then opted not to. In the process of getting things working I ended up deleting all my migration files... how bad does that leave me in trying to resolve this? Interestingly the production database is running fine despite having deployments since then--

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

No branches or pull requests

2 participants