Django model to admin, integer fields and textfield are not visible in admin section


Django model to admin, integer fields and textfield are not visible in admin section


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





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



age = models.SmallIntegerField()


()




1 Answer
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()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined

Opening a url is failing in Swift