0

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?

4
  • What is the output when you use {{ product.PrCompany }}? This will give you a hint as to what records are being accessed. Commented Aug 2, 2009 at 3:37
  • Interesting. If i do that, i get the name of the company? So guessing the relation works, but why dont i get the URL then? Is perhaps URL a reserved word of some sort? Commented Aug 2, 2009 at 10:49
  • Well, I suppose the next test would be to input a harmless string into one of the ComURL fields --- if you change the value to 'foo', do you still get 'None' returned on those records? Commented Aug 2, 2009 at 11:10
  • Found it... Apparently i was looking at one database, while i had the setup to another database. The database I was looking at was an older one, and the discrepancy in models was what was causing this. Commented Aug 2, 2009 at 12:12

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.