Methods in Models

34 views
Skip to first unread message

Deep Shah

unread,
Oct 24, 2016, 3:47:26 AM10/24/16
to Django users
What kind of methods should be part of the models and what should be in the views? Can anyone give me an example of a method which should be in a Model than the views file?

Asad Jibran Ahmed

unread,
Oct 24, 2016, 4:15:28 AM10/24/16
to django...@googlegroups.com
Any method that works only with the model data and is used in multiple places in the application should be a part of the model.

Next, if you have functions that operate on multiple pieces of data (or more than 1 model instances) you should put them in the view where they are used. But if these functions are needed from multiple views, then personally I create a helper class to hold them, and the helper class is outside the view and model files.

Of course in the end, none of these are hard and fast rules. Just go with whatever you feel is more maintainable, and use these as general guidelines.
On Mon, Oct 24, 2016 at 11:47 AM, Deep Shah <deeps...@gmail.com> wrote:
What kind of methods should be part of the models and what should be in the views? Can anyone give me an example of a method which should be in a Model than the views file?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ccf6df1-aaa2-42a7-b5dc-ecb8f2390bf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deep Shah

unread,
Oct 26, 2016, 2:34:52 AM10/26/16
to Django users
This makes sense! Thanks!
Reply all
Reply to author
Forward
0 new messages