0

I have a django table that's supposed to display the contents of each field of a model called Resource I wrote it like this, with results being a part of the contexts dictionary and simply containing filtered Resource objects.

      <table style="width: 70%;">
  <tr>
     <th>Title</th>
     <th>Author</th>
     <th>Country</th>
     <th>Description</th>
  </tr>
{% for resource in results %}
  <tr>
     <td><a href="{{ resource.link }}">{{ resource.title }}</a></td>
     <td>{{ resource.author }}</td>
     <td>{{ resource.country }}</td>
     <td>{{ resource.description }}</td>
  </tr>

{% endfor %}

The basic html table that created currently gets to dimensions of around 1500 x 3200. Pretty big, but that's not because my monitor is big or something like that. As a matter of fact, even if I had the css style set as width: 70% attribute or anything of that sort, the dimensions of the table do not change.

If I get rid of the following line, <td>{{ resource.description }}</td> which is supposed to display the Resource model's textfield known as "description", however, then then I can actually customize the width of the table and prevent it from being so long.

I need to be able to shorten the width of the table, and particularly this field. What can be done?

Byron Smith
  • 587
  • 10
  • 32
  • 1
    have a look at [this](https://stackoverflow.com/questions/4457506/set-the-table-column-width-constant-regardless-of-the-amount-of-text-in-its-cell) SO question and [this](https://jsfiddle.net/w8egv4r6/) jsfiddle. – ohannes Sep 01 '17 at 07:36

1 Answers1

0

Try adding css for the description <td>.

stye="overflow-x: scroll; width: 300px;"

That way no matter how long is the description it won't stretch the table.

sshopov
  • 220
  • 1
  • 6