Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 4, 2011 22:18:11

Ondřej M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Hello,
I am experienced PHP developer (and by PHP I mean advanced programming
with MVC frameworks, TDD, ORM libraries, design patterns and such, so
no scoffing please :)) and I would like to try something new. I've
chosen Python and Django and I am building my bachelor thesis project
with it.

I dived directly into django-nonrel fork, because I am building the
project on App Engine. However, I have few basic questions that
concern basic relational Django as well.

1) Since Python has no object encapsulation, I have no idea how to
implement computed columns in its models. E. g. I want to save forum
post rating in the "posts" table even if I have related table with all
the related post votes because it's faster and no joins are required
to get the rating value.

2) I would like to perform some integrity checking before saving
object to the database. I found here (http://docs.djangoproject.com/en/1.2/topics/db/models/#overriding-predefined-model-methods) that I can
override entity save method and stop it's execution before calling
parent implementation. However, this didn't work for me for two
reasons - it somehow caused 500 error on App Engine (because the app
does not know that the object was not saved?) and it does not meet my
needs - I would like to "attach" some error message to this
application state and I would like this message to bubble up to the
form errors (in case it happens when a form is submitted) in a way
compatible with Django admin, so the user can fix the problem.

3) I would like to read about some best practices about midsize and
large Django projects. How to organize the code, what directory
structure to choose etc. Are there any additional layers between model
and views widely used? Where should I put my code that is not directly
related to model and is used in more than one view? Can you recommend
me some articles about this topic?

4) What about dependency injection? From what I saw so far it seems
like Django is full of singletons, static attributes and methods and
hidden dependencies, which are considered as bad practice. For example
how can I use two connections to two different databases to load and
save model entities? Are there any "inversion of control" concepts?

Thank you very much! And you can expect more questions to come in this
thread :)

Ondřej Mirtes from Prague, Czech Republic

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

Offline

#2 Jan. 5, 2011 02:38:17

Shawn M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Hi Ondřej.

For your question #1, you could create a field in the model itself and then use
signals to populate it upon the saving of a "vote" instance.

#2: The validation should all be done during form validation, prior to save.
Using a Form or ModelForm. That way, the user can get friendly, useful errors.

#3: I have no idea. Maybe someone else has recommendations.

#4: There's a whole lot of stuff in that question. Maybe if you broke out some
specific examples someone will try to explain the rationale behind the design.

http://docs.djangoproject.com/en/1.2/topics/signals/http://docs.djangoproject.com/en/1.2/ref/forms/validation/Shawn

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

Offline

#3 Jan. 5, 2011 13:52:06

Scott G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


On Jan 4, 9:38 pm, Shawn Milochik <sh...@milochik.com> wrote:
> Hi Ondřej.
>
> ...
> #2: The validation should all be done during form validation, prior to
> save. Using a Form or ModelForm. That way, the user can get friendly, useful
> errors.

Further to this, look into model validation if the logic is integral
to the model:http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#validating-objectsI tend to put the low-level logic in there, and have the forms handle
the errors raised from the model validation, rather than packing it
all into the form (if for no other reason than sometimes objects are
not created from forms!).

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

Offline

#4 Jan. 7, 2011 14:22:18

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Re: "inversion of control" in Python - look at:http://plope.com/control_inversionhttp://code.activestate.com/recipes/413268-dependency-injection-the-python-way/http://blog.code.zaubersoftware.com/2009/04/controlfreak-python-inversion-of.htmlOn Jan 5, 12:06 am, Ondřej Mirtes <ond...@mirtes.cz> wrote:
> Hello,
> I am experienced PHP developer (and by PHP I mean advanced programming
> with MVC frameworks, TDD, ORM libraries, design patterns and such, so
> no scoffing please :)) and I would like to try something new. I've
> chosen Python and Django and I am building my bachelor thesis project
> with it.
>
> I dived directly into django-nonrel fork, because I am building the
> project on App Engine. However, I have few basic questions that
> concern basic relational Django as well.
>
> 1) Since Python has no object encapsulation, I have no idea how to
> implement computed columns in its models. E. g. I want to save forum
> post rating in the "posts" table even if I have related table with all
> the related post votes because it's faster and no joins are required
> to get the rating value.
>
> 2) I would like to perform some integrity checking before saving
> object to the database. I found here (http://docs.djangoproject.com/en/> 1.2/topics/db/models/#overriding-predefined-model-methods) that I can
> override entity save method and stop it's execution before calling
> parent implementation. However, this didn't work for me for two
> reasons - it somehow caused 500 error on App Engine (because the app
> does not know that the object was not saved?) and it does not meet my
> needs - I would like to "attach" some error message to this
> application state and I would like this message to bubble up to the
> form errors (in case it happens when a form is submitted) in a way
> compatible with Django admin, so the user can fix the problem.
>
> 3) I would like to read about some best practices about midsize and
> large Django projects. How to organize the code, what directory
> structure to choose etc. Are there any additional layers between model
> and views widely used? Where should I put my code that is not directly
> related to model and is used in more than one view? Can you recommend
> me some articles about this topic?
>
> 4) What about dependency injection? From what I saw so far it seems
> like Django is full of singletons, static attributes and methods and
> hidden dependencies, which are considered as bad practice. For example
> how can I use two connections to two different databases to load and
> save model entities? Are there any "inversion of control" concepts?
>
> Thank you very much! And you can expect more questions to come in this
> thread :)
>
> Ondřej Mirtes from Prague, Czech Republic

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

