1
class Student(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    father_name = models.CharField(max_length=60)
    age = models.SmallIntegerField
    created = models.DateTimeField(auto_now=False, auto_now_add=True)
    modified = models.DateTimeField(auto_now=True, auto_now_add=False)
    address = models.TextField
    email = models.EmailField(default="")
    id = models.AutoField
    std = models.SmallIntegerField
    remarks = models.TextField

I have created a model called Student and added it to Django admin and migrated it. There was no problem with migration. When I tried to add a new student via admin page, I am only getting following fields, How can I get integer fields like age in UI? enter image description here

1
  • 1
    It should be age = models.SmallIntegerField(). Note () signs. Just add it for all fields and run makemigrations/migrate. Commented Jun 29, 2018 at 11:27

1 Answer 1

1

When you want to create fields in a django model (which are equivalent to columns in table) you need to call the function of that specific field.

Here you are only referring to the specific function and not actually calling them.

Thus the solution:

class Student(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    father_name = models.CharField(max_length=60)
    age = models.SmallIntegerField()
    created = models.DateTimeField(auto_now=False, auto_now_add=True)
    modified = models.DateTimeField(auto_now=True, auto_now_add=False)
    address = models.TextField()
    email = models.EmailField(default="")
    id = models.AutoField()
    std = models.SmallIntegerField()
    remarks = models.TextField()
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.