0

I have made a Django project and designed a model with a field name in it what I write is :

name = models.CharField(max_length = 250)

Is there a way to print CharField on the screen, using command like

d = name.field() 

and it stores a String in variable d as CharField. If I ask it as attendance.field, I want it to show BooleanField as output. Like :

from django.db import models as data_type
class UserAttendance(data_type.Model):
    user=data_type.ForeignKey(UserList,on_delete=data_type.CASCADE)
    date=data_type.DateField()
    attendance=data_type.BooleanField(default=False)

I searched but did not found anything that allowed to print CharField on screen. Can anyone suggest me how to do this ?

3
  • I just want it to return DataField or BooleanField for date and attendance respectively Commented May 7, 2019 at 5:36
  • 1
    Possible duplicate of how to get field type string from db model in django Commented May 7, 2019 at 5:43
  • Format txt in proper manner and also highlighted important words to get easily what answer is needed. Commented May 7, 2019 at 6:35

1 Answer 1

0

You can use get_internal_type() as suggested in the comment by @ruddra sir

UserAttendance._meta.get_field('attendance').get_internal_type()
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.