Monday, October 24, 2016

Re: Methods in Models

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 <deepshah.91@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-users@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.

--
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-users@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/CA%2BYYaWekXL_Qveb1xUeM1fFdNdpmNu9fvoYO9_zJUBn4qOGk3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment