Re: strftime

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Hi Armagan,

I would suggest investigating what the 'date' variable contains..

You can do this by doing:
print type(date)
print dir(date)
print date

I'd also recommend going back through your code and seeing how the date
object is instantiated.

For future reference, you do really need to provide more info in the future
to get any sort of assistance.

There's some great tips and advice on what information is useful to provide
here:
https://code.djangoproject.com/wiki/UsingTheMailingList

Cal

On Thu, Jun 21, 2012 at 9:47 AM, armagan  wrote:

> Hi,
>
> I'm trying to show the date in rss with this function
>
> def item_pubdate(self, item):
>
> date = item.delivery_date
>
> return date.strftime("%d/%m/%y")
>
> But I have an error  'str' object has no attribute 'tzinfo'.
>
> Can you help me? How I code the function?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/xE87Vj40cLQJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: strftime

2012-06-21 Thread robin nanola
i think i would be better if you  read python datetime docs

http://docs.python.org/library/datetime.html#datetime.date.strftime

On Thu, Jun 21, 2012 at 4:47 PM, armagan  wrote:

> Hi,
>
> I'm trying to show the date in rss with this function
>
> def item_pubdate(self, item):
>
> date = item.delivery_date
>
> return date.strftime("%d/%m/%y")
>
> But I have an error  'str' object has no attribute 'tzinfo'.
>
> Can you help me? How I code the function?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/xE87Vj40cLQJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



strftime

2012-06-21 Thread armagan
Hi,

I'm trying to show the date in rss with this function

def item_pubdate(self, item):

date = item.delivery_date

return date.strftime("%d/%m/%y")

But I have an error  'str' object has no attribute 'tzinfo'.

Can you help me? How I code the function?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/xE87Vj40cLQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 'unicode' object has no attribute 'strftime'

2008-02-16 Thread Darthmahon

All,

Got it working in the end - this is what I did:

_dob_year = int(form.clean_data['dob_year'])
_dob_month = int(form.clean_data['dob_month'])
_dob_day = int(form.clean_data['dob_day'])

_dob = date( year = _dob_year, month = _dob_month, day = _dob_day )

There probably is a cleaner way of doing it, but it seems to work :)

