I have a form, which is for scheduling an appointment. I give user 3 dates on which the meeting can be scheduled. Now in the admin I want to select one of the dates according to my convenience, and store it in a field of the same model. How can I do that
Right now my meeting dates are just char fields like this
schedule1 = models.CharField()
schedule2 = model.CharField()
schedule3 = models.CharFiedl()
selected_schedule = model.CharField(choices={something here})
The schedule fields will be filled when the object is created. So I am sure the choices will be there, I just have to dynamically set them. How can I do this?
Any help will be appreciated.
Here’s what you do (if the schedule fields are already prefilled):
On your admin, simply state that you want to use that form:
Further note:
I’d recommend a different solution to your problem than storing the choices on the same model. For instance, you might have a model called
ScheduleChoice, and there could be 3 records of that, etc. Or, you might calculate the value based on some other rules, and just don’t store the choices at all. Also, I’d recommend usingDateTimeFieldto store the dates. You can convert the date to any format you like (e.g.January 12th, 2011 at 3:35PM) and still store it as the same datetime object in the database.