Re: help passing data from view to template

2005-12-21 Thread Colleen Owens
Okay, yeah this was a dumb question, foolishly asked before I got
through part 4 of the tutorial. I see now that calling get_link_list
from within my template will do what I need. I didn't realize that
get_link_list would preserve ordering.On 12/21/05, Colleen Owens <[EMAIL PROTECTED]> wrote:
I'm a Django newbie. This follows up on a question I asked before and a very helpful answer to on this list.

So I have a list of dates and for each date I have a list of link
objects I want to display. I'm trying to figure out how to best pass
this data from my view to the template. 

I tried this and several variations on this, but I'm not properly
accessing the variable keys that I'm passing into my Context object. I
guess what I really don't understand is what can be passed into the
template and how it's accessed. All the examples I could find just pass
in very simple lists.

def index(request):
    date_list = newslists.get_list(order_by=["-date"])
    args = {'date_list': date_list}
    for date in date_list:
        dateids = date.get_link_order()
        datelinks = []
        for id in dateids:
            datelinks.append(links.get_object(id__exact = id))
        args[] = datelinks
    t = loader.get_template('news/index')
    c = Context(args)
    return HttpResponse(t.render(c))

(nevermind that even if this worked, the list wouldn't be very pretty)

{% for date in date_list %}
    {{ date }}
    {% for link in date %}
    {{ link.title }}
    {% endfor %}
{% endfor %}


Thanks for your help!

Colleen




Re: Django for eCommerce?

2005-12-21 Thread James Bennett

On 12/21/05, Michael Hipp <[EMAIL PROTECTED]> wrote:
> Could anyone elaborate - perhaps with pointers to docs or example code to
> implement some of the features?

Here's how I'd imagine it would be set up:

Models:
  Product (related ManyToMany to Category)
  Category (related ManyToMany to Product)
  User (either the built-in User model, or your own)
  Cart (related OneToOne to User and OneToMany to Product)

This would give you the ability to add products to the site and
categorize them, and to have a cart for each user that they can add
products to. The hardest part would be payment processing; you'd need
to write code in your checkout view that would take payment details
and send that information through your processing service.


--
"May the forces of evil become confused on the way to your house."
  -- George Carlin


Re: Django for eCommerce?

2005-12-21 Thread Ian Holsman

from my understanding there is no opensource 'shopping cart' or
'product database' application
which you can just download and install.

but i'm sure if you want to sponsor one there will be a couple of
hands going up to do it.

what Jacob meant is that all the bits for you to build a eCommerce
site are available.. you just need to build the app.

regards
Ian.

On 12/22/05, Michael Hipp <[EMAIL PROTECTED]> wrote:
>
> Jacob Kaplan-Moss wrote:
> >
> > On Dec 21, 2005, at 10:24 AM, Michael Hipp wrote:
> >
> >> How suitable is Django for an eCommerce site (SSL, shopping cart,
> >> product database, accounts, etc.)?
> >
> >
> > Very well suited.
>
> Thank you.
>
> Could anyone elaborate - perhaps with pointers to docs or example code to
> implement some of the features?
>
> Thanks,
> Michael
>


--
[EMAIL PROTECTED] -- blog: http://feh.holsman.net/ -- PH: ++61-3-9877-0909

If everything seems under control, you're not going fast enough. -
Mario Andretti


Re: concept problem with apps

2005-12-21 Thread James Bennett

On 12/21/05, Armin <[EMAIL PROTECTED]> wrote:
> Thanks James for the great example. So, online store which is a huge
> project all by itself will not be broken down to multiple apps? But
> will be used as a simple package.

If it would be easier to maintain as one application, do it as one
application. If it would be easier to maintain as multiple
applications, do it as multiple applications. Django makes it easy to
do whatever's most convenient for you.


--
"May the forces of evil become confused on the way to your house."
  -- George Carlin


Re: Django for eCommerce?

2005-12-21 Thread Michael Hipp


Jacob Kaplan-Moss wrote:


On Dec 21, 2005, at 10:24 AM, Michael Hipp wrote:

How suitable is Django for an eCommerce site (SSL, shopping cart,  
product database, accounts, etc.)?



Very well suited.


Thank you.

Could anyone elaborate - perhaps with pointers to docs or example code to 
implement some of the features?


Thanks,
Michael


Re: concept problem with apps

2005-12-21 Thread Waylan Limberg

On 12/21/05, James Bennett <[EMAIL PROTECTED]> wrote:
>
> Client A is an individual who wants to have a weblog.
>
> Client B is a company that wants to have an online store.
>
> Client C is a company that wants to have both an online store and a weblog.
>
> So you could write a 'weblog' application, and install it into Client
> A's site and Client C's site, and a 'store' application, and install
> it for Client B and Client C. Because Django applications are
> portable, you only have to write each application once, and then you
> can install it into as many sites as you need to.

And don't forget that Client C can then log in once for both the
online store and the weblog and share the same user and session data.
If they were told that was not possible, they probably wouldn't like
that as they don't see them as 2 separate apps, just separate parts of
one.

On various lists and forum's I often see questions about how two (or
more) sepperate apps installed for a single client can share this
data. Seeing each app is developed seperately, its not always easy or
possable. Django eliminates that problem as long as all apps are
developed using Django. As we begin to see some apps released into the
public domain, this will really make things easy.

