views:

68

answers:

1

I have the following in models:

  class Companies(models.Model):
    ComName = models.CharField(max_length=255)
    ComURL = models.CharField(max_length=1024,null=True)

  class Products(models.Model):
    PrName = models.CharField(max_length=255)
    PrCompany =  models.ForeignKey(Companies)

and the following in the template:

  {% if products %}
    var markers = [
    {% for product in products %}{"url":"{{ product.PrCompany.ComURL }}","name":"{{ product.PrName }}"},{% endfor %}
    ]
  {% endif %}
{% endblock %}

but the output i get is:

var markers = [
{"url":"None","name":"Samsung GT-S7350"},{"url":"None","name":"SonyEricsson W395"},{"url":"None","name":"Nokia E75"},
]

I look in the database, and each entry has a value in there, which is not empty. Why does it say "None" ? Something is not right in the relation?

A: 

you might want to try models.URLField() instead of a CharField for the ComURL.

rizumu
if i use URLfield that all URL's have to be unique, which is not something i want.