Django can't convert 'Recipe_instruction' object to str implicitly
<p>I am developing an application in django. Here is my models.py and views.py code:</p>

<pre><code>#models.py
class Recipe_instruction(models.Model):
    content = models.TextField(max_length=500)
    recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
    order = models.IntegerField(max_length=500)
    class Meta:
            app_label='recipe_base'
    def __str__(self):
        return self.content
</code></pre>

<h1>views.py</h1>

<pre><code>#create recipes_dict
...
        recipe_instructions = Recipe_instruction.objects.filter(recipe = recipe)
        recipe_instructions_string = ""
        for recipe_instruction in recipe_instructions:
            recipe_instructions_string = recipe_instructions_string + recipe_instruction.content


...
</code></pre>

<p>My goal is to get all the recipe instructions and pin them together into a single string  <code>recipe_instructions_string</code></p>

<p>But when I run my views.py, it gives me the following error:</p>

<pre><code>recipe_instructions_string = recipe_instructions_string + recipe_instruction.content
TypeError: Can't convert 'Recipe_instruction' object to str implicitly
</code></pre>

<p>Can anyone tell me whats going on?</p>

<p>As recipe_instruction.content is a text field so I shouldn't need to convert it again into a string as its already a string.</p>

<p><strong>TRACEBACK:</strong></p>

<pre><code>Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/root/worker/worker/views.py", line 500, in Task1
    recipe_instructions_string = recipe_instructions_string + recipe_instruction.content
TypeError: Can't convert 'Recipe_instruction' object to str implicitly
</code></pre>

<p>The problem isn't with the code here.. but whilst we're looking at it, try changing the entire code to</p>

<pre><code>instructions = Recipe_instruction.objects.filter(recipe=recipe).values_list('content',
                                                                            flat=True)
recipe_instructions_string  = "".join(instructions)
</code></pre>

<p>This would stop the error from occuring if it were here, and be more efficient.</p>

python django