Hello Guys,
I'm relatively new to django.
I have some doubt about good practices, using it.
1 - I have some helpers that I use on all apps.
For this I created a app called helpers
(./manager.py startapp helpers)
it don't have any view, or model.
And then I created some files like:
misc.py
choices.py
use.py
and inside choices.py I have for example:
from content.models import Publication, Issue, Article, Comment, Image
OBJ_HANDLER = {
'publication': Publication,
'issue': Issue,
'article': Article,
'comment': Comment,
'image': Image,
}
PERMISSION_CHOICES = (
(0, 'None'),
(1, 'Read/Comment'),
(2, 'Edit/Comment'),
(4, 'Read'),
)
Is it ok, if I create 'empty' apps, like that ?
2 - There are some commands that I like to think that I will always use:
for example:
add, remove, view, edit and browse
For that I created a file (handlers.py) insie my app (content)
And I use like this:
content/urls.py:
urlpatterns = patterns('',
(r'^browse/(?P<obj>.*)/(?P<page>.*)/', 'content.views.browse'),
(r'^(?P<cmd>.*)/(?P<obj>.*)/(?P<key>.*)/(.*)', 'content.handlers.url'),
)
content/handlers.py:
import views
def url(request, cmd, obj, key=0):
f_name = obj+ '_' +cmd
call = getattr(views, f_name.lower())
return call(request, key)
content/views.py:
def publication_edit(request, key):
do_something()
So, I can use:
/content/edit/publication/<my_key>/
Is it ok, if I create other files in the app's directory, like this ?
(I have a file called 'forms' too).
3 - Is there any problem if I use the OBJ_HANDLER (from
helpers/choices.py) like this:?
entries_list = OBJ_HANDLER[obj].objects.all().filter('public =', True)
4 - I have a form that has a create() method.
class IssueForm(djangoforms.ModelForm):
#... code....
def create(self, data):
return Issue(publication = data['publication']).save()
Is it ok if I return saved objects in forms ?
Is all of this, or some of this, good practices ?
Thank you a lot :)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.