How to use custom classes in django

259 views
Skip to first unread message

jake2891

unread,
Sep 22, 2010, 4:10:15 AM9/22/10
to Django users
Hey guys, i am using extjs in django and am wondering the correct way
to build custom classes like file upload classes and classes of
functions. I am a bit confused does everything have to go into
views.py by defining a function for each ajax request or what is the
process? As with extjs like drop downs make an ajax request to
populate them with data do all of these for all of my fields go into
the view or can i create a custom class of methods and just use the
views for rendering the forms. thanks

Daniel Roseman

unread,
Sep 22, 2010, 4:48:44 AM9/22/10
to Django users
Why do you think you need classes for this? Python is not Java, not
everything has to be a class.
--
DR.

jake2891

unread,
Sep 22, 2010, 4:56:39 AM9/22/10
to Django users
It doesnt need to be a class i am new to python / django and come from
a php background so was just wondering what the best practice is? Is
it to just put all requests and handling the savinf form data all into
the one view.py? thanks for the reply

Bill Freeman

unread,
Sep 22, 2010, 9:20:33 AM9/22/10
to django...@googlegroups.com
Start with the tutorial (for python version 2.x) at python.org

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

Sam Lai

unread,
Sep 23, 2010, 2:17:04 AM9/23/10
to django...@googlegroups.com
After revising python basics, here's how I'd structure it -

On 22 September 2010 18:10, jake2891 <leahy...@hotmail.com> wrote:
> Hey guys, i am using extjs in django and am wondering the correct way
> to build custom classes like file upload classes and classes of
> functions.

I'm assuming by 'file upload classes' you mean file upload views, i.e.
the code responsible for receiving the file upload. If so, they're
just like any other view. In Django though, you might want to consider
putting file validation and processing code into your forms.py or
models.py for better abstraction and reusability.

For 'classes of (useful) functions', put them wherever they make
sense. As mentioned, they don't need to be classes - you can just have
files with functions in them. Use classes only when a class makes
sense. If they're only applicable in one app, put them in a file in
that app. You might want to use different files to separate the
functions into different namespaces.

> I am a bit confused does everything have to go into
> views.py by defining a function for each ajax request or what is the
> process? As with extjs like drop downs make an ajax request to
> populate them with data do all of these for all of my fields go into
> the view or can i create a custom class of methods and just use the
> views for rendering the forms. thanks

Yep, they're just like every other view. You could use some python
magic to reuse the same view for different but related AJAX requests
and avoid repetition. You might want to consider putting the code for
getting the data in your form, so you can easily create an alternative
non-AJAX form.

Reply all
Reply to author
Forward
0 new messages