On Thu, May 1, 2014 at 5:36 PM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
On 2/05/2014 2:16 AM, Adam "Cezar" Jenkins wrote:
On Thu, May 1, 2014 at 11:10 AM, Venkatraman S <venkat83@gmail.com<emperorcezar@gmail.com <mailto:emperorcezar@gmail.com>> wrote:Â Â |-----views.py
Right now I have a large project with an equally large API (done
using django rest framework). The current structure is something
like this:
api
|-----urls.py
|-----models.py
|
----v1
  |-----serializers.py
  |-----permissions.py
  |-----tests.pyrefactor that into multiple files under 'v1'  itself - nothing is
etc
As you can guess, the views.py file is pretty big and I want to
refactor this out. Currently I have a few options in front of
me, the one I'm leaning towards is to put an 'api/v1' package
into each app and use the api app to tie all the urls together
and hold views that don't fall into an app.
If the only pain point is the big views file, then why not just
stopping you from doing that.Â
That was one way I started refactoring, but ran into issues. Say I have
a destinations.py view file in the api, but I also have a destinations
app. In my views file I can't do 'from destinations.models import
Destination' cause the name conflicts. So I started having to name
things 'destinations_api.py' which seemed really dirty.
I might have missed something here but the usual Django way of refactoring a large views (models too) file is to convert it into a directory containing a file for each view. Then you can still refer to each view using the dotted names as previously. No need to change other code in other parts of the app which calls them.
You're correct that code outside of those view wouldn't have to change, but the name of the file the view is in can clash with something outside that file.
Â<mailto:django-users+unsubscribe@googlegroups.com>. <mailto:django-users@googlegroups.com>.
--
You received this message because you are subscribed to a topic in
the Google Groups "Django users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/django-users/rizwdsi5o1k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
django-users+unsubscribe@googlegroups.com<https://groups.google.com/d/msgid/django-users/CAN7tdFT0BAG5XoKoiavKr7v24DqSQTc7D%2Bq5EY7Wgoh_VzvzeA%40mail.gmail.com?utm_medium=email&utm_source=footer>. --
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAN7tdFT0BAG5XoKoiavKr7v24DqSQTc7D%2Bq5EY7Wgoh_VzvzeA%40mail.gmail.com
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
<mailto:django-users+unsubscribe@googlegroups.com>. <mailto:django-users@googlegroups.com>.https://groups.google.com/d/msgid/django-users/CAN6vQqtUML2-o3pkx02o%2BnsZ0nnYCUC6XULjw--MdRwRyOcsdg%40mail.gmail.com
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
<https://groups.google.com/d/msgid/django-users/CAN6vQqtUML2-o3pkx02o%2BnsZ0nnYCUC6XULjw--MdRwRyOcsdg%40mail.gmail.com?utm_medium=email&utm_source=footer>.--To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5362CC50.5060905%40dewhirst.com.au.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/rizwdsi5o1k/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN6vQquB1Lsmq%2BeH1D9imZFOVr7H8Gr0%3D5VqaxCE6K_iAB1SYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment