Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i get models field type from a model queryset in Django?

Can i get model field type from a model queryset in Django?

For example: a is b model's queryset and the b model has following fields:

  • f:charfield
  • g:foreignkey
  • h:manytomany

Is there any way to get field g's type from queryset a? thx.

like image 665
victor Avatar asked Sep 11 '10 16:09

victor


People also ask

What is the type of QuerySet in Django?

A QuerySet is a collection of data from a database. A QuerySet is built up as a list of objects. QuerySets makes it easier to get the data you actually need, by allowing you to filter and order the data.

What does field type signifies in Django models?

Fields in Django are the data types to store a particular type of data. For example, to store an integer, IntegerField would be used. These fields have in-built validation for a particular data type, that is you can not store “abc” in an IntegerField. Similarly, for other fields.


1 Answers

I have the answer:

a.model._meta.get_field('g').get_internal_type()
like image 183
victor Avatar answered Oct 19 '22 20:10

victor