9-bits
9-bits

Reputation: 10765

Test for existence of field in django class

Given a django class and a field name how can you test to see whether the class has a field with the given name?

The field name is a string in this case.

Upvotes: 0

Views: 71

Answers (1)

Dima Bildin
Dima Bildin

Reputation: 1553

For example:

field_name_exists = field_name in ModelName._meta.get_all_field_names()

Upvotes: 1

Related Questions