Hello,
I installed django-profiles and added an extended UserProfile. One
template displays all fields which are necessary to edit a users
profile. Every user can choose a favorite aeroplane. Every aeroplane
is built by one manufacturer.
I print the edit form in the template with {{ form }}. The form
dispays a select tag to chose a favorite aeroplane. Everything works
fine.
I want to make a little change on how the select field displays the
options. I would like to add the manufacturer to the option string. Is
there an easy way to insert the manufacturer to the option? I want to
avoid as much code as possible since the django-profiles app provides
views and forms. I hope not to write any own. Maybe I can change the
model so that it alwas displays Manufacturer+Aeroplane when called?
I just tried to insert the following code in the Aeroplane class:
def __unicode__(self):
return self.name + manufacturer.name
------------
Here some detailed explanation and code:
My select field looks like this:
<select>
<option>Plane1</option>
<option>Plane2</option>
<option>Plane3</option>
</select>
My select field *should* looks like this:
<select>
<option>Manufacturer1 Plane1</option>
<option>Manufacturer2 Plane2</option>
<option>Manufacturer3 Plane3</option>
</select>
Here is the models.py
class Aeroplane(models.Model):
name = models.CharField(max_length=32, unique=True)
year_of_construction = models.PositiveSmallIntegerField()
manufacturer = models.ForeignKey(Manufacturer)
def __unicode__(self):
return self.name
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
favorite_aeroplane = models.ForeignKey(Aeroplane, blank=True)
def get_absolute_url(self):
return ('profiles_profile_detail', (), { 'username':
self.user.username })
get_absolute_url = models.permalink(get_absolute_url)
Here is the template:
{% extends "base.html" %}
{% block content %}
<form method="POST" action="">
{{ form.as_p }}
<input type="submit" name="submit" value="Update" id="submit">
</form>
{% endblock content %}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---