Kermit
Kermit

Reputation: 6042

Django model name with underscore?

I have subtly different entities that are important enough with respect to the relationships, flexibility, and expression of my schema that they warrant separate models.

How should I name/ case these?

a) Layerinput, Layerhidden, Layeroutput

b) Layer_Input, Layer_Hidden, Layer_Output

c) LayerInput, LayerHidden, LayerOutput

Right now I am leaning option a so that Django doesn't do anything too automagically incorrect with them, but that won't look great in documentation and code. Will use them with either DRF or graphql.

Upvotes: 1

Views: 3499

Answers (4)

PG_185
PG_185

Reputation: 116

CamelCase (option c) is also useful because Django will know how to render your model names in the admin site. For example 'LayerInput' will appear correctly as 'Layer input' without you having to specify it anywhere.

Upvotes: 0

kayuapi_my
kayuapi_my

Reputation: 508

If you're referring to naming Classes, you should choose c) as shown in image below (obtained from https://docs.djangoproject.com/en/2.1/topics/db/models/#verbose-field-names).enter image description here

If you're referring to the field_names (eg. name and age under the class CommonInfo in the figure above), then the convention for django is as followed:

enter image description here

Upvotes: 2

Nautatava Navlakha
Nautatava Navlakha

Reputation: 315

Use camelCase (option c), this helps you differentiate words in a variable while minimising the characters (as in option b)

Use this as a guide: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/

Upvotes: 1

JPG
JPG

Reputation: 88689

According to PEP8 conventions,

Class names should normally use the CapWords convention.

These naming conventions are also followed in the Django framework. So you can choose the third option.

Upvotes: 1

Related Questions