querying multiselectcheckbox

16 views
Skip to first unread message

Tech Today

unread,
Jan 31, 2018, 8:11:04 PM1/31/18
to Django users
# this is my model

from django.db import models
from multiselectfield import MultiSelectField

TRACK_EVENTS_CHOICES = (
('100M', '100 Meter'),
('200M', '200 Meter'),
('400M', '400 Meter'),
('800M', '800 Meter'),
('1500M', '1500 Meter'),
('5000M', '5000 Meter'),

)
class Particiepents(models.Model):

roll_no = models.IntegerField()
Full_name = models.CharField(max_length=40)
father_name = models.CharField(max_length=40)
sex = models.CharField(max_length=10, choices=SEX_CHOICES)
branch = models.CharField(max_length=20, choices=BRANCH_CHOICES)
semester = models.CharField(max_length=10, choices=SEMESTER_CHOICES)
track_events = MultiSelectField(max_length=30, null=True, blank=True, choices=TRACK_EVENTS_CHOICES, default="track_events")
field_events = MultiSelectField(max_length=30, null=True, blank=True, choices=FIELD_EVENTS_CHOICES, default="track_events")


def __str__(self):
return self.Full_name

# I want to retrieve a individual lists of Full_name participating in different track_events(100m, 200m, 400m..)



Andy

unread,
Feb 1, 2018, 3:30:44 AM2/1/18
to Django users
Once you fixed the typo in your model name its
Participants.objects.filter(track_events__in=['100M', '200M']).values_list('Full_name')

And you should use single case for model name (Participant) and lower case for full_name as you did with the other attributes.

Reply all
Reply to author
Forward
0 new messages