Created
September 18, 2012 15:43
-
-
Save majgis/3743833 to your computer and use it in GitHub Desktop.
django snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Compact example to get the name of the primary key field of a Django model. | |
loc_fields = self._model._meta.fields | |
loc_pk = next((f.db_column or f.name for f in loc_fields if f.primary_key)) | |
#Get all related model classes for a model class or instance | |
related_models = [f.rel.to for f in loc_record._meta.fields if f.rel] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment