python - naming of Django Foreign Keys in order to request correct column -


i'm using django (i'm new it). want define foreign key, , i'm not sure how go it.

i have table called stat_types:

class stattypes(models.model):     stat_type = models.charfield(max_length=20) 

now want define foreign key in overall_stats table stat_type id automatically generated django. following?

    stat_types_id = models.foreignkey('beta.stattypes') 

what if wanted instead have stat_type column of stat_types table foreign key. be:

stat_type = models.foreignkey('beta.stattypes') 

i guess confusion arises in not knowing name column in second model, in order know column of first model use foreign key.

thanks!

it not matter name give fk column name. django figures out foreignkey , appends _id field. not need _id here. think enough

stat_type = models.foreignkey('beta.stattypes') 

doc says:

it’s suggested, not required, name of foreignkey field (manufacturer in example above) name of model, lowercase. can, of course, call field whatever want.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -