Skip to content Skip to sidebar Skip to footer

My Status Object Is Not Saving In Django

When I enter the shell, I run into the following problem: from users.models import Status from django.utils import timezone Status.objects.all() >>> [] p = Status() p.sta

Solution 1:

I told you before, you need to read the documentation and follow the tutorial. This is not the way to set a default value for a model's field. Please go through the documentation and tutorial at https://docs.djangoproject.com/en/1.5/ If you run into problems during it, come back and ask questions, but if you continue to things incorrectly you are just forming bad habits.


I realize that the original content may seem aggressive, that was not the intent. I just want to prevent you from doing things your way as opposed to the way they are designed to be done and wasting tons of your time in the process (I've done it before). That being said, I will try and demonstrate how the designers of django would most likely have wanted you to set up your model.

class Status(models.Model):
    status = models.CharField(max_length=200, null=True, blank=True)
    time= models.DateTimeField('date published', default=timezone.datetime.min)

As you can see, there is no __init__ used when creating models. You simply give it fields as properties. Each field type has several options to set things like default values, max_length, etc...

Solution 2:

why not simply do:

class Status(models.Model):

status = models.CharField(max_length=200)
status_time = models.DateTimeField(auto_now_add=True)

Which will add a date time object automatically once a Status instance is created. More info here

Post a Comment for "My Status Object Is Not Saving In Django"