I'm trying to output the description field from my model in a django form without joy.
After searching around and not finding what I need I hope I can ask here.
Here is my models, form, template and template output. I've abrieviated to help make this post concise.
I'm working on the view in this project so the model has been designed by someone else and I can't really change it.
MODELS:
1)
from django.db import models
class Project(models.Model):
description = models.TextField(blank = True)
name = models.CharField(max_length = 255, blank = True)
def __unicode__(self):
""" String representation of projects. """
return unicode(self.name)
2)
from django.db import models
class Share(models.Model):
description = models.TextField
last_access = models.DateTimeField(auto_now = True)
location = models.URLField(verify_exists = False)
project = models.ForeignKey('Project', related_name = 'shares')
def __unicode__(self):
return unicode(self.location)
FORM:
from django import forms
from models import Share
class ExportForm(forms.Form):
ps = forms.ModelMultipleChoiceField(queryset=Share.objects.filter(project=1),widget=forms.SelectMultiple())
VIEW:
form = ExportForm()
TEMPLATE:
I have this to ouput the multiple select bos:
{{ form.ps }}
TEMPLATE OUTPUT:
<select multiple="multiple" name="ps" id="id_ps">
<option value="11">Share object </option>
<option value="10">Share object </option>
</select>
I've tried several things from searching around but can't seem to be able to make the 'description' field in there rather than 'Share object'
Any advise much appreciated.
Thanks!