New object not added to queryset in Django

Question:

Here is the model

class Student(models.Model):
    """Student info"""
    id = models.CharField( max_length=7,primary_key=True)
    name = models.CharField(_('name'),max_length=8, default=""); # help_text will locate after the field
    address = models.CharField(_('address'),max_length=30,blank=True,default="")    #blank true means the
    GENDER_CHOICES = [("M", _("male")),("F",_("female"))]
    student_number = models.CharField(max_length=10,blank=True)
    gender = models.CharField(_("gender"),max_length=6, choices = GENDER_CHOICES, default="M");

I user shell to create two users as below:

msg

But the queryset number didn’t increase although I created two users.
#I hate Django. Q = Q

Asked By: Alston

||

Answers:

You are using a custom id field as model id and you put it as Char, so you should add this id also when you want to save an object

But it is not a good idea, if you want to use custom id use it in this way

id = models.AutoField(primary_key=True)
Answered By: Hashem
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.