On Thu, 2008-03-06 at 14:05 -0800, DuncanM wrote:
> I want to create a model that doesn't ask for the users input on the
> date, it takes the days date automatically,
>
> I thought it would be as simple as doing:
>
> class News(models.Model):
> newsTitle = models.CharField("News Title", maxlength=200, core=True,
> help_text="Title of the news item e.g. website launch")
> date = datetime.date.today()
> author = models.CharField(maxlength=200)
>
>
> But apparently not as this does not work.
It works perfectly. It just doesn't work as you expected. There's a
difference.:-)
If you are wanting this to be a model field (something that is saved to
the database), create a normal date field and use the default attribute
to set its value. The "default" can be a callable, so
datetime.date.today will work.
> Could anyone help please?
>
> Also I would ideally like the author to be autopopulated by whoever
> posts the item using the admin interface. How would I do this?
Models don't know anything about views and the request/response path
(intentionally). However, if you search for threadlocals in conjunction
with Django, you'll find a solution on the wiki to put the "current
user" into threadlocals, where you can access it from your model's
save() method.
Malcolm
--
A conclusion is the place where you got tired of thinking.
http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---