Home > Software design >  New object not added to queryset in Django
New object not added to queryset in Django

Time:10-20

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

CodePudding user response:

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)
  • Related