form select field by category django code example

Example 1: django ModelChoiceField value not id

articles = ModelChoiceField(queryset=Articles.objects.all(),
        to_field_name='slug')

Example 2: django modelform datetime

class BookingForm(ModelForm):
    check_in = DateTimeField(required=True, input_formats=["%Y-%m-%dT%H:%M", ])
    check_out = DateTimeField(
        required=True, input_formats=["%Y-%m-%dT%H:%M", ])
#NOTE: input_formats must be a list, even for a single format!
    class Meta:
        model = Booking
        fields = ['room', 'check_in', 'check_out']