Offline

#5 Jan. 7, 2011 14:28:26

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Re: " I would like to read about some best practices about midsize and
large Django projects."

I would recommend first implementing a small-ish but meaningful (i.e.
something that addresses a Real World problem, and that you will
actually use) project; that way you will see the overall structure and
shape of a typical project. Trying to "brute force" PHP concepts into
a Python -based framework is a certain recipe for frustration... and
just reading about them will not help change your world view. (My
2c) I started with The Django Book - it starts very simply, with the
basic concepts, and someone with your skills should be able to work
through this fairly quickly.

On Jan 5, 12:06 am, Ondřej Mirtes <ond...@mirtes.cz> wrote:
> Hello,
> I am experienced PHP developer (and by PHP I mean advanced programming
> with MVC frameworks, TDD, ORM libraries, design patterns and such, so
> no scoffing please :)) and I would like to try something new. I've
> chosen Python and Django and I am building my bachelor thesis project
> with it.
>
> I dived directly into django-nonrel fork, because I am building the
> project on App Engine. However, I have few basic questions that
> concern basic relational Django as well.
>
> 1) Since Python has no object encapsulation, I have no idea how to
> implement computed columns in its models. E. g. I want to save forum
> post rating in the "posts" table even if I have related table with all
> the related post votes because it's faster and no joins are required
> to get the rating value.
>
> 2) I would like to perform some integrity checking before saving
> object to the database. I found here (http://docs.djangoproject.com/en/> 1.2/topics/db/models/#overriding-predefined-model-methods) that I can
> override entity save method and stop it's execution before calling
> parent implementation. However, this didn't work for me for two
> reasons - it somehow caused 500 error on App Engine (because the app
> does not know that the object was not saved?) and it does not meet my
> needs - I would like to "attach" some error message to this
> application state and I would like this message to bubble up to the
> form errors (in case it happens when a form is submitted) in a way
> compatible with Django admin, so the user can fix the problem.
>
> 3) I would like to read about some best practices about midsize and
> large Django projects. How to organize the code, what directory
> structure to choose etc. Are there any additional layers between model
> and views widely used? Where should I put my code that is not directly
> related to model and is used in more than one view? Can you recommend
> me some articles about this topic?
>
> 4) What about dependency injection? From what I saw so far it seems
> like Django is full of singletons, static attributes and methods and
> hidden dependencies, which are considered as bad practice. For example
> how can I use two connections to two different databases to load and
> save model entities? Are there any "inversion of control" concepts?
>
> Thank you very much! And you can expect more questions to come in this
> thread :)
>
> Ondřej Mirtes from Prague, Czech Republic

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

Offline

#6 Jan. 8, 2011 10:07:29

Ondřej M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Thank you all for your responses.

I have one more question - what is the purpose of "apps" in
"projects" (when I create new app in a project via manage.py
startapp)? Are they something like sections of a web (articles, forum,
user administration?) or are they rather something like modules,
reusable across projects? How big should be an app?

How should I solve typical scenario when my site consists of a small
frontend presentation and a complex API service?

Thanks.

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

Offline

#7 Jan. 8, 2011 10:30:31

Mike T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


