Django naming conventions for dates

Is there any naming convention for the dates "created" and "last edit" in Django?

i.e., in the Symfony Framework, these fields are called by default:

  • created_at
  • updated_at
+4
source share
4 answers

In Django origin models, these fields are named based on the type of model, i.e.

  • auth.User: date_joined
  • comments.Comment: submit_date

Therefore, probably we should follow this agreement.

0
source

Indeed, as far as I can tell, there is no canonical agreement for Django, but I really like the Rails convention:

  • created_at for DateTime fields
  • created_on for date fields

created works great for creation dates, but as soon as you have more ambiguous fields like activated , this becomes a problem. Is this a boolean or a date / date? Naming conventions exist to help developers understand code faster and spend less time on unimportant decisions. This is the philosophy behind the configuration convention , which is big in the Rails community, but unfortunately not so much in Django. This confusion that I mentioned, for example, is typical, and therefore I prefer to always be more clear:

  • If it is boolean is_activated
  • If it is datetime activated_at
  • If it's just activated_on date

I heard people say that “you should not mix field names with data types”, but in my opinion this is pretty empty advice and I never heard any specific arguments. If we want to optimize code readability and decision making, than I really think explicit naming conventions are the way to go.

+8
source

I prefer created and updated without the _at suffix. I do not know of any "canonical" preference for designating fields.

For what it's worth, I think Rails uses created_at / created_on and updated_at / updated_on .

+1
source

I don’t think there is something like a canonical way to call such things in Django. Some parts are well covered by PEP8 , mainly because this kind of thing goes beyond Django, as this is a much more important issue (and possibly households).

However, I believe that these fields are usually called created_at and updated_at , and I personally follow this convention when writing my own code. I recommend avoiding names like created or updated , as they are ambiguous (although some popular libs use this style): are they logical or something else? is_created / is_updated , if you need it, these are the best options.

+1
source

All Articles