goinnn/django-multiselectfield

access to the values of the field failed in the code but I can get it in the shell

hamifthi opened this issue · 3 comments

Hello guys,
I have a problem when I try to access the values of the multiselectfield in my code but when I try on the shell I can access to the values

Day_Choices = (
    ('1', 'Saturday'),
    ('2', 'Sunday'),
    ('3', 'Monday'),
    ('4', 'Tuesday'),
    ('5', 'Wednesday'),
    ('6', 'Thursday'),
    ('7', 'Friday')
)
days_of_week = MultiSelectField(choices=Day_Choices, null=True)
from users.models import Coach                                                                                                           c = Coach.objects.all()
c
<QuerySet [<Coach: sth>]>
c = Coach.objects.all()[0]
c = Coach.objects.all()[0]
c
<Coach: sth>
c.age
23
c.days_of_week
['1', '2', '3']

but in the code

c = Coach.objects.all()[0]
print(c.days_of_week)

output
None, None, None

Rsvns commented

Same problem bro,try this:
print((c.days_of_week)[0])
Then,you can see the right value.

c.days_of_week isn't a general List in Python.The type of c.days_of_week is <class 'multiselectfield.db.fields.MSFList'>.

Rsvns commented

You can transform c.days_of_week to list:
print(list(c.days_of_week))

Same problem bro,try this:
print((c.days_of_week)[0])
Then,you can see the right value.

c.days_of_week isn't a general List in Python.The type of c.days_of_week is <class 'multiselectfield.db.fields.MSFList'>.

thanks for your help it's a long ago and I don't work with this module anymore. By the way thank you for your help