On the other hand, if this behavior is undesirable, one could always
put each app in a separate project.



--

Waylan Limberg
[EMAIL PROTECTED]


Re: additional data for generic views

2005-12-21 Thread Ian Holsman

if your view uses DjangoContext (which the generic views do I belive)
than the user is just

{{ user }}
so something like
{% for group in user.get_group_list %}
 {{ group }}
{% endfor %}
should work.

regards
Ian

On 12/22/05, patrick k <[EMAIL PROTECTED]> wrote:
>
> while trying to implement a system for project-management into our
> django-based admin-interface, i´m having a small problem here.
>
> right now, i´m using generic views for the "notes".
> when a user wants to create a note, he/she has to select a user or a
> user-group which relates to that note. for the user(groups), i´m using
> djangos auth tables.
>
> question is: how do i get the user and user-groups within my template (which
> is notes_form.html)?
> more general: is there a way to add additional data (from different modules)
> to info_dict?
>
> patrick
>
>


--
[EMAIL PROTECTED] -- blog: http://feh.holsman.net/ -- PH: ++61-3-9877-0909

If everything seems under control, you're not going fast enough. -
Mario Andretti


Re: concept problem with apps

2005-12-21 Thread Armin

Thanks James for the great example. So, online store which is a huge
project all by itself will not be broken down to multiple apps? But
will be used as a simple package.

Armin



Re: concept problem with apps

2005-12-21 Thread James Bennett

On 12/21/05, Armin <[EMAIL PROTECTED]> wrote:
> I don't quite understand the need for multiple 'apps'. They share the
> same 'session' variables... so you wouldn't run 2 different websites as
> two different apps. Basically, I want to get some examples of
> situations I'd need to use apps.

You don't have to use separate apps for everything, but it can be
handy depending on what you're going to use them for, particularly if
you're going to reuse them. For example, consider the case of a
freelance web developer who has three clients:

Client A is an individual who wants to have a weblog.

Client B is a company that wants to have an online store.

Client C is a company that wants to have both an online store and a weblog.

So you could write a 'weblog' application, and install it into Client
A's site and Client C's site, and a 'store' application, and install
it for Client B and Client C. Because Django applications are
portable, you only have to write each application once, and then you
can install it into as many sites as you need to.

If you're only ever going to set up one Django-powered site, the case
for maintaining separate applications isn't as strong; as far as I'm
concerned, reusability and portability are the big benefits here.


--
"May the forces of evil become confused on the way to your house."
  -- George Carlin


additional data for generic views

2005-12-21 Thread patrick k

while trying to implement a system for project-management into our
django-based admin-interface, i´m having a small problem here.

right now, i´m using generic views for the "notes".
when a user wants to create a note, he/she has to select a user or a
user-group which relates to that note. for the user(groups), i´m using
djangos auth tables.

question is: how do i get the user and user-groups within my template (which
is notes_form.html)?
more general: is there a way to add additional data (from different modules)
to info_dict?

patrick 



Re: Django built-in web server?

2005-12-21 Thread Michael Hipp


Joseph Kocherhans wrote:
On 12/21/05, *Michael Hipp* <[EMAIL PROTECTED] > 
wrote:



The documentation says "Django comes with its own Web server for
development
purposes." I'd like to use this for development and experimentation.
But I can
find nothing about where it lives or how to configure and run it.
Any pointers? 



You're probably looking for the django-admin.py runserver command. Check 
out http://www.djangoproject.com/documentation/tutorial2/ and search for 
"Start the development server"


Yes. I completely missed that. Thank you very much.

Michael


Re: Django built-in web server?

2005-12-21 Thread Joseph Kocherhans
On 12/21/05, Michael Hipp <[EMAIL PROTECTED]> wrote:
The documentation says "Django comes with its own Web server for developmentpurposes." I'd like to use this for development and experimentation. But I canfind nothing about where it lives or how to configure and run it. Any pointers?
You're probably looking for the django-admin.py runserver command. Check out http://www.djangoproject.com/documentation/tutorial2/ and search for "Start the development server"
Joseph


Django built-in web server?

2005-12-21 Thread Michael Hipp


The documentation says "Django comes with its own Web server for development 
purposes." I'd like to use this for development and experimentation. But I can 
find nothing about where it lives or how to configure and run it. Any pointers?


Thanks,
Michael


Django for eCommerce?

2005-12-21 Thread Michael Hipp


Hello, just trying to get started with Django. Question...

How suitable is Django for an eCommerce site (SSL, shopping cart, product 
database, accounts, etc.)?


Thank you,
Michael Hipp
Heber Springs, Arkansas, USA


Re: Problem in Admin section, in shell works great

2005-12-21 Thread Robert Wittams