I've had this question too, when I'm designing a project. So far, I have
dumped all of my own code into the one app that I create for the project and
then add external apps that can be found on the internet to extend my
project's functionality. For example, I needed to download articles from
RSS feeds so I added feedjack to my project. I don't use any of that app's
templates or views, but I use the admin interface to manage the feeds, and I
access the model objects from my own app. I also use the included command
line script to update the feeds. For the next project I start, I will think
about the features that I plan, and whether or not those features could ever
be reused in some other project. If so, then I'll try to put those features
into separate apps. I believe there are some additional steps to take to
make an app reusable outside of the project in which it is created.

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

Offline

#8 Jan. 8, 2011 13:50:39

Mike R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


On Saturday, January 08, 2011 02:07:22 am Ondřej Mirtes wrote:
> Thank you all for your responses.
>
> I have one more question - what is the purpose of "apps" in
> "projects" (when I create new app in a project via manage.py
> startapp)? Are they something like sections of a web (articles, forum,
> user administration?) or are they rather something like modules,
> reusable across projects? How big should be an app?
>


They are really both, see django-registration, djangobb, pinax, and many other
django-apps (search google code and github).

> How should I solve typical scenario when my site consists of a small
> frontend presentation and a complex API service?
>

This is really a question best left upto you to answer. Looking at existing
apps, some are small providing specific functionality (django-email-
notifiation iirc is another), others really huge providing a whole slew of
things (see djangobb and pinax). Others have made apps that just hold template
tags, to one app for the whole site (which most new django developers do).

My suggestion to you is to build it the way that makes it easy to maintain the
site, for you and developers after you. If some functionality that you come up
with can be of use to others, then it's worthwhile to make it it's own app and
release it into the wild via your fav license.

Mike



--
Death comes on every passing breeze,
He lurks in every flower;
Each season has its own disease,
Its peril -- every hour.
--Reginald Heber

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

Offline

#9 Jan. 10, 2011 09:46:44

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Apps vs Projects

There is probably no one better to address this topic than James
Bennet - see:http://www.b-list.org/weblog/2008/feb/11/integrity/(e.g. "when Django first appeared I was playing with Rails, and the
available options for this sort of reusable functionality in Rails
all, frankly, sucked: engines and plugins and what-have-you, and none
of it was really elegant.")

But you really need to watch this video. Its long but James is very
very focused and clearly highlights the key concepts and their
practical demonstration:http://www.youtube.com/watch?v=A-S0tqpPga4On Jan 8, 12:07 pm, Ondřej Mirtes <ond...@mirtes.cz> wrote:
> Thank you all for your responses.
>
> I have one more question - what is the purpose of "apps" in
> "projects" (when I create new app in a project via manage.py
> startapp)? Are they something like sections of a web (articles, forum,
> user administration?) or are they rather something like modules,
> reusable across projects? How big should be an app?

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

Offline

#10 Jan. 10, 2011 09:52:52

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

A few beginner questions


Just one point of clarity - the intention is clearly for apps to be
small and focused and "do one thing well". Like much of Python, of
course, you as a developer can abuse this to your heart's content and
create humugenous and unwieldy code bases. (Pinax, incidentally, is
not an "app", but a bundled collection of apps that aim to make it
easier to start developing certain types of sites.)

On Jan 8, 3:50 pm, Mike Ramirez <gufym...@gmail.com> wrote:
> On Saturday, January 08, 2011 02:07:22 am Ondřej Mirtes wrote:
>
> > Thank you all for your responses.
>
> > I have one more question - what is the purpose of "apps" in
> > "projects" (when I create new app in a project via manage.py
> > startapp)? Are they something like sections of a web (articles, forum,
> > user administration?) or are they rather something like modules,
> > reusable across projects? How big should be an app?
>
> They are really both, see django-registration, djangobb, pinax, and many other
> django-apps (search google code and github).
>
> > How should I solve typical scenario when my site consists of a small
> > frontend presentation and a complex API service?
>
> This is really a question best left upto you to answer. Looking at existing
> apps, some are small providing specific functionality (django-email-
> notifiation iirc is another), others really huge providing a whole slew of
> things (see djangobb and pinax). Others have made apps that just hold template
> tags, to one app for the whole site (which most new django developers do).
>
> My suggestion to you is to build it the way that makes it easy to maintain the
> site, for you and developers after you. If some functionality that you come up
> with can be of use to others, then it's worthwhile to make it it's own app and
> release it into the wild via your fav license.
>
> Mike
>
> --
> Death comes on every passing breeze,
> He lurks in every flower;
> Each season has its own disease,
> Its peril -- every hour.
>         --Reginald Heber

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

Offline

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support