I am trying to add contents to models.py dynamically using templates. For this i have the following line in views.py
model_content = render_to_string('myapp/models.txt',{'table':table_name, 'fields':fields})
models.txt in templates
class {{ table }}(models.Model):
{% for field in fields %}
{{ field.field_name }} = models.{{ field.field_type.name }}
{% endfor %}
But when i wrote model_content string to a file say models.py i am getting the below
class Mytable(models.Model):
order = models.CharField
cust_name = models.CharField
I am getting an extra line after every line. How to avoid this. I will provide additional information if required.