4

I am wondering if there is a way to use a list that is stored in a foreignkey as the choices for a charfield.

Here is what I have right now but it is not working.

priority = models.ForeignKey(SLAs)
prioritylevel = models.CharField(choices=priority.details)

It says that the ForeignKey has no attribute 'details'

If this has been answered, please point me the correct direction.

Thanks :)

icebox3d
  • 449
  • 7
  • 17

1 Answers1

4

I think you want use this in forms?

So you can do smth like this:

class MyForm(forms.ModelForm):
    prioritylevel = forms.ModelChoiceField(queryset=OtherModel.objects.values('level'))

and in model this will just CharField. It this solve your problem?

Andrey Nelubin
  • 3,084
  • 1
  • 20
  • 25