I have a django ForeignKey like this
class Example(models.Model):
Field = models.CharField("Description", max_length=50)
AnotherField = models.CharField("Extra Info", max_length=50)
def __unicode__(self):
return self.Field
By default the HTML select
will contain as description the values of the Example.Field
field. I can't change the unicode method. The real problem is when I need another values a model. I need something like This:
class SecondExapmle(models.Model):
Description = models.CharField("Description", max_length=50)
Foreign = models.ForeignKey(Example)
SecondData = models.ForeignKey(Example, show_value_from_column="AnotherField") # this line
Suposing that SecondExample
has the next records:
-----------------------------
| id | field | anotherfield |
-----------------------------
| 1 | Str | Another Str |
| 2 | Str2 | Another2 |
-----------------------------
I need that the Form's Foreign select contains the next HTML:
<select id="id_foreign">
<option value='1'>Str</option>
<option value='2'>Str2</option>
</select>
And the Forms AnotherField select contains the next HTML:
<select id="id_anotherfield">
<option value='1'>Anotheer Str</option>
<option value='2'>Another2</option>
</select>