I have the following in models.py:
class Choices(models.Model):
description = models.CharField(max_length=300)
def __unicode__(self):
return self.description
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
fullname = models.CharField(_('Full Name'), max_length=50)
birthdate = models.DateTimeField(_('Birthday'))
url = models.URLField(_('Website'), blank=True)
company = models.CharField(_('Company'), max_length=50)
CATEGORY_CHOICES = (
('M',_('Male')),
('F',_('Female')),
)
gender = models.CharField(_('Gender'), max_length=200, choices = CATEGORY_CHOICES)
picture = models.ImageField(_('Picture/Avatar'), upload_to='profile_photo', blank=True)
bio = models.TextField()
planguages = models.ManyToManyField(Choices)
Now, I want to be able to edit both user profile in admin, as well as option to populate choices users can pick from when creating profile. Being a django newb I am, I managed to make options for editing users profiles only, but didn’t manage to populate Choices. Anyhow, I can do it, but I don’t know how to have both.
EDITED:
Here’s my current admin.py
class ChoicesAdmin(admin.ModelAdmin):
list_display = ['description']
class ProfilesAdmin(admin.ModelAdmin):
list_display = ['user']
admin.site.register(UserProfile, ProfilesAdmin)
What you are looking for is
filter_horizontalThis will allow you to add languages to a user.
Also, you must have the ChoicesAdmin class registered in order to see the green + link to add choices.