Noob questions

215 views
Skip to first unread message

Ray Wang

unread,
Dec 16, 2010, 11:38:22 AM12/16/10
to Pinax Users
Hi,

I've just gotten started with Pinax and it has some great features out
of the box.

I had a couple question on non-design related things:

1.) While I found overriding templates intuitive and easy. I was
wondering how you would override things such as models.py and
views.py. For example, if I want to extend the the profile module to
add fields such as profession and age, how would I do it in the
existing framework?

2.) Is there anyway to have all the pinax modules be copied to my app
and run from there instead of a pinax directory? I find it's adds
extra work to refer to the pinax file system to find a template name
and override it in my app instead of directly editing it.

Thanks a lot,
Ray

Matt M

unread,
Dec 16, 2010, 1:36:32 PM12/16/10
to pinax...@googlegroups.com
"For example, if I want to extend the the profile module to
add fields such as profession and age, how would I do it in the
existing framework?"

Google "Django get_profile"
That should lead you in the right direction.
Basically you create a new model for profession, age, etc... Have a foreign key pointing back to the User model. Then you retrieve the extended data in your views/templates with get_profile


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


James Tauber

unread,
Dec 16, 2010, 1:57:30 PM12/16/10
to pinax...@googlegroups.com

On Dec 16, 2010, at 11:38 AM, Ray Wang wrote:

> Hi,
>
> I've just gotten started with Pinax and it has some great features out
> of the box.
>
> I had a couple question on non-design related things:
>
> 1.) While I found overriding templates intuitive and easy. I was
> wondering how you would override things such as models.py and
> views.py. For example, if I want to extend the the profile module to
> add fields such as profession and age, how would I do it in the
> existing framework?

Take a look at idios:

https://github.com/eldarion/idios

> 2.) Is there anyway to have all the pinax modules be copied to my app
> and run from there instead of a pinax directory? I find it's adds
> extra work to refer to the pinax file system to find a template name
> and override it in my app instead of directly editing it.

I'm confused whether you're talking about the modules or the templates (you seem to start off talking about one then switch to the other)

James

Matt M

unread,
Dec 16, 2010, 2:02:40 PM12/16/10
to pinax...@googlegroups.com
I believe you can see this in action in pinax by looking at the profile model in pinax.
Just follow what is happening there.

Ray Wang

unread,
Dec 16, 2010, 5:08:40 PM12/16/10
to Pinax Users
Hi,

Thank you Matt and James for replying so fast.

I'm also new to django and I'm afraid I might have used the wrong
terminology:

-I basically want to add the age, profession fields to the existing
pinax Profile App. If I want to override a template file for Profile,
I can create a corresponding file for it in the $PROJECT_ROOT/template
folder, but the same doesn't seem to apply for models.py under the
$PROJECT_ROOT/app/profile/model.py. I was wondering how to override
just that one file in an App.

I took a look at edios and it seems like it would solve my problem.
But that was a generic case which I want to apply to other Pinax apps.
For example, also overriding status update or swap etc.

After googling more on, I found this: http://www.markus-gattol.name/ws/python_web.html#sec11

"Overriding build-in Pinax Applications
Assuming we want to override $PINAX_ROOT/apps/blog with $PROJECT_ROOT/
apps/blog we can do so simply by copying the application and make our
project-local (read individual) changes to it. Pinax will then load
$PROJECT_ROOT/apps/blog rather than $PINAX_ROOT/apps/blog.
Those who do not care about merging in upstream changes nor submitting
bugfixes/features upstream would just issue cp -a $PINAX_ROOT/apps/
blog $PROJECT_ROOT/apps and be done. Those who consider themselves
good FLOSS-country citizens however care about contributing back as
well ..."

I was wondering if that method is a good way to do it (?)

-For my second question. I actually mean is there a way to copy all
the pinax code (app/ and template/) into my django app like how a
normal django app would be structured instead of externally linking. I
think the above solution might also work in that regard.

Sorry for the long email.

Thanks!
Ray

