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.

Plugins that reference Post via ForeignKey all erroring when trying to add/edit them

See original GitHub issue

I made 3 plugins a few months back, that reference the Post model of this app using the ForeignKey field. I’m not sure what changed, as no changes were made to the code base, but for some reason all of the plugins that have these fields in them are now returning this error:

__str__ returned non-string (type NoneType)

Error during template rendering

In template /home/****/.env/venv/lib/python3.5/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19

__str__ returned non-string (type NoneType)
9	            {% for field in line %}
10	                <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11	                    {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12	                    {% if field.is_checkbox %}
13	                        {{ field.field }}{{ field.label_tag }}
14	                    {% else %}
15	                        {{ field.label_tag }}
16	                        {% if field.is_readonly %}
17	                            <p>{{ field.contents }}</p>
18	                        {% else %}
19	
                                  
      {{ field.field }}
      

      
20	                        {% endif %}
21	                    {% endif %}
22	                    {% if field.field.help_text %}
23	                        <p class="help">{{ field.field.help_text|safe }}</p>
24	                    {% endif %}
25	                </div>
26	            {% endfor %}
27	        </div>
28	    {% endfor %}
29	</fieldset>

The model here is very simple:

class FailingModel(CMSPlugin):
    post = models.ForeignKey(Post, related_name="failing_model", on_delete=models.CASCADE)

Any help would be greatly appreciated.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
gmenihcommented, Jun 6, 2017

@yakky Used a backed up database, since I wasn’t able to create a post without a title again, and it works now - shows the title of a different translation for the post that doesn’t exist in current translation.

Thanks for solving this!

1reaction
yakkycommented, Jun 5, 2017

@gmenih341 we need a smarter __str__ I guess. Let me check and I’ll be back to you later today

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database problem after update (Cannot add or update a child ...
Hello, I tried to update woocommerce, because i want to publish a new ... Database problem after update (Cannot add or update a...
Read more >
3 common foreign key mistakes (and how to avoid them)
Foreign key constraints are important to any SQL database, but they can also cause problems if they're not implemented correctly.
Read more >
Unable to create foreign key relationships in the Table Editor
Bug report Describe the bug Unable to create relationships between tables using the 'Add foreign key' function in the table editor.
Read more >
FOREIGN KEY constraint failed while trying to delete an object ...
So I have these models in my app:
Read more >
Foreign keys | WebStorm Documentation - JetBrains
Foreign key relationships specify how tables relate to each other and indicate relationships between tables. WebStorm recognizes foreign key ...
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