[Answered ]-Best practice for adding a custom field in Django

1👍

I would put any custom fields of yours in a separate fields.py.

Have a look at some apps in django.contrib, most have a generic structure of a single models.py, fields.py, views.py, middleware.py etc.

Following the standard means that your app can be picked up by anyone familiar with the django framework with ease.

1👍

I wouldn’t recomend to have everything in one models.py file. I like to create separate packages for models, fields and views, which then contain additional modules. I think it’s one of the best solutions for code structure and readability of Django application.
It looks like this:

/app
  /models
     /__init__.py
     /model1.py
     /model2.py
  /fields
     /__init__.py
     /custom_field1.py
     /custom_field2.py
  /views
     /__init__.py
     /page1.py
     /page2.py
👤davekr

Leave a comment