On Feb 16, 10:49 am, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hi Alex,
>
> Tried this and it gave me the following error:
>
> TypeError at /register/
> an integer is required
>
> Any ideas?
>
> On Feb 13, 11:03 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> > You create string object with bits from form. But you have to make
> > date object. Example:
>
> > from datetime import date
> > _dob = date( year = form.clean_data['dob_year'],
> >                    month = form.clean_data['dob_month'],
> >                    day = form.clean_data['dob_day']
> >                       )
>
> > On 14 фев, 01:48,Darthmahon<[EMAIL PROTECTED]> wrote:
>
> > > Hi Alex,
>
> > > Not quite sure what you mean exactly. This is how that field is
> > > structured in my models.py file:
>
> > > birthday = models.DateField(blank=True)
>
> > > So it's already set as a datefield, but for some reason it seems as
> > > though my join is converting it into a string and Django doesn't like
> > > that.
>
> > > By the way, I am using Django 0.96 and MySQL.
>
> > > On Feb 13, 10:38 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> > > > If birthday UserProfile field in DataField you must set date object to
> > > > it. Not string.
>
> > > > On 14 фев, 00:50,Darthmahon<[EMAIL PROTECTED]> wrote:
>
> > > > > Hmm I seem to have hit another problem just after another!
>
> > > > > I've got a form that lets user's select the birthday via three
> > > > > dropdowns (day, month and year). This is all using newforms.
> > > > > Basically, within my views.py file I have a function that creates new
> > > > > users - one part of this process is to make sure the three dropdowns
> > > > > are joined together to create the timestamp so I can insert into the
> > > > > database.
>
> > > > > Here is this join:
>
> > > > > # join date back together
> > > > > days =
> > > > > [form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data['
> > > > >  dob_day']]
> > > > > _dob = "-".join(days)
>
> > > > > # save user
> > > > > user =
> > > > > User.objects.create_user(username=_username,email=_email,password=_password
> > > > >  )
> > > > > user.save()
>
> > > > > # save custom profile
> > > > > user_profile =
> > > > > UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> > > > > user_profile.save()
>
> > > > > However - what happens is I get this error:
>
> > > > > AttributeError at /register/
> > > > > 'unicode' object has no attribute 'strftime'
>
> > > > > Now I am sure it is referring to the join I am trying to do. I've
> > > > > tried wrapping unicode() around it but that didn't help either.
>
> > > > > Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'unicode' object has no attribute 'strftime'

2008-02-16 Thread Darthmahon

Hi Alex,

Tried this and it gave me the following error:

TypeError at /register/
an integer is required

Any ideas?

On Feb 13, 11:03 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> You create string object with bits from form. But you have to make
> date object. Example:
>
> from datetime import date
> _dob = date( year = form.clean_data['dob_year'],
>                    month = form.clean_data['dob_month'],
>                    day = form.clean_data['dob_day']
>                       )
>
> On 14 фев, 01:48,Darthmahon<[EMAIL PROTECTED]> wrote:
>
> > Hi Alex,
>
> > Not quite sure what you mean exactly. This is how that field is
> > structured in my models.py file:
>
> > birthday = models.DateField(blank=True)
>
> > So it's already set as a datefield, but for some reason it seems as
> > though my join is converting it into a string and Django doesn't like
> > that.
>
> > By the way, I am using Django 0.96 and MySQL.
>
> > On Feb 13, 10:38 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> > > If birthday UserProfile field in DataField you must set date object to
> > > it. Not string.
>
> > > On 14 фев, 00:50,Darthmahon<[EMAIL PROTECTED]> wrote:
>
> > > > Hmm I seem to have hit another problem just after another!
>
> > > > I've got a form that lets user's select the birthday via three
> > > > dropdowns (day, month and year). This is all using newforms.
> > > > Basically, within my views.py file I have a function that creates new
> > > > users - one part of this process is to make sure the three dropdowns
> > > > are joined together to create the timestamp so I can insert into the
> > > > database.
>
> > > > Here is this join:
>
> > > > # join date back together
> > > > days =
> > > > [form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data['
> > > >  dob_day']]
> > > > _dob = "-".join(days)
>
> > > > # save user
> > > > user =
> > > > User.objects.create_user(username=_username,email=_email,password=_password
> > > >  )
> > > > user.save()
>
> > > > # save custom profile
> > > > user_profile =
> > > > UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> > > > user_profile.save()
>
> > > > However - what happens is I get this error:
>
> > > > AttributeError at /register/
> > > > 'unicode' object has no attribute 'strftime'
>
> > > > Now I am sure it is referring to the join I am trying to do. I've
> > > > tried wrapping unicode() around it but that didn't help either.
>
> > > > Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'unicode' object has no attribute 'strftime'

2008-02-13 Thread Alex Koshelev

You create string object with bits from form. But you have to make
date object. Example:

from datetime import date
_dob = date( year = form.clean_data['dob_year'],
   month = form.clean_data['dob_month'],
   day = form.clean_data['dob_day']
  )

On 14 фев, 01:48, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hi Alex,
>
> Not quite sure what you mean exactly. This is how that field is
> structured in my models.py file:
>
> birthday = models.DateField(blank=True)
>
> So it's already set as a datefield, but for some reason it seems as
> though my join is converting it into a string and Django doesn't like
> that.
>
> By the way, I am using Django 0.96 and MySQL.
>
> On Feb 13, 10:38 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> > If birthday UserProfile field in DataField you must set date object to
> > it. Not string.
>
> > On 14 фев, 00:50, Darthmahon <[EMAIL PROTECTED]> wrote:
>
> > > Hmm I seem to have hit another problem just after another!
>
> > > I've got a form that lets user's select the birthday via three
> > > dropdowns (day, month and year). This is all using newforms.
> > > Basically, within my views.py file I have a function that creates new
> > > users - one part of this process is to make sure the three dropdowns
> > > are joined together to create the timestamp so I can insert into the
> > > database.
>
> > > Here is this join:
>
> > > # join date back together
> > > days =
> > > [form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data['
> > >  dob_day']]
> > > _dob = "-".join(days)
>
> > > # save user
> > > user =
> > > User.objects.create_user(username=_username,email=_email,password=_password
> > >  )
> > > user.save()
>
> > > # save custom profile
> > > user_profile =
> > > UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> > > user_profile.save()
>
> > > However - what happens is I get this error:
>
> > > AttributeError at /register/
> > > 'unicode' object has no attribute 'strftime'
>
> > > Now I am sure it is referring to the join I am trying to do. I've
> > > tried wrapping unicode() around it but that didn't help either.
>
> > > Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'unicode' object has no attribute 'strftime'

2008-02-13 Thread Darthmahon

Hi Alex,

Not quite sure what you mean exactly. This is how that field is
structured in my models.py file:

birthday = models.DateField(blank=True)

So it's already set as a datefield, but for some reason it seems as
though my join is converting it into a string and Django doesn't like
that.

By the way, I am using Django 0.96 and MySQL.

On Feb 13, 10:38 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> If birthday UserProfile field in DataField you must set date object to
> it. Not string.
>
> On 14 фев, 00:50, Darthmahon <[EMAIL PROTECTED]> wrote:
>
> > Hmm I seem to have hit another problem just after another!
>
> > I've got a form that lets user's select the birthday via three
> > dropdowns (day, month and year). This is all using newforms.
> > Basically, within my views.py file I have a function that creates new
> > users - one part of this process is to make sure the three dropdowns
> > are joined together to create the timestamp so I can insert into the
> > database.
>
> > Here is this join:
>
> > # join date back together
> > days =
> > [form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data[' 
> > dob_day']]
> > _dob = "-".join(days)
>
> > # save user
> > user =
> > User.objects.create_user(username=_username,email=_email,password=_password 
> > )
> > user.save()
>
> > # save custom profile
> > user_profile =
> > UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> > user_profile.save()
>
> > However - what happens is I get this error:
>
> > AttributeError at /register/
> > 'unicode' object has no attribute 'strftime'
>
> > Now I am sure it is referring to the join I am trying to do. I've
> > tried wrapping unicode() around it but that didn't help either.
>
> > Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'unicode' object has no attribute 'strftime'

2008-02-13 Thread Alex Koshelev

If birthday UserProfile field in DataField you must set date object to
it. Not string.

On 14 фев, 00:50, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hmm I seem to have hit another problem just after another!
>
> I've got a form that lets user's select the birthday via three
> dropdowns (day, month and year). This is all using newforms.
> Basically, within my views.py file I have a function that creates new
> users - one part of this process is to make sure the three dropdowns
> are joined together to create the timestamp so I can insert into the
> database.
>
> Here is this join:
>
> # join date back together
> days =
> [form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data['dob_day']]
> _dob = "-".join(days)
>
> # save user
> user =
> User.objects.create_user(username=_username,email=_email,password=_password)
> user.save()
>
> # save custom profile
> user_profile =
> UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
> user_profile.save()
>
> However - what happens is I get this error:
>
> AttributeError at /register/
> 'unicode' object has no attribute 'strftime'
>
> Now I am sure it is referring to the join I am trying to do. I've
> tried wrapping unicode() around it but that didn't help either.
>
> Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'unicode' object has no attribute 'strftime'

2008-02-13 Thread Darthmahon

Hmm I seem to have hit another problem just after another!

I've got a form that lets user's select the birthday via three
dropdowns (day, month and year). This is all using newforms.
Basically, within my views.py file I have a function that creates new
users - one part of this process is to make sure the three dropdowns
are joined together to create the timestamp so I can insert into the
database.

Here is this join:

# join date back together
days =
[form.clean_data['dob_year'],form.clean_data['dob_month'],form.clean_data['dob_day']]
_dob = "-".join(days)

# save user
user =
User.objects.create_user(username=_username,email=_email,password=_password)
user.save()

# save custom profile
user_profile =
UserProfile(user_id=user.id,gender=_gender,birthday=_dob,living=_location)
user_profile.save()

However - what happens is I get this error:

AttributeError at /register/
'unicode' object has no attribute 'strftime'

Now I am sure it is referring to the join I am trying to do. I've
tried wrapping unicode() around it but that didn't help either.

Any ideas? I've had a look on here but can't see any solutions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting error: 'unicode' object has no attribute 'strftime'

2007-10-13 Thread Karen Tracey

At 10:35 AM 10/13/2007, Greg wrote:
[snip details of change to django code]

>That seems to fix the problem.  Is the code that I took needed there
>for a reason?  Will this changed have an effect on how other areas of
>my application work?

Yes, that code is needed and is there for a reason.  The object 
passed to that function should NOT be a unicode object, it ought to 
be a datetime object so that strftime can be called on it to properly 
format it.  The bug is not the line of code you changed, it is 
whatever is causing a unicode object to be passed into the 
flatten_data function.

I see from the archives you have brought this problem to the group 
before, but I don't see any resolution.  I gather you are using 
sqlite, which, I'm sorry, I know nothing about so I can't really help 
you.  For some reason you are getting back a unicode object from the 
db instead of a datetime.  You say you just added this DateTime field 
to your model.  Did you modify the table in sqlite yourself or did 
you re-initialize using django?  It seems that either your version of 
sqlite is behaving oddly and returning a unicode string for something 
that ought to be a datetime object, or the field is not of the proper 
type in the database.

Karen


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting error: 'unicode' object has no attribute 'strftime'

2007-10-13 Thread Greg

Ok,
I've made some changes and now I'm able to add styles in the admin.
However, it required me to change change a django file that I'm not
sure I should change.  Here is what i changed.

In c:\Python24\lib\site-packages\django\db\models\fields\__init__.py
and changed the method 'flatten_data(self, follow, obj=None):'.  I
changed the following line of code from:

return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or
'')}

to

return {self.attname: (val is not None or '')}

/

That seems to fix the problem.  Is the code that I took needed there
for a reason?  Will this changed have an effect on how other areas of
my application work?

Thanks


On Oct 12, 5:34 pm, Greg <[EMAIL PROTECTED]> wrote:
> Hello,
> I just added the following field to my Style class:
>
> newrugs = models.DateField(auto_now_add=True)
>
> Now, when I try to view my Style objects in the admin I get the
> following error:
>
> AttributeError at /admin/plush/style/5/
> 'unicode' object has no attribute 'strftime'
>
> 
>
> Any suggestions on what's causing this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Getting error: 'unicode' object has no attribute 'strftime'

2007-10-12 Thread Greg

Hello,
I just added the following field to my Style class:

newrugs = models.DateField(auto_now_add=True)

Now, when I try to view my Style objects in the admin I get the
following error:

AttributeError at /admin/plush/style/5/
'unicode' object has no attribute 'strftime'



Any suggestions on what's causing this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'str' has no attribute 'strftime'

2007-09-18 Thread Russell Keith-Magee

On 9/19/07, jacoberg2 <[EMAIL PROTECTED]> wrote:
>
> Hey, I am trying to read a string from a file and then save it to the
> database. In doing so I get the error message 'str' has no attribute
> 'strftime'. the string is a a dat that i am trying to save to the
> datetimefield in my database. The parser i used returned a string but
> hen it tries to save this string tothe appropiate place it send that
> error back. any suggestions? Thanks for your time.

What version of Django are you using? This bug (or something very much
like it) was fixed over the weekend sprint, so it shouldn't be a
problem any more in the SVN trunk version. If it is, we may need to
reopen a ticket.

As a side note - part of the problem is that datetime fields are
supposed to accept DateTime objects, not strings. As a result of the
change on the weekend, strings that are correctly formatted (by which
I mean 'ready for DB-API insertion', in the format '%Y-%m-%d
%H:%M:%S') are also accepted, but any other format will still cause
difficulties.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'str' has no attribute 'strftime'

2007-09-18 Thread jacoberg2

Hey, I am trying to read a string from a file and then save it to the
database. In doing so I get the error message 'str' has no attribute
'strftime'. the string is a a dat that i am trying to save to the
datetimefield in my database. The parser i used returned a string but
hen it tries to save this string tothe appropiate place it send that
error back. any suggestions? Thanks for your time.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error adding DateField - 'unicode' object has no attribute 'strftime'

2007-09-05 Thread Michael Radziej

Hi Greg,

On Wed, Sep 05, Greg wrote:

> 
> Michael,
> I'm using sqlite.

Thanks for the clarification. I've almost no experience with sqlite, sorry.

Michael


-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error adding DateField - 'unicode' object has no attribute 'strftime'

2007-09-05 Thread Greg

Michael,
I'm using sqlite.

Lapin,
Where in my code do you want me to use smart_str?

Thanks

On Aug 29, 3:58 am, Michael Radziej <[EMAIL PROTECTED]> wrote:
> On Tue, Aug 28, Greg wrote:
>
> > Hello,
> > I have the following code in my models.py file
>
> > class Orders(models.Model):
> > timestamp = models.DateField()
> > ... etc
>
> > /
>
> > I have the following in my view.py function
>
> > from datetime import datetime
> > o = Orders()
> > o.timestamp = datetime.now()
> > ... etc
> > o.save()
>
> > 
>
> > However, when I view this order in the admin I get the following
> > error:
>
> > AttributeError at /admin/rugs/orders/13/
> > 'unicode' object has no attribute 'strftime'
>
> > Does anybody know what's going on?
>
> Do you use Mysql? I made the weird experience that MySQLdb sometimes returns
> a string instead of datetime.datetime. It seemed to happen deep in either
> MySQLdb or even the client library of mysql. (Mysql 4.1)
>
> Michael
>
> --
> noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
> Tel +49-911-9352-0 - Fax +49-911-9352-100http://www.noris.de- The 
> IT-Outsourcing Company
>
> Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk -
> Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error adding DateField - 'unicode' object has no attribute 'strftime'

2007-08-29 Thread Michael Radziej

On Tue, Aug 28, Greg wrote:

> 
> Hello,
> I have the following code in my models.py file
> 
> class Orders(models.Model):
> timestamp = models.DateField()
> ... etc
> 
> /
> 
> I have the following in my view.py function
> 
> from datetime import datetime
> o = Orders()
> o.timestamp = datetime.now()
> ... etc
> o.save()
> 
> 
> 
> However, when I view this order in the admin I get the following
> error:
> 
> AttributeError at /admin/rugs/orders/13/
> 'unicode' object has no attribute 'strftime'
> 
> Does anybody know what's going on?

Do you use Mysql? I made the weird experience that MySQLdb sometimes returns
a string instead of datetime.datetime. It seemed to happen deep in either
MySQLdb or even the client library of mysql. (Mysql 4.1)

Michael

-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error adding DateField - 'unicode' object has no attribute 'strftime'

2007-08-29 Thread Iapain

try converting it into string with smart_str


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Error adding DateField - 'unicode' object has no attribute 'strftime'

2007-08-28 Thread Greg

Hello,
I have the following code in my models.py file

class Orders(models.Model):
timestamp = models.DateField()
... etc

/

I have the following in my view.py function

from datetime import datetime
o = Orders()
o.timestamp = datetime.now()
... etc
o.save()



However, when I view this order in the admin I get the following
error:

AttributeError at /admin/rugs/orders/13/
'unicode' object has no attribute 'strftime'

Does anybody know what's going on?

Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-08 Thread Frank Singleton

Russell Keith-Magee wrote:

>On 8/8/07, Collin Grady <[EMAIL PROTECTED]> wrote:
>  
>
>>This is not a backend issue at all - the problem is you're assigning a
>>string to the DateField, which is not what it needs.
>>
>>
Thank Russ for the help.. typo on my part ;-)

yes this works !!

mydate = datetime.date(*time.strptime(inputdata[MY_DATE], '%Y-%m-%d')[:3])

Cheers.

/Frank





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-08 Thread Russell Keith-Magee

On 8/8/07, Collin Grady <[EMAIL PROTECTED]> wrote:
>
> This is not a backend issue at all - the problem is you're assigning a
> string to the DateField, which is not what it needs.





You are completely correct. I saw the error message, saw it was
similar to a problem I was triaging recently, and didn't look close
enough at the details.

Apologies to Frank for leading you astray on this one.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-08 Thread Collin Grady

This is not a backend issue at all - the problem is you're assigning a
string to the DateField, which is not what it needs.

DateField/TimeField/DateTimeField need the python objects for them,
not strings.

They convert it to a string internally before save, so that the
database gets the right value, but by keeping it the python objects
outside of that, you don't have to do a lot of string processing if
you need to change a date :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-07 Thread Russell Keith-Magee

On 8/6/07, justquick <[EMAIL PROTECTED]> wrote:
>
> AttributeError: 'str' object has no attribute '_meta'

This problem is unrelated to Image or FileFields - the problem is your
ForeignKey.

String-form foreign key references only work with models defined in
the same application. If you want to reference the User model, you
will need to add

from django.contrib.auth.models import User

to the top of your file, and change your ForeignKey reference to:

 owner = ForeignKey(User)

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-06 Thread justquick

I have recently been working on a model and found this problem:

class Image(Model):
name = CharField(maxlength=255)
owner = ForeignKey('user')
file = ImageField(upload_to='Image/%Y-%m/', blank=True, null=True)
description = TextField()
datetime = DateTimeField(auto_now_add=True)

class Admin:
search_fields = ('description','name')
list_filter = ('datetime',)

def __str__(self): return self.name

Add the app to my installed apps list and then any attempt to run
manage.py results in:

Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management.py",
line 1725, in execute_manager
execute_from_command_line(action_mapping, argv)
  File "/usr/lib/python2.5/site-packages/django/core/management.py",
line 1616, in execute_from_command_line
action_mapping[action](int(options.verbosity),
options.interactive)
  File "/usr/lib/python2.5/site-packages/django/core/management.py",
line 510, in syncdb
_check_for_validation_errors()
  File "/usr/lib/python2.5/site-packages/django/core/management.py",
line 1195, in _check_for_validation_errors
num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.5/site-packages/django/core/management.py",
line 1046, in get_validation_errors
for r in rel_opts.get_all_related_objects():
  File "/usr/lib/python2.5/site-packages/django/db/models/options.py",
line 146, in get_all_related_objects
if f.rel and self == f.rel.to._meta:
AttributeError: 'str' object has no attribute '_meta'


Seems to be only a problem with ImageField, FileField still works

Fedora Core 7
Django  (0, 97, 'pre') (SVN)
Python 2.5
MySql 5.0.37



On Aug 5, 8:27 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 8/4/07, Frank Singleton <[EMAIL PROTECTED]> wrote:
>
>
>
> > AttributeError: 'str' object has no attribute 'strftime'
>
> Hi Frank,
>
> You're the second person in recent history to report this problem -
> however, I've been unable to replicate it. The last user was on
> Windows, and I had mentally put it down as a configuration issue; the
> fact that you're seeing it on Linux suggests that it might be a larger
> problem.
>
> The short version: The database backend (sqlite/pysqlite) should be
> returning datetime objects for records containing date fields, but for
> some reason, it seems to be returning strings for some users.
>
> If you can provide a simple test case that exhibits the problem (e.g.,
> minimal model, set of instructions for generating the error, complete
> set of version details for OS, database, etc), I'll have another look
> and see what I can see.
>
> Yours,
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-05 Thread Russell Keith-Magee

On 8/4/07, Frank Singleton <[EMAIL PROTECTED]> wrote:
>
> AttributeError: 'str' object has no attribute 'strftime'

Hi Frank,

You're the second person in recent history to report this problem -
however, I've been unable to replicate it. The last user was on
Windows, and I had mentally put it down as a configuration issue; the
fact that you're seeing it on Linux suggests that it might be a larger
problem.

The short version: The database backend (sqlite/pysqlite) should be
returning datetime objects for records containing date fields, but for
some reason, it seems to be returning strings for some users.

If you can provide a simple test case that exhibits the problem (e.g.,
minimal model, set of instructions for generating the error, complete
set of version details for OS, database, etc), I'll have another look
and see what I can see.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



DateField() , AttributeError: 'str' object has no attribute 'strftime'

2007-08-04 Thread Frank Singleton

Hi,

fedora 7
django 0.96
DATABASE_ENGINE = 'sqlite3'

maybe its late but DateField is causing me some grief when trying to 
load some test data from
the command line (ie: not via admin web).

in model

test_date = models.DateField()


in another python script (run on command line ) that imports the model 
and attempts to populate an sqlite
database with lots of entries (test data from ascii file , including 
date fields in the format -mm-dd)

eg: equivalent to

obj.test_date='2007-12-04'

obj.save()

it complains about

 raceback (most recent call last):
  File "populate_database.py", line 136, in 
tr.save()
  File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 
223, in save
db_values = [f.get_db_prep_save(f.pre_save(self, True)) for f in 
self._meta.fields if not isinstance(f, AutoField)]
  File 
"/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", 
line 494, in get_db_prep_save
value = value.strftime('%Y-%m-%d')
AttributeError: 'str' object has no attribute 'strftime'


SO, thought I would have to do a

time.strptime('2007-02-23', '%Y-%m-%d') thing in between but did not get 
it working.


Suggestions welcome :-)

/F

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Greg

bump

On Jul 31, 2:53 pm, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Ha...sorry I'm such a idiot.
>
> I think I got in now (If not...you might need to help me find it).
>
> My Zip file that I downloaded is labeled sqlite-3_3_15.  Is that what
> you need?
>
> Sorry about this confusion Russ
>
> Thanks
>
> On Jul 31, 9:10 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > pysqlite2.3.3
>
> > That's just the binding. What version of SQLite itself?
>
> > Russ %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Greg

Russ,
Ha...sorry I'm such a idiot.

I think I got in now (If not...you might need to help me find it).

My Zip file that I downloaded is labeled sqlite-3_3_15.  Is that what
you need?

Sorry about this confusion Russ

Thanks

On Jul 31, 9:10 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > pysqlite2.3.3
>
> That's just the binding. What version of SQLite itself?
>
> Russ %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-31 Thread Russell Keith-Magee

On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> pysqlite2.3.3

That's just the binding. What version of SQLite itself?

Russ %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Greg

Russ,
pysqlite2.3.3

On Jul 30, 7:20 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > I guess I have v3.  In my settings.py file i have:
>
> > DATABASE_ENGINE = 'sqlite3'
>
> That's just what your settings file says. This setting could read
> sqlite3 even if you don't have sqlite installed.
>
> Yours
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Russell Keith-Magee

On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> I guess I have v3.  In my settings.py file i have:
>
> DATABASE_ENGINE = 'sqlite3'

That's just what your settings file says. This setting could read
sqlite3 even if you don't have sqlite installed.

Yours
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Greg

Russ,
I guess I have v3.  In my settings.py file i have:

DATABASE_ENGINE = 'sqlite3'

On Jul 30, 6:57 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Russ,
> > I'm using SQLite version - 0.99svn.  And here is my django info
>
> Ermm.. are you sure? Django requires v3 of SQLite, and pysqlite v2
> bindings... I can't even think where you would get a subversion
> release of SQLite 0.99. If you really _do_ have an sqlite that is that
> old, we could have found your problem.
>
> > C:\Python24\Lib\site-packages\django>svn info
> > Revision: 5709
>
> Ok - so its relatively recent. We can rule that out as the issue.
>
> Yours,
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Russell Keith-Magee

On 7/31/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Russ,
> I'm using SQLite version - 0.99svn.  And here is my django info

Ermm.. are you sure? Django requires v3 of SQLite, and pysqlite v2
bindings... I can't even think where you would get a subversion
release of SQLite 0.99. If you really _do_ have an sqlite that is that
old, we could have found your problem.

> C:\Python24\Lib\site-packages\django>svn info
> Revision: 5709

Ok - so its relatively recent. We can rule that out as the issue.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Greg

Russ,
I'm using SQLite version - 0.99svn.  And here is my django info

C:\Python24\Lib\site-packages\django>svn info
Path: .
URL: http://code.djangoproject.com/svn/django/trunk/django
Repository Root: http://code.djangoproject.com/svn
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 5709
Node Kind: directory
Schedule: normal
Last Changed Author: mtredinnick
Last Changed Rev: 5708
Last Changed Date: 2007-07-15 05:10:44 -0500 (Sun, 15 Jul 2007)

Thanks


On Jul 30, 8:43 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Russell,
> > I'm using sqlite
>
> > DATABASE_ENGINE = 'sqlite3'
>
> Hrm. I don't get this problem with sqlite, either; b.timestamp returns
> a datetime object for me.
>
> It is possible this might be a problem specific to sqlite on Windows -
> I don't currently have access to a Windows machine to test this theory
> - but I'm not inclined to believe this, as I'm sure other users would
> have complained.
>
> What version of SQLite and pysqlite are you using?
>
> > I can't seem to find out what django revision I have.  I ran 'svn
> > info' from c:/django however it said 'svn: '.' is not a working copy'
>
> That command will only work if you installed Django using svn, and
> c:\django is the root of your Django checkout (i.e., the directory
> with AUTHORS, INSTALL, LICENSE, MANIFEST.in, README, etc).
>
> How (and where) did you install Django?
>
> Yours,
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Russell,
> I'm using sqlite
>
> DATABASE_ENGINE = 'sqlite3'

Hrm. I don't get this problem with sqlite, either; b.timestamp returns
a datetime object for me.

It is possible this might be a problem specific to sqlite on Windows -
I don't currently have access to a Windows machine to test this theory
- but I'm not inclined to believe this, as I'm sure other users would
have complained.

What version of SQLite and pysqlite are you using?

> I can't seem to find out what django revision I have.  I ran 'svn
> info' from c:/django however it said 'svn: '.' is not a working copy'

That command will only work if you installed Django using svn, and
c:\django is the root of your Django checkout (i.e., the directory
with AUTHORS, INSTALL, LICENSE, MANIFEST.in, README, etc).

How (and where) did you install Django?

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Greg

Russell,
I'm using sqlite

DATABASE_ENGINE = 'sqlite3'

I can't seem to find out what django revision I have.  I ran 'svn
info' from c:/django however it said 'svn: '.' is not a working copy'



On Jul 30, 6:49 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Russ,
> > Here is what I get with I use 'python manage.py shell'
> ...
> > >>> b.timestamp
> > u'2007-07-29'
>
> Ok - this is interesting. This should be a datetime object. This
> suggests a problem with the database backend.
>
> I've just tried what you've sent me using the PostgreSQL backend, and
> I haven't had any difficulties.
>
> To repeat two questions I asked previously, what is:
>
> > > > > - The exact revision of Django you are using
> > > > > - The database backend you are using
>
> Yours,
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-30 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Russ,
> Here is what I get with I use 'python manage.py shell'
...
> >>> b.timestamp
> u'2007-07-29'

Ok - this is interesting. This should be a datetime object. This
suggests a problem with the database backend.

I've just tried what you've sent me using the PostgreSQL backend, and
I haven't had any difficulties.

To repeat two questions I asked previously, what is:

> > > > - The exact revision of Django you are using
> > > > - The database backend you are using

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is what I get with I use 'python manage.py shell'

>>> b = Orders.objects.get(pk=1)
>>> b.s_name
u'Bob Smith''
>>> b.timestamp
u'2007-07-29'
>>>

No errors when I access the timestamp property from within the python
shell.

On Jul 30, 12:00 am, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my Orders Class:
>
> class Orders(models.Model):
> timestamp = models.DateField()
> b_name = models.CharField("Billing Name", maxlength=100)
> b_address = models.CharField("Billing Address", maxlength=100)
> b_city = models.CharField("Billing City", maxlength=100)
> b_state = models.USStateField("Billing State")
> b_zip = models.CharField("Billing Zip", maxlength=100)
> b_phone = models.CharField("Billing Phone", maxlength=100)
> b_email = models.EmailField("Billing Email")
> s_name = models.CharField("Name", maxlength=100)
> s_address = models.CharField("Shipping Address", maxlength=100)
> s_city = models.CharField("Shipping City", maxlength=100)
> s_state = models.USStateField("Shipping State")
> s_zip = models.CharField("Shipping Zip", maxlength=100)
> s_phone = models.CharField("Shipping Phone", maxlength=100)
> s_email = models.EmailField("Shipping Email")
> amount = models.CharField("Order Amount", maxlength=100)
> card_number = models.CharField("Card Number", maxlength=100)
> exp_date = models.CharField("Exp. Date", maxlength=100)
> card_code = models.CharField("Card Code", maxlength=100)
> order_status = models.ForeignKey(OrderStatus)
> voided = models.BooleanField("Has order been voided?")
> email = models.BooleanField("Has an email been sent")
> order = models.TextField("Details of Order", maxlength=1000)
> comments = models.TextField("none", maxlength=1000)
>
> class Admin:
> list_display = ('s_name', 'order_status')
>
> def __str__(self,):
> return self.s_name
>
> On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > Russ,
> > Here is my traceback:
>
> > Traceback (most recent call last):
> > File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   77. response = callback(request, *callback_args, **callback_kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \decorators.py" in _checklogin
> >   55. return view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   39. response = view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \main.py" in change_stage
> >   370. new_data = manipulator.flatten_data()
> > File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> > in flatten_data
> >   250. new_data.update(f.flatten_data(fol, obj))
> > File "c:\Python24\lib\site-packages\django\db\models\fields
> > \__init__.py" in flatten_data
> >   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> > %d") or '')}
>
> >   AttributeError at /admin/rugs/orders/1/
> >   'unicode' object has no attribute 'strftime'
>
> > On Jul 29, 11:34 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> > wrote:
>
> > > On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > Russ,
> > > > I tried including the code that you recommended.  However, I'm still
> > > > getting the same error:
>
> > > > AttributeError at /admin/rugs/orders/1/
> > > > 'unicode' object has no attribute 'strftime'
>
> > > Just to clarify - If you create, modify and save an object at the
> > > command prompt, it works fine. You can retrieve the object using the
> > > command line using calls to filter, etc, and print out objects
> > > retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
> > > view the object in the admin pages you get an error. Is this correct?
>
> > > If this is the case, it is possible that you have encountered some
> > > sort of bug with the admin views dealing with date fields; to help
> > > track this down, could you provide:
>
> > > - A full stack trace of the error you are seeing
> > > - The exact revision of Django you are using
> > > - The code for the Order model
> > > - The database backend you are using
>
> > > Thanks,
> > > Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is my view:

def success(request):
f = processpay(request)
if f == 'True':
pr = theamount(request)
o = Orders()
o.timestamp = datetime.now()
o.s_name = 'Bob Smith'
o.s_address = '18sdf est 15'
o.s_city = 'New York'
o.s_state = 'NY'
o.s_zip = '44801'
o.s_phone = '123-123-1321'
o.s_email = '[EMAIL PROTECTED]'
o.b_name = 'Bob'
o.b_address = 'asdf'
o.b_city = 'adsf'
o.b_state = 'NY'
o.b_zip = '1'
o.b_phone = '123-132-1231'
o.b_email = '[EMAIL PROTECTED]'
o.amount = '200'
o.card_number = '123123123123'
o.exp_date = '0909'
o.card_code = '509'
o.order_status_id = '1'
o.voided = 'False'
o.email = 'False'
o.order = 'Order Info'
o.comments = 'Comment Info'
o.save()
odet = request.session['orderdetails']
c = request.session['cart']
p = request.session['pad']
del request.session['orderdetails']
del request.session['cart']
del request.session['pad']
request.session.modified = True
return render_to_response('result.html', {'s': odet, 'r': c, 
'spad':
p, 'p': pr})
else:
return render_to_response('result.html', {'s': 'Did not work'})

On Jul 30, 12:00 am, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my Orders Class:
>
> class Orders(models.Model):
> timestamp = models.DateField()
> b_name = models.CharField("Billing Name", maxlength=100)
> b_address = models.CharField("Billing Address", maxlength=100)
> b_city = models.CharField("Billing City", maxlength=100)
> b_state = models.USStateField("Billing State")
> b_zip = models.CharField("Billing Zip", maxlength=100)
> b_phone = models.CharField("Billing Phone", maxlength=100)
> b_email = models.EmailField("Billing Email")
> s_name = models.CharField("Name", maxlength=100)
> s_address = models.CharField("Shipping Address", maxlength=100)
> s_city = models.CharField("Shipping City", maxlength=100)
> s_state = models.USStateField("Shipping State")
> s_zip = models.CharField("Shipping Zip", maxlength=100)
> s_phone = models.CharField("Shipping Phone", maxlength=100)
> s_email = models.EmailField("Shipping Email")
> amount = models.CharField("Order Amount", maxlength=100)
> card_number = models.CharField("Card Number", maxlength=100)
> exp_date = models.CharField("Exp. Date", maxlength=100)
> card_code = models.CharField("Card Code", maxlength=100)
> order_status = models.ForeignKey(OrderStatus)
> voided = models.BooleanField("Has order been voided?")
> email = models.BooleanField("Has an email been sent")
> order = models.TextField("Details of Order", maxlength=1000)
> comments = models.TextField("none", maxlength=1000)
>
> class Admin:
> list_display = ('s_name', 'order_status')
>
> def __str__(self,):
> return self.s_name
>
> On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > Russ,
> > Here is my traceback:
>
> > Traceback (most recent call last):
> > File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   77. response = callback(request, *callback_args, **callback_kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \decorators.py" in _checklogin
> >   55. return view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   39. response = view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \main.py" in change_stage
> >   370. new_data = manipulator.flatten_data()
> > File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> > in flatten_data
> >   250. new_data.update(f.flatten_data(fol, obj))
> > File "c:\Python24\lib\site-packages\django\db\models\fields
> > \__init__.py" in flatten_data
> >   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> > %d") or '')}
>
> > 

Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is my Orders Class:

class Orders(models.Model):
timestamp = models.DateField()
b_name = models.CharField("Billing Name", maxlength=100)
b_address = models.CharField("Billing Address", maxlength=100)
b_city = models.CharField("Billing City", maxlength=100)
b_state = models.USStateField("Billing State")
b_zip = models.CharField("Billing Zip", maxlength=100)
b_phone = models.CharField("Billing Phone", maxlength=100)
b_email = models.EmailField("Billing Email")
s_name = models.CharField("Name", maxlength=100)
s_address = models.CharField("Shipping Address", maxlength=100)
s_city = models.CharField("Shipping City", maxlength=100)
s_state = models.USStateField("Shipping State")
s_zip = models.CharField("Shipping Zip", maxlength=100)
s_phone = models.CharField("Shipping Phone", maxlength=100)
s_email = models.EmailField("Shipping Email")
amount = models.CharField("Order Amount", maxlength=100)
card_number = models.CharField("Card Number", maxlength=100)
exp_date = models.CharField("Exp. Date", maxlength=100)
card_code = models.CharField("Card Code", maxlength=100)
order_status = models.ForeignKey(OrderStatus)
voided = models.BooleanField("Has order been voided?")
email = models.BooleanField("Has an email been sent")
order = models.TextField("Details of Order", maxlength=1000)
comments = models.TextField("none", maxlength=1000)

class Admin:
list_display = ('s_name', 'order_status')

def __str__(self,):
return self.s_name

On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my traceback:
>
> Traceback (most recent call last):
> File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> get_response
>   77. response = callback(request, *callback_args, **callback_kwargs)
> File "c:\Python24\lib\site-packages\django\contrib\admin\views
> \decorators.py" in _checklogin
>   55. return view_func(request, *args, **kwargs)
> File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> in _wrapped_view_func
>   39. response = view_func(request, *args, **kwargs)
> File "c:\Python24\lib\site-packages\django\contrib\admin\views
> \main.py" in change_stage
>   370. new_data = manipulator.flatten_data()
> File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> in flatten_data
>   250. new_data.update(f.flatten_data(fol, obj))
> File "c:\Python24\lib\site-packages\django\db\models\fields
> \__init__.py" in flatten_data
>   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> %d") or '')}
>
>   AttributeError at /admin/rugs/orders/1/
>   'unicode' object has no attribute 'strftime'
>
> On Jul 29, 11:34 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Russ,
> > > I tried including the code that you recommended.  However, I'm still
> > > getting the same error:
>
> > > AttributeError at /admin/rugs/orders/1/
> > > 'unicode' object has no attribute 'strftime'
>
> > Just to clarify - If you create, modify and save an object at the
> > command prompt, it works fine. You can retrieve the object using the
> > command line using calls to filter, etc, and print out objects
> > retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
> > view the object in the admin pages you get an error. Is this correct?
>
> > If this is the case, it is possible that you have encountered some
> > sort of bug with the admin views dealing with date fields; to help
> > track this down, could you provide:
>
> > - A full stack trace of the error you are seeing
> > - The exact revision of Django you are using
> > - The code for the Order model
> > - The database backend you are using
>
> > Thanks,
> > Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Russ,
> I tried including the code that you recommended.  However, I'm still
> getting the same error:
>
> AttributeError at /admin/rugs/orders/1/
> 'unicode' object has no attribute 'strftime'

Just to clarify - If you create, modify and save an object at the
command prompt, it works fine. You can retrieve the object using the
command line using calls to filter, etc, and print out objects
retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
view the object in the admin pages you get an error. Is this correct?

If this is the case, it is possible that you have encountered some
sort of bug with the admin views dealing with date fields; to help
track this down, could you provide:

- A full stack trace of the error you are seeing
- The exact revision of Django you are using
- The code for the Order model
- The database backend you are using

Thanks,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
I tried including the code that you recommended.  However, I'm still
getting the same error:

AttributeError at /admin/rugs/orders/1/
'unicode' object has no attribute 'strftime'

///

I updated my view to include the following lines:

from datetime import datetime
...
o.timestamp = datetime.now()



When I drill down on the order from within my admin I still get the
error listed above.

Thanks

On Jul 29, 7:45 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Ok,
> > I just added a Field in my Orders class.  It looks like this:
> ...
> > Do I need to put something into my timestamp field when I create the
> > Orders instance?  For example:
>
> Yes; your field is a required field, so you will need to provide
> timestamp data. DateFields store their data in datatime format; so you
> will need to do something like:
>
> >>> from datetime import datetime
> >>> o.timestamp = datetime(2007,7,30)
>
> To assist with form handling, Django also allows string inputs to date fields:
>
> >>> o.timestamp = "2007-07-30"
> > I would like to be able to create the current date when I' working
> > with the Orders instance (o.timestamp)
>
> For this one, try:
>
> >>> o.timestamp = datetime.now()
>
> Yours,
> Russ Magee %-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Ok,
> I just added a Field in my Orders class.  It looks like this:
...
> Do I need to put something into my timestamp field when I create the
> Orders instance?  For example:

Yes; your field is a required field, so you will need to provide
timestamp data. DateFields store their data in datatime format; so you
will need to do something like:

>>> from datetime import datetime
>>> o.timestamp = datetime(2007,7,30)

To assist with form handling, Django also allows string inputs to date fields:

>>> o.timestamp = "2007-07-30"

> I would like to be able to create the current date when I' working
> with the Orders instance (o.timestamp)

For this one, try:

>>> o.timestamp = datetime.now()

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Ok,
I just added a Field in my Orders class.  It looks like this:

timestamp = models.DateField("Creation Date")

//

I create a new instance of the order class below:

o = Orders()
o.s_name = 'Greg Smith'
o.s_address = '123 West Main'
o.s_city = 'city'
... (And so on)
o.save()

Do I need to put something into my timestamp field when I create the
Orders instance?  For example:

o = Orders()
o.timestamp = ?? # Not sure what goes here
o.s_name = 'Bob'
o.s_address = '123 West Main'
o.s_city = 'city'
... (And so on)
o.save()

//

Currently, when I save the Orders instance it writes it to the db.  I
can view the record in my admin.  I can open the record and select
'Today' for my timestamp field and click save.  However, I get the
error ''unicode' object has no attribute 'strftime'' When I try to
open the record after I added the timestamp.

I would like to be able to create the current date when I' working
with the Orders instance (o.timestamp)

Any help would be appreciated.

Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileField: id of row (like strftime)

2007-05-29 Thread Thomas Guettler

Am Freitag, 25. Mai 2007 10:51 schrieb Thomas Güttler:
> Hi,
>
> the upload_to argument to FileField evals strftime formatting.
>
> I would like to have the ID of the belonging row.
>
> Example: One MyObject has N attachments.
>
> class Attachment(models.Model):
> file=models.FileField(upload_to="%(myobject_id)s")
> myobject=models.ForeignKey(MyObject)
>
>
> This way all attachments of one MyObjects are in the same directory.

Here is how I solved this:

MyObject instances have N attachments:

The files should be in myobjects/MYOBJECTID/...

class MyAttachmentField(models.FileField):
def get_directory_name(self):
return os.path.normpath(os.path.join(self.upload_to, 
str(self.myobject_id)))

def save_file(self, *args, **kwargs):
new_data=args[0]
self.myobject_id=new_data["myobject_id"]
return models.FileField.save_file(self, *args, **kwargs)

class MyAttachment(models.Model):
def __str__(self):
return '<%s %s %s>' % (
self.__class__.__name__, self.myobject.id, self.file)

file=MyAttachmentFileField(upload_to="myobjects")
myobject=models.ForeignKey(MyObject, edit_inline=models.STACKED)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



FileField: id of row (like strftime)

2007-05-25 Thread Thomas Güttler

Hi,

the upload_to argument to FileField evals strftime formatting.

I would like to have the ID of the belonging row.

Example: One MyObject has N attachments.

class Attachment(models.Model):
file=models.FileField(upload_to="%(myobject_id)s")
myobject=models.ForeignKey(MyObject)


This way all attachments of one MyObjects are in the same directory.

This would be very nice.

 Thomas

-- 
Thomas Güttler, http://www.tbz-pariv.de/ 
Bernsdorfer Str. 210-212, 09126 Chemnitz, Tel.: 0371/5347-917
TBZ-PARIV GmbH  Geschäftsführer: Dr. Reiner Wohlgemuth
Sitz der Gesellschaft: Chemnitz Registergericht: Chemnitz HRB 8543

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField returns 'str' object has no attribute 'strftime'

2007-04-30 Thread Phil Davis

On 30/04/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
[...]
> Same problem:
>   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_date=form.clean_data['conference_date'],

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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField returns 'str' object has no attribute 'strftime'

2007-04-30 Thread [EMAIL PROTECTED]

Same problem:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/core/handlers/base.py" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/dahl/Code/telecom/confmngr/views.py" in detail
  205. conf.save()
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/base.py" in save
  217. db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f
in non_pks]
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/fields/__init__.py" in get_db_prep_save
  494. value = value.strftime('%Y-%m-%d')

  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, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Would you mind posting your code snippet here. I have the same issue.
> I thought the widget dealt with the creation of the datetime.date obj?
>
> best regards,
>
> David
>
> On Apr 20, 4:56 am, Henrik Lied <[EMAIL PROTECTED]> wrote:
>
> > Hi 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!
>
> > On 20 Apr, 11:44, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> > > On Fri, 2007-04-20 at 09:09 +, Henrik Lied wrote:
> > > > Hi there,
>
> > > > I'm creating a user registration system for a project.
> > > > The system uses the SelectDateWidget for user input of birthdate.
>
> > > > When I try to regist

Re: DateField returns 'str' object has no attribute 'strftime'

2007-04-30 Thread [EMAIL PROTECTED]

Would you mind posting your code snippet here. I have the same issue.
I thought the widget dealt with the creation of the datetime.date obj?

best regards,

David

On Apr 20, 4:56 am, Henrik Lied <[EMAIL PROTECTED]> wrote:
> Hi 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!
>
> On 20 Apr, 11:44, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> > On Fri, 2007-04-20 at 09:09 +, Henrik Lied wrote:
> > > Hi there,
>
> > > 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
>
> > 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


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField returns 'str' object has no attribute 'strftime'

2007-04-20 Thread Henrik Lied

Hi 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!

On 20 Apr, 11:44, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-04-20 at 09:09 +, Henrik Lied wrote:
> > Hi there,
>
> > 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
>
> 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


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateField returns 'str' object has no attribute 'strftime'

2007-04-20 Thread Malcolm Tredinnick

On Fri, 2007-04-20 at 09:09 +, Henrik Lied wrote:
> Hi there,
> 
> 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

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



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



DateField returns 'str' object has no attribute 'strftime'

2007-04-20 Thread Henrik Lied

Hi there,

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?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-16 Thread Waylan Limberg

On 5/16/06, Jay Parlar <[EMAIL PROTECTED]> wrote:
>
> On 5/16/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
> >
> > Jay Parlar wrote:
> >
> > >Hmm... So let me get this straight... When someone does an upload via
> > >my form, Django *temporarily* stores it in my uploads directory, with
> > >the "_" at the end of the filename, right?
> > >
> > No. It tries to save the file with the given name and appends '_' only
> > when there are already files with this filename. It's not temporary.
> >

Um, shouldn't it rename the old file (appending the '_') and then save
the new file with the filename (less the '_')? Or is that what you
meant to say?

>
> Alright, let me see if I understand it this time: If you upload a file
> that's already been uploaded, then Django will lose the association to
> the old one, and it will essentially be sitting orphaned on the disk?
>
> For my use case, I actually want to keep every version of every file
> ever uploaded to the server.
>

If it works the way I suggest above, then one could conceivably append
a date/timestamp rather than an underscore, preserving all previous
versions of a file. I haven't checked if it's currently available, but
a setting to set what should be appended would be nice. Then one could
write some simple python code that scans the upload dir and lists all
versions of the files.

-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-16 Thread Ivan Sagalaev

Jay Parlar wrote:

>Alright, let me see if I understand it this time: If you upload a file
>that's already been uploaded, then Django will lose the association to
>the old one, and it will essentially be sitting orphaned on the disk?
>  
>
Exactly.

>For my use case, I actually want to keep every version of every file
>ever uploaded to the server.
>  
>
Lucky you :-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-16 Thread Jay Parlar

On 5/16/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> Jay Parlar wrote:
>
> >Hmm... So let me get this straight... When someone does an upload via
> >my form, Django *temporarily* stores it in my uploads directory, with
> >the "_" at the end of the filename, right?
> >
> No. It tries to save the file with the given name and appends '_' only
> when there are already files with this filename. It's not temporary.
>

Alright, let me see if I understand it this time: If you upload a file
that's already been uploaded, then Django will lose the association to
the old one, and it will essentially be sitting orphaned on the disk?

For my use case, I actually want to keep every version of every file
ever uploaded to the server.

Jay P.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-15 Thread Ivan Sagalaev

Jay Parlar wrote:

>Hmm... So let me get this straight... When someone does an upload via
>my form, Django *temporarily* stores it in my uploads directory, with
>the "_" at the end of the filename, right?
>
No. It tries to save the file with the given name and appends '_' only 
when there are already files with this filename. It's not temporary.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-15 Thread Jay Parlar

On 5/15/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> Jay Parlar wrote:
>
> >I'm still curious though if doing the
> >new_data.update(request.FILES.copy()) is the best way to do that part
> >of it.
> >
> >
> Only if you don't care of lost files in your upload :-). Here's the code
> that I use in my project to handle this. The function receives list of
> file fields excludes them from saving by manipulator and handles deletes
> and overrides manually. It assumes that file should be deleted if its
> associated field in POST is empty.
>
> def process_file_post(manipulator,request,field_names):
>   data=request.POST.copy()
>   # file data is not included in data for manipulator.save because
>   # Django can't handle file deletes and overrides
>   validation_data=data.copy()
>   validation_data.update(request.FILES.copy())
>   errors=manipulator.get_validation_errors(validation_data)
>   manipulator.do_html2python(data)
>   if errors:
> raise EManipulatorErrors, (errors,data)
>   for field_name in field_names:
> old_filename=getattr(manipulator.original_object,field_name) and
> getattr(manipulator.original_object,'get_%s_filename'%field_name)()
> obj=manipulator.save(data)
> file_field=request.FILES.get('%s_file'%field_name,'')
> if (not data[field_name] or file_field) and old_filename:
>   os.remove(old_filename)
> if file_field:
>
> getattr(obj,'save_%s_file'%field_name)(file_field['filename'],file_field['content'])
>   return obj
>
>

Hmm... So let me get this straight... When someone does an upload via
my form, Django *temporarily* stores it in my uploads directory, with
the "_" at the end of the filename, right? And then when we do the
save(), it saves it again in uploads/, but this time with the proper
filename?

Jay P.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-15 Thread Ivan Sagalaev

Jay Parlar wrote:

>I'm still curious though if doing the
>new_data.update(request.FILES.copy()) is the best way to do that part
>of it.
>  
>
Only if you don't care of lost files in your upload :-). Here's the code 
that I use in my project to handle this. The function receives list of 
file fields excludes them from saving by manipulator and handles deletes 
and overrides manually. It assumes that file should be deleted if its 
associated field in POST is empty.

def process_file_post(manipulator,request,field_names):
  data=request.POST.copy()
  # file data is not included in data for manipulator.save because
  # Django can't handle file deletes and overrides
  validation_data=data.copy()
  validation_data.update(request.FILES.copy())
  errors=manipulator.get_validation_errors(validation_data)
  manipulator.do_html2python(data)
  if errors:
raise EManipulatorErrors, (errors,data)
  for field_name in field_names:
old_filename=getattr(manipulator.original_object,field_name) and 
getattr(manipulator.original_object,'get_%s_filename'%field_name)()
obj=manipulator.save(data)
file_field=request.FILES.get('%s_file'%field_name,'')
if (not data[field_name] or file_field) and old_filename:
  os.remove(old_filename)
if file_field:
  
getattr(obj,'save_%s_file'%field_name)(file_field['filename'],file_field['content'])
  return obj


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-15 Thread Ivan Sagalaev

Jay Parlar wrote:

>Ahh, very cool.  How should I build the new_data object though? Is
>this the *right* way?
>
>new_data = request.POST.copy()
>new_data.update(request.FILES.copy())
>  
>
Well... In general it's a bit tricky. Doing it like this and feeding 
this new_data to manipulator will validate and save everything including 
uploaded files. But since Django doesn't automatically remove associated 
files on update you'll get lost files sitting forever in your upload dir 
whenever you upload new file. This should be resolved manually depending 
on what your app is supposed to do in this case.

>I tried doing it this way, but now the 'creation_time' field in my
>model is causing a problem. ie., my model is actually:
>
>class FirmwareUpload(models.Model):
>   firmware = models.FileField(upload_to="uploads/%A-%B-%Y")
>   creation_time = models.DateTimeField(auto_now_add=True)
>   class Admin: ...
>
>
>When I try to upload the file, the new 'obj =
>manipulator.save(new_data)' is causing the following error:
>
>OperationalError at /firmware/
>firmware_firmwareupload.creation_time may not be NULL
>
>
>Shouldn't the AddManipulator have prepopulated that field, because of
>the 'auto_now_add=True'? I wasn't seeing that error before the change.
>  
>
No, auto_now_add is supposed to be filled when object is first saved. 
However due to a bug (http://code.djangoproject.com/ticket/555) 
auto_now_add fields are saved successfully but not populated with the 
new time after save. This causes your bug because manipulator actualy 
saves the object twice: first time for the object itself and second time 
doing save_*_file which calls object's save(). Ad this second save() 
tries to update auto_now_add field with empty value that still lives in it.

To work this around you can write override object's save() and select 
new saved time explicitely into the field as described in first comment 
in the ticket.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing a field's upload_to strftime

2006-05-15 Thread Jay Parlar

On 5/15/06, Jay Parlar <[EMAIL PROTECTED]> wrote:
> On 5/15/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> > Instead of saving your file manually use Django's helper method:
> >
> > obj = manipulator.save(new_data)
> > info = request.FILES['firmware_file']
> > obj.save_firmware_file_file(info['filename'], info['content'])
> >
> > This not only fills date values but also resolves filename conflicts.
> > http://www.djangoproject.com/documentation/db_api/#save-foo-file-filename-raw-contents
> >
> > The actual filename may change during this save_*_file so to get real
> > (and full) filename you use obj.get_firmware_file_filename().
> >
>
> Ahh, very cool.  How should I build the new_data object though? Is
> this the *right* way?
>
> new_data = request.POST.copy()
> new_data.update(request.FILES.copy())
>
> I tried doing it this way, but now the 'creation_time' field in my
> model is causing a problem. ie., my model is actually:
>
> class FirmwareUpload(models.Model):
>firmware = models.FileField(upload_to="uploads/%A-%B-%Y")
>creation_time = models.DateTimeField(auto_now_add=True)
>class Admin: ...
>
>
> When I try to upload the file, the new 'obj =
> manipulator.save(new_data)' is causing the following error:
>
> OperationalError at /firmware/
> firmware_firmwareupload.creation_time may not be NULL
>
>
> Shouldn't the AddManipulator have prepopulated that field, because of
> the 'auto_now_add=True'? I wasn't seeing that error before the change.
>


I got the creation_time issue worked out, by changing the model to
'auto_now=True'.

I'm still curious though if doing the
new_data.update(request.FILES.copy()) is the best way to do that part
of it.

Jay P.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Using strftime() in datetime fields

2005-11-11 Thread Eric Walstad

On Friday 11 November 2005 17:46, Pedro Furtado wrote:
> > Turn it into a date, datetime or time object first, then format
> > it. Like the traceback says, strings don't have strftime
> > attributes/methods.
>
> But it already is a datetime object.

Not according to the traceback you posted.
-E


Re: Using strftime() in datetime fields

2005-11-11 Thread Pedro Furtado

> Turn it into a date, datetime or time object first, then format it.
> Like the traceback says, strings don't have strftime
> attributes/methods.

But it already is a datetime object. The "object" I stated is an
object of a model class, which contains a datetimefield. Am I clear
now?

The code runs smoothly in Python prompt but not in views.

Pedro

--
Pedro Furtado
Juiz de Fora - MG