Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:52:01+00:00 2026-06-09T20:52:01+00:00

Model: class Comment(models.Model): date = models.DateTimeField(default = datetime.datetime.now) text = models.TextField() Form: class CommentForm(forms.ModelForm):

  • 0

Model:

class Comment(models.Model):
    date = models.DateTimeField(default = datetime.datetime.now)
    text = models.TextField()

Form:

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment

In template I have only “text” field. When I click on submit button, QueryDict in form.data contains only text, despite the default value for date field. How to set default value properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:52:03+00:00Added an answer on June 9, 2026 at 8:52 pm

    Update:

    I figured that default=datetime.date.now behaved like auto_now_add=True because you mentioned that your template only contains the text field.

    It turns out your situation is not handled any differently and you must display the date field in your form.

    If you want to ignore it, you can override the ModelForm.save method to set the date yourself, or add it in your model save() definition.

    You should look into the auto_now_add=True parameter in model field definitions which automatically adds this behavior of setting a date field to datetime.datetime.now() upon the first save.

    date = models.DateTimeField(auto_now_add=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model like class Document(models.Model): comment = models.TextField(null=True,blank=True) upload_date = models.DateTimeField(blank=False) Document
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def
Model: class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() def __unicode__(self):
I'm working on my Django threaded comments.My model is: class Comment(models.Model): name = models.CharField(max_length=100)
I have two models. Comment and his Subcomments: class Comment(models.Model): .... author = models.CharField(max_length=80)
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I'm trying to add comments to a Post model class Comment < ActiveRecord::Base belongs_to
I am using Rails 3.2. I have following models: Blog Comment User class Blog
class Followup < ActiveRecord::Base belongs_to :post belongs_to :comment end This model needs to only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.