Reputation: 127
For some reason I don't get this rather simple operation work. I'm trying to save model instance to database (sqllite), but the saving fails with no error message (just showing 500, internal server error). I have made my database with migrations (make migrations, migrate) and it should be up to date. So here is my view code:
post = Post(pub_date = datetime.datetime.now, image_url = " some url", price = 0, item_id=1, description="some text", url=link)
post.save()
And here is are the models:
class Post(models.Model):
pub_date = models.DateTimeField('date published')
image_url = models.CharField(max_length=500)
price = models.IntegerField()
item = models.ForeignKey(Item, related_name='posts')
description = models.CharField(max_length=300)
url = models.CharField(max_length=500)
class Item(models.Model):
name = models.CharField(max_length=150)
pub_date = models.DateTimeField('date published')
description = models.CharField(max_length=300)
image_url = models.CharField(max_length=500, default="#")
categories = models.ManyToManyField(Category)
Upvotes: 0
Views: 319
Reputation: 20015
Use:
datetime.datetime.now()
datetime.datetime.now
alone is a function and so you are trying to assign to pub_date
a function, instead of function's value.
Upvotes: 3