I have been searching and looking through docs, but I want to ask and confirm for the best solution here.
Trying to define model choices.
- 'yes, no and not sure' choice From Radio Select
- How would I define for Multiple Choices
Simple Example: In my models.py, I have
class Property(models.Model):
name = models.CharField()
class Feature(models.Model):
YES_CHOICES = ( # example of 1, there can be only one selection
('YES', 'Yes'),
('NO', 'No'),
('NOT_SURE', 'Not Sure')
)
PARKING_CHOICES = ( # example of 2, there can be multiple selections
('GARAGE', 'Garage'),
('STREET', 'Street'),
('PRIVATE_LOT', 'Private Lot'),
('VALET', 'Valet'),
)
nearby_school = models.CharField(max_length=8, choices=YES_CHOICES)
parking_options = models. MultipleChoiceField(choices=PARKING_CHOICES)
class PropertyFeature(models.Model)
property = models.ForeignKey(Property)
feature = models.ForeignKey(Feature)
...
Are those best ways to do it?
- Should I use NullBooleanField instead for yes, no , not sure question?
- Is that a correct way for defining and storing for multiple choice answers? Sometimes, I see people using manytomany objects.
Just want to use the most efficient and the easiest method offered from Django.