I'm creating a user registration system for a project.
The system uses the SelectDateWidget for user input of birthdate.
When I try to register a new user, the system spits back this error:
'str' object has no attribute 'strftime'
This is the relevant code:
bd_month = frm.data['birthdate_month']
bd_day = frm.data['birthdate_day']
if len(bd_month) == 1:
bd_month = '0'+bd_month
if len(bd_day) == 1:
bd_day = '0'+bd_day
temp_date = frm.data['birthdate_year']+'-'+bd_month+'-'+bd_day
The error occurs in django/db/models/fields/__init__.py in
get_db_prep_save
Anyone have a clue?
A few more clues might be helpful. The error message is telling you that
you're passing a string where a datetime object is expected, but you
don't explain how you are passing data to a model field anywhere. Note
that get_db_prep_save() is used to convert Python objects back to
strings for putting into the database, so if your field data has not
been already converted to a Python object by that point, a mistake has
been made somewhere.
What line in the above code fragment throughs the exception? If none of
those lines do it, how are you passing your data to the code that does
throw the exception? Can you write a short example that shows the
problem?
Regards,
Malcolm
I just figured it out - with some help in the IRC-channel.
I passed the form variables through datetime.date. That did the trick.
Thanks for your reply!
best regards,
David
AttributeError at /telecom/conference/detail/9/
'tuple' object has no attribute 'strftime'
----
This happens on update of newform. What am I doing wrong?
view code:
-----------------
conf = Conference.objects.get(id=conf_id)
if request.POST:
#validate input:
if conf.caller == os.environ['REMOTE_USER']:
p = request.POST.copy()
form = ConferenceForm(p)
print "before is valid"
if form.is_valid():
print dir(form.clean_data['conference_date'])
#try:
conf.caller=form.clean_data['caller'],
conf.extension=form.clean_data['extension'],
conf.day_of_week=form.clean_data['day_of_week'],
conf.conference_date=form.clean_data['conference_date'],
conf.conference_time=form.clean_data['conference_time'],
conf.time_zone=form.clean_data['time_zone'],
conf.group_leader=form.clean_data['group_leader'],
conf.leader_extension=form.clean_data['leader_extension'],
conf.number_of_lines=form.clean_data['number_of_lines'],
conf.domestic_lines=form.clean_data['domestic_lines'],
conf.international_lines=form.clean_data['international_lines'],
conf.duration_of_call=form.clean_data['duration_of_call'],
conf.recurring_call=form.clean_data['recurring_call'],
conf.end_date=form.clean_data['end_date'],
conf.cost_code=form.clean_data['cost_code'],
conf.unattended_tone_in=form.clean_data['unattended_tone_in']
conf.save()
msg = "Conference #%s Updated" % conf_id
-----
conferenceForm:
-----
class ConferenceForm(forms.Form):
caller = forms.CharField(max_length=256,label="Caller/Requester",
initial=os.environ['REMOTE_USER'])
extension = forms.CharField(max_length=11,label="Extension")
day_of_week = forms.ChoiceField(label="Day of
Week",choices=dow_choices)
conference_date = forms.DateField(label="Conference Date")
conference_time = forms.TimeField(label="Conference Time")
time_zone = forms.CharField(max_length=4,label="Time Zone")
group_leader = forms.CharField(max_length=32,label="Group Leader")
leader_extension = forms.CharField(max_length=11,label="Leader
Extension")
number_of_lines = forms.CharField(max_length=11,label="Number of
Lines")
domestic_lines = forms.CharField(max_length=11,label="Domestic
Lines")
international_lines =
forms.CharField(max_length=11,label="International Lines")
duration_of_call = forms.TimeField(label="Call Duration")
recurring_call = forms.CharField(label="Recurring
Call",required=False,
widget=CheckboxInput())
end_date = forms.CharField(label="End Date",required=False)
cost_code = forms.CharField(max_length=32,label="Cost Code")
unattended_tone_in = forms.CharField(label="Unattended Tone-in",
widget=CheckboxInput(),
initial=True)
On Apr 30, 11:39 am, "deezth...@gmail.com" <deezth...@gmail.com>
wrote:
In python if you do an assignment where the right hand side has one or
more commas then it means you are creating a tuple:
>>> a = 1
>>> a
1
>>> a = 1,
>>> a
(1,)
So just remove the trailing commas in your view and you will then be
assigning a date rather than a tuple to conference_date.
In general the error "'tuple' object has no attribute xxx" normally
means a trialling comma slipped in somewhere - it is a mistake I have
made several times.
--
Phil