On Dec 16, 2:02 pm, Matt M <slackbabb...@gmail.com> wrote:
> I believe you can see this in action in pinax by looking at the profile
> model in pinax.
> Just follow what is happening there.
>
>
>
>
>
>
>
> On Thu, Dec 16, 2010 at 10:36 AM, Matt M <slackbabb...@gmail.com> wrote:
> > "For example, if I want to extend the the profile module to
> > add fields such as profession and age, how would I do it in the
> > existing framework?"
>
> > Google "Django get_profile"
> > That should lead you in the right direction.
> > Basically you create a new model for profession, age, etc... Have a foreign
> > key pointing back to the User model. Then you retrieve the extended data in
> > your views/templates with get_profile
>
> > On Thu, Dec 16, 2010 at 8:38 AM, Ray Wang <raycornellw...@gmail.com>wrote:
>
> >> Hi,
>
> >> I've just gotten started with Pinax and it has some great features out
> >> of the box.
>
> >> I had a couple question on non-design related things:
>
> >> 1.) While I found overriding templates intuitive and easy. I was
> >> wondering how you would override things such as models.py and
> >> views.py. For example, if I want to extend the the profile module to
> >> add fields such as profession and age, how would I do it in the
> >> existing framework?
>
> >> 2.) Is there anyway to have all the pinax modules be copied to my app
> >> and run from there instead of a pinax directory? I find it's adds
> >> extra work to refer to the pinax file system to find a template name
> >> and override it in my app instead of directly editing it.
>
> >> Thanks a lot,
> >> Ray
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Pinax Users" group.
> >> To post to this group, send email to pinax...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> pinax-users...@googlegroups.com<pinax-users%2Bunsubscribe@googlegr oups.com>
> >> .

James Tauber

unread,
Dec 16, 2010, 7:17:09 PM12/16/10
to pinax...@googlegroups.com

On Dec 16, 2010, at 5:08 PM, Ray Wang wrote:

> Hi,
>
> Thank you Matt and James for replying so fast.
>
> I'm also new to django and I'm afraid I might have used the wrong
> terminology:
>
> -I basically want to add the age, profession fields to the existing
> pinax Profile App. If I want to override a template file for Profile,
> I can create a corresponding file for it in the $PROJECT_ROOT/template
> folder, but the same doesn't seem to apply for models.py under the
> $PROJECT_ROOT/app/profile/model.py. I was wondering how to override
> just that one file in an App.

Individual app files don't work the same way as templates in that regard. The entire app package has to be overridden. Although, in many cases the app will support some level of customization without you having to write your own app.

> I took a look at edios and it seems like it would solve my problem.

The way idios approaches the problem is you write your own profile model (you don't override anything) but you subclass ProfileBase so idios can provide a lot of the generic profile-like capability for you.

> But that was a generic case which I want to apply to other Pinax apps.
> For example, also overriding status update or swap etc.

To the extent that you can't customize via templates or via whatever mechanisms the app provides, you'd need to write your own app.

> After googling more on, I found this: http://www.markus-gattol.name/ws/python_web.html#sec11
>
> "Overriding build-in Pinax Applications
> Assuming we want to override $PINAX_ROOT/apps/blog with $PROJECT_ROOT/
> apps/blog we can do so simply by copying the application and make our
> project-local (read individual) changes to it. Pinax will then load
> $PROJECT_ROOT/apps/blog rather than $PINAX_ROOT/apps/blog.
> Those who do not care about merging in upstream changes nor submitting
> bugfixes/features upstream would just issue cp -a $PINAX_ROOT/apps/
> blog $PROJECT_ROOT/apps and be done. Those who consider themselves
> good FLOSS-country citizens however care about contributing back as
> well ..."
>
> I was wondering if that method is a good way to do it (?)

Well, as that article says, if you want to be a good open source citizen, don't do it that way. It's fine, though, if you don't plan to share your customizations back to the community and if you're find not being able to get new updates for that app.

> -For my second question. I actually mean is there a way to copy all
> the pinax code (app/ and template/) into my django app like how a
> normal django app would be structured instead of externally linking. I
> think the above solution might also work in that regard.

You can certainly copy it, just using cp -r or equivalent. But again, that has the caveat that you can't easily share your customizations nor be able to get updates for the app you've copied.


James

Ray Wang

unread,
Dec 17, 2010, 10:17:11 AM12/17/10
to Pinax Users
Thank you James for the answers! I'll keep them in mind and only
override locally when necessary.

Ray
Reply all
Reply to author
Forward
0 new messages