0

I have two tables:

class Career(models.Model):    
    title = models.CharField(max_length=300)
    job_type = models.CharField(max_length=20, blank=False, default=None)
    location = models.CharField(max_length=200, blank=False, default=None)
    description = RichTextUploadingField(max_length=227, blank=False, default=None)

class ApplyJob(models.Model):
    first_name = models.CharField(verbose_name=_('First Name'), max_length=100)
    last_name = models.CharField(verbose_name=_('Last Name'), max_length=100)
    email = models.EmailField(verbose_name=_('Email'), max_length=200)
    position = models.CharField(verbose_name=_('Position'), max_length=40)
    apply = models.ManyToManyField(Career, default=None, blank=True)

And a ModelForm:

class Meta:
    model = ApplyJob
    fields = ('first_name', 'last_name', 'email','position', 'message')
    widgets = {
         'position': forms.Select(choices=CHOICES, attrs={'class': 'form-control'})}

I want to add choices selection in position with values from Career table, so itried to query Career table to get all values. So i tried CHOICES = Career.objects.values_list('title', flat=True).distinct() but i got an Exception Error: too many values to unpack (expected 2)

Any ideas on what the problem is about? Thank you!

paniklas
  • 305
  • 3
  • 15

1 Answers1

0

For those who may challenge the same problem. I solved it by adding id in the query. What i understood is that Select fields need an id and a display name. CHOICES = Career.objects.values_list('id', 'title').distinct()

paniklas
  • 305
  • 3
  • 15