R0b0tn1k
R0b0tn1k

Reputation: 4306

Django relation doesnt work?

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?

Upvotes: 0

Views: 120

Answers (1)

Thomas Schreiber
Thomas Schreiber

Reputation: 1818

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

Upvotes: 1

Related Questions