0

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)

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.