Burhan wrote:
> class META:
> admin =  meta.Admin(
> list_display=('name','price'),
> list_filter=('price'),
This list_filter value is not a tuple. It is just a string in brackets.
This means that we iterate through the string and try to find fields
with the individual character names.

Maybe we should assert that these things are not strings.

Change it to:

 list_filter=('price',),



Re: Importing stuff in your app's models module?

2005-12-21 Thread Aggelos Orfanakos

Thanks for your response. I'm looking forward to this branch. :-)



Re: single table inheritance

2005-12-21 Thread Marcos Sánchez Provencio

According to sets theory you should not even care about order of
columns, the same as happens with the elements of a Python dict.

You can always tweak the generated sql for aesthetics...

El mié, 21-12-2005 a las 01:03 +, braver escribió:
> Is there a way to do single table inheritance in django?  E.g., I have
> this part of a classical CD model:
> 
> # order is preserved here,
> # but changes for derived classes => so we invert it for them!
> 
> class Person(meta.Model):
> middle_name = meta.TextField(null=True)
> last_name   = meta.TextField()
> first_name  = meta.TextField()
> 
> class Composer(Person):
> pass
> 
> class Conductor(Person):
> pass
> 
> class Soloist(Person):
> pass
> 
> Here's the SQL generated by django:
> 
> CREATE TABLE "cd_persons" (
> "id" integer NOT NULL PRIMARY KEY,
> "middle_name" text NULL,
> "last_name" text NOT NULL,
> "first_name" text NOT NULL
> );
> 
> CREATE TABLE "cd_composers" (
> "id" integer NOT NULL PRIMARY KEY,
> "first_name" text NOT NULL,
> "last_name" text NOT NULL,
> "middle_name" text NULL
> ...
> 
> -- notice that the order of columns for Person corresponds to
> cd_persons, but for the derived classes it's backwards!  Thus, I
> inverted it in Person -- which is, in fact, abstract in C++ sense, I'm
> only going to use Composer/Conductor/Soloist.  The SQL generator
> appears broken for the order of the derived classes, or I'm not
> supposed to do such things in a model?
> 
> Rails has "single table inheritance" in the sense you can put all
> attributes into one table, and superimpose all classes on it, with an
> extra "type" column as the discriminant/class tag.  Any such thing in
> django?
> 
-- 
Marcos Sánchez Provencio <[EMAIL PROTECTED]>



Re: concept problem with apps

2005-12-21 Thread Jeroen Ruigrok van der Werven
Perhaps it is just me, but I have a bit of difficulty understanding
what you are trying to ask here. Could you please rephrase it?

Thanks,

--
Jeroen Ruigrok van der Werven


Re: Problem in Admin section, in shell works great

2005-12-21 Thread Adrian Holovaty

On 12/21/05, Burhan <[EMAIL PROTECTED]> wrote:
>   Any idea? I suspect its the 'name' and that this is a reserved name
> in Django.  Is there a list of such things? I have run into this
> problem before (while naming my app admin).

Hmmm, no, "name" certainly isn't a reserved name. It must be something else.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: Importing stuff in your app's models module?

2005-12-21 Thread Adrian Holovaty

On 12/21/05, Aggelos Orfanakos <[EMAIL PROTECTED]> wrote:
> I recently wanted to tweak how a model was being saved, so I used the
> _pre_save method of it. In the _pre_save method I needed to use the
> gethostbyaddr and herror of the socket module. To my surprise, I got
> problems [1] when having "from socket import gethostbyaddr, herror" in
> module-level. It worked, however, when I moved the from ... import ...
> statement *inside* the _pre_save method.
>
> Is there a restriction on importing stuff in your app's models module?
> And if yes, is there a reason for this?

At the moment, the model module doesn't share the namespace of the
module in which the models are defined. However, this is one of the
core pieces of magic that is going away in the magic-removal branch
we've been working on -- so that won't be the case for much longer.

For now, put the "from socket import..." within _pre_save().

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Importing stuff in your app's models module?

2005-12-21 Thread Aggelos Orfanakos

I recently wanted to tweak how a model was being saved, so I used the
_pre_save method of it. In the _pre_save method I needed to use the
gethostbyaddr and herror of the socket module. To my surprise, I got
problems [1] when having "from socket import gethostbyaddr, herror" in
module-level. It worked, however, when I moved the from ... import ...
statement *inside* the _pre_save method.

Is there a restriction on importing stuff in your app's models module?
And if yes, is there a reason for this?

Thanks!

[1]: From the debug output I got, it looked like Django was unable to
find gethostbyaddr and herror in the namespace. Like I had never
imported them?!



Re: downloadable django documentation?

2005-12-21 Thread Burhan

For the impatient, you can disable CSS in your browser and get a nice
'print friendly' version.



Re: SQL Injection

2005-12-21 Thread hugo

>They escape the string in the manner appropriate to the database
>backend being used. In the above case if you were using MySQL your
>string would become:

Actually they use the parameter binding way of doing it: they pass both
the SQL and a list of parameters to the DBAPI and so it's up to the
database driver to do the right thing.

bye, Georg