LoginSignup
4
4

More than 5 years have passed since last update.

python忘備録

Posted at

モデルのfield名を取得する方法

from django.db import models
class hoge(models.Model):
  hoge_id = models.IntegerField()
  hoge_text = models.CharField()

と定義されているクラスのフィールド名を取得する場合

field_names = [field.name for field in hoge._meta.fields]

これで取って来れる。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4