Re: Database management commands

2011-10-28 Thread Leonardo Giordani
You are right, thanks.

2011/10/28 Russell Keith-Magee :
> On Fri, Oct 28, 2011 at 12:49 AM, Leonardo Giordani
>  wrote:
>> This is a problem related to Innodb and MyISAM. Django uses this
>> latter,
>
> Incorrect. Django doesn't have any built in preference for InnoDB or
> MyISAM -- it uses the system default table type. On most systems,
> MyISAM is the default, but this isn't guaranteed or expected.
>
> Django supports both MyISAM and InnoDB table types, but the available
> feature set changes depending on the underlying table store.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Model Inheritance and ModelForms

2011-10-28 Thread Alex
I've been scouring Google and the Django documentation and I can't
figure out how to do this. I'm working on an inventory management
system for my shop. My inventory models.py similar to the following:

class ItemType( models.Model ):
def __unicode__( self ):
return "blah blah blah"

itemType = models.CharField( max_length = 32 )
isBook = models.BooleanField()

class InventoryItem( models.Model ):
def __unicode__( self ):
return "blah"

itemType = models.ForeignKey( ItemType )
description = models.CharField( max_length = 256 )

class InventoryBook( InventoryItem ):
def __unicode__( self ):
return "blah blah"

title = models.CharField( max_length = 64 )

In my web app, I create a ModelForm based on InventoryItem and present
that to the user. Upon submission, the POST data is used to create an
instance of InventoryItem. I then check to see if
inventoryItem.itemType.isBook() is True - if True, I want to cast
inventoryItem to an InventoryBook type so I can set the extra fields
and call save() so that it creates records in both tables in the MySQL
database.

I started trying to add a method to InventoryItem that would return an
InventoryBook instance after being given the title string, but that
doesn't work because Python doesn't have prototyping/forward
declarations.

Am I approaching this completely wrong, or am I just overlooking
something simple? Any advice or links to relevant documentation would
be *much* appreciated. Thanks!

-Alex

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



Django inline admin max_num, extra not working

2011-10-28 Thread Jose
I have extended the User model as explained here and in many other
sites.

However, when defining the User Profile Inline in admin.py, no matter
what values I use for max_num or extra, in the admin site it will
always show one inline for the user profile I have already created and
another blank one (User Profile #2).

The only way it does a difference is if I use extra=-1 in which case I
only get the blank form.

I have searched a lot in the Internet but found no solution. I am
using Django 1.2.3

I appreciate your help.

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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread angelika
Thank you all for your help and suggestions. Last time I installed
Django it took a full two days and I was nearly in tears at the end.
Most of the time was spend trying to solve the problems that Kurtis is
talking about, with the MySQLdb package. Although I am usually not a
person who takes shortcuts, this time I'm really looking for the
easiest way to just get the darn thing to work.

creecode, I tried the commands you suggested first. No matter which
version I switched to, it still said No module named django, which
seems weird but there it is. So I ran sudo easy_install django, just
to see if it could be that easy. When the install was done, it seemed
to work at first. I could run import django, no problem. I started the
tutorial on djangoproject.com and got as far as setting up a db and
running python manage.py runserver, before the dreaded
"django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No module named MySQLdb" started showing up. God damn it.

At this point I thinking maybe I should just switch to using
PostgreSQL instead, if that would solve the problem. What do you guys
think?

/Angelika

On Oct 27, 6:12 pm, Andre Terra  wrote:
> IMHO, If you can't understand how imports and sys.path work, it's best to
> put the Django book aside and read up on the basics of installing and
> running Python.
>
> Cheers,
> AT
>
>
>
>
>
>
>
> On Thu, Oct 27, 2011 at 1:55 PM, creecode  wrote:
> > Angelika may not want to get into virtualenv and virtualenvwrapper at this
> > point.  If you're just getting into Python/Django it may be more overhead
> > than you want to deal with conceptually at this time.  If your project is
> > simple or you're just learning then you may want to wait until you feel the
> > need for these tools.
>
> > Don't get me wrong these tools are fantastic and I use them myself!
>
> > Toodle-loo..
> > creecode
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/django-users/-/uzKtIhXl5qMJ.
>
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Database management commands

2011-10-28 Thread Daniele Procida
On Fri, Oct 28, 2011, Russell Keith-Magee  wrote:

>On Fri, Oct 28, 2011 at 12:49 AM, Leonardo Giordani
> wrote:
>> This is a problem related to Innodb and MyISAM. Django uses this
>> latter,
>
>Incorrect. Django doesn't have any built in preference for InnoDB or
>MyISAM -- it uses the system default table type. On most systems,
>MyISAM is the default, but this isn't guaranteed or expected.

COuld it still be the case that the issue is the result of the older Django 
database having used one engine by default, and the new one the other?

Daniele

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



Re: Django inline admin max_num, extra not working

2011-10-28 Thread Tom Evans
On Fri, Oct 28, 2011 at 9:47 AM, Jose  wrote:
> I have extended the User model as explained here and in many other
> sites.
>
> However, when defining the User Profile Inline in admin.py, no matter
> what values I use for max_num or extra, in the admin site it will
> always show one inline for the user profile I have already created and
> another blank one (User Profile #2).
>
> The only way it does a difference is if I use extra=-1 in which case I
> only get the blank form.
>
> I have searched a lot in the Internet but found no solution. I am
> using Django 1.2.3
>
> I appreciate your help.
>

What do you want to happen, just to have exactly the one user profile
inline for each user?

If you define the UserProfile as having a OneToOneField instead of a
ForeignKey, then that would happen by default.

Cheers

Tom

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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread Andre Terra
PostgreSQL is great, you will have no regrets!


Cheers,
AT

On Fri, Oct 28, 2011 at 6:13 AM, angelika  wrote:

> Thank you all for your help and suggestions. Last time I installed
> Django it took a full two days and I was nearly in tears at the end.
> Most of the time was spend trying to solve the problems that Kurtis is
> talking about, with the MySQLdb package. Although I am usually not a
> person who takes shortcuts, this time I'm really looking for the
> easiest way to just get the darn thing to work.
>
> creecode, I tried the commands you suggested first. No matter which
> version I switched to, it still said No module named django, which
> seems weird but there it is. So I ran sudo easy_install django, just
> to see if it could be that easy. When the install was done, it seemed
> to work at first. I could run import django, no problem. I started the
> tutorial on djangoproject.com and got as far as setting up a db and
> running python manage.py runserver, before the dreaded
> "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> module: No module named MySQLdb" started showing up. God damn it.
>
> At this point I thinking maybe I should just switch to using
> PostgreSQL instead, if that would solve the problem. What do you guys
> think?
>
> /Angelika
>
> On Oct 27, 6:12 pm, Andre Terra  wrote:
> > IMHO, If you can't understand how imports and sys.path work, it's best to
> > put the Django book aside and read up on the basics of installing and
> > running Python.
> >
> > Cheers,
> > AT
> >
> >
> >
> >
> >
> >
> >
> > On Thu, Oct 27, 2011 at 1:55 PM, creecode  wrote:
> > > Angelika may not want to get into virtualenv and virtualenvwrapper at
> this
> > > point.  If you're just getting into Python/Django it may be more
> overhead
> > > than you want to deal with conceptually at this time.  If your project
> is
> > > simple or you're just learning then you may want to wait until you feel
> the
> > > need for these tools.
> >
> > > Don't get me wrong these tools are fantastic and I use them myself!
> >
> > > Toodle-loo..
> > > creecode
> >
> > >  --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To view this discussion on the web visit
> > >https://groups.google.com/d/msg/django-users/-/uzKtIhXl5qMJ.
> >
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Model Inheritance and ModelForms

2011-10-28 Thread Tom Evans
On Fri, Oct 28, 2011 at 7:50 AM, Alex  wrote:
> I've been scouring Google and the Django documentation and I can't
> figure out how to do this. I'm working on an inventory management
> system for my shop. My inventory models.py similar to the following:
>
>    class ItemType( models.Model ):
>        def __unicode__( self ):
>            return "blah blah blah"
>
>        itemType = models.CharField( max_length = 32 )
>        isBook = models.BooleanField()
>
>    class InventoryItem( models.Model ):
>        def __unicode__( self ):
>            return "blah"
>
>        itemType = models.ForeignKey( ItemType )
>        description = models.CharField( max_length = 256 )
>
>    class InventoryBook( InventoryItem ):
>        def __unicode__( self ):
>            return "blah blah"
>
>        title = models.CharField( max_length = 64 )
>
> In my web app, I create a ModelForm based on InventoryItem and present
> that to the user. Upon submission, the POST data is used to create an
> instance of InventoryItem. I then check to see if
> inventoryItem.itemType.isBook() is True - if True, I want to cast
> inventoryItem to an InventoryBook type so I can set the extra fields
> and call save() so that it creates records in both tables in the MySQL
> database.
>
> I started trying to add a method to InventoryItem that would return an
> InventoryBook instance after being given the title string, but that
> doesn't work because Python doesn't have prototyping/forward
> declarations.
>
> Am I approaching this completely wrong, or am I just overlooking
> something simple? Any advice or links to relevant documentation would
> be *much* appreciated. Thanks!
>
> -Alex
>

If you have an InventoryItem which should be an InventoryBook, you
need to create the InventoryBook, not cast to it.

item = …
if item.itemType.isBook():
  book = InventoryBook.objects.create(inventoryitem=item, title=…)

Inheritance like this in django isn't really like OOO inheritance,
InventoryBook just magically gains a OneToOneField back to
InventoryItem called inventoryitem.

Cheers

Tom

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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread Kurtis Mullins
I'd give PostgreSQL a shot and see if it magically works for you. It's an
awesome database. If you have any problems with it though, here's the "easy
way out" I took. I just installed Mac Ports and never had another problem.
Of course, you'll have to make sure you're using the Mac Ports tools you
install (Python, easy_install/pip) and not the ones that come with OSX. More
information here:

http://www.macports.org/

Some of the packages you'll need include Python, setup tools, and the
MySQL-python connector. Let me know if you decide to go this route and I'll
be happy to help you along the way! There's also lots of good info that can
be found with google.

Good luck!

On Fri, Oct 28, 2011 at 5:47 AM, Andre Terra  wrote:

> PostgreSQL is great, you will have no regrets!
>
>
> Cheers,
> AT
>
>
> On Fri, Oct 28, 2011 at 6:13 AM, angelika wrote:
>
>> Thank you all for your help and suggestions. Last time I installed
>> Django it took a full two days and I was nearly in tears at the end.
>> Most of the time was spend trying to solve the problems that Kurtis is
>> talking about, with the MySQLdb package. Although I am usually not a
>> person who takes shortcuts, this time I'm really looking for the
>> easiest way to just get the darn thing to work.
>>
>> creecode, I tried the commands you suggested first. No matter which
>> version I switched to, it still said No module named django, which
>> seems weird but there it is. So I ran sudo easy_install django, just
>> to see if it could be that easy. When the install was done, it seemed
>> to work at first. I could run import django, no problem. I started the
>> tutorial on djangoproject.com and got as far as setting up a db and
>> running python manage.py runserver, before the dreaded
>> "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
>> module: No module named MySQLdb" started showing up. God damn it.
>>
>> At this point I thinking maybe I should just switch to using
>> PostgreSQL instead, if that would solve the problem. What do you guys
>> think?
>>
>> /Angelika
>>
>> On Oct 27, 6:12 pm, Andre Terra  wrote:
>> > IMHO, If you can't understand how imports and sys.path work, it's best
>> to
>> > put the Django book aside and read up on the basics of installing and
>> > running Python.
>> >
>> > Cheers,
>> > AT
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Thu, Oct 27, 2011 at 1:55 PM, creecode  wrote:
>> > > Angelika may not want to get into virtualenv and virtualenvwrapper at
>> this
>> > > point.  If you're just getting into Python/Django it may be more
>> overhead
>> > > than you want to deal with conceptually at this time.  If your project
>> is
>> > > simple or you're just learning then you may want to wait until you
>> feel the
>> > > need for these tools.
>> >
>> > > Don't get me wrong these tools are fantastic and I use them myself!
>> >
>> > > Toodle-loo..
>> > > creecode
>> >
>> > >  --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Django users" group.
>> > > To view this discussion on the web visit
>> > >https://groups.google.com/d/msg/django-users/-/uzKtIhXl5qMJ.
>> >
>> > > To post to this group, send email to django-users@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > django-users+unsubscr...@googlegroups.com.
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



CBV "Router"

2011-10-28 Thread Kurtis
Hey Guys,

I'm trying to create a "router" as recommended in IRC for several
different views. My Views are UpdateViews, so they are the new CBVs. I
don't mind my router being a simple function based view, though.

Basically, a User can edit some data. This data changes based upon the
user's "class" ... although when I say that, it's not programmatically
what I mean. A user can have a Band object, OR they can have a
Musician object, or later on there'll be more choices.

I want there to be one URL to edit that data. For example, they could
go to http://www.example.com/edit-profile and based upon what type of
an object the user has, they will be presented a specific ModelView.
So if the user goes to that URL and they are a Musician, they will be
presented my MusicianProfileUpdateView. If they are a Band, they will
be presented my BandProfileUpdatedView. And so forth

I'm just really not sure what the simplest way to do this is. My views
have quite a bit of custom logic and overrides so in a best case
scenario, I'd be able to do the following:

if Band.objects.filter(user = user).exists():
 return BandProfileUpdateView
elif Musician.objects.filter(user = user).exists():
return MusicianProfileUpdateView

Currently, I just give them different URLs but I think it's a horrible
approach from a User-experience point of view. I'm open to any
suggestions, and if it's something pretty complex then feel free to
throw in a short snippet example.

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: CBV "Router"

2011-10-28 Thread Kurtis Mullins
Nevermind! Thanks to FunkyBob, I have a solution. I didn't realize you could
do this so easily, so I'll share it with others.

# views.py
def my_router(request):
view = MyCBV.as_view(template_name = 'foo.html')
return view(request)

Of course, I actually have logic in my function -- but I'm sure you get the
point :)

On Fri, Oct 28, 2011 at 7:09 AM, Kurtis  wrote:

> Hey Guys,
>
> I'm trying to create a "router" as recommended in IRC for several
> different views. My Views are UpdateViews, so they are the new CBVs. I
> don't mind my router being a simple function based view, though.
>
> Basically, a User can edit some data. This data changes based upon the
> user's "class" ... although when I say that, it's not programmatically
> what I mean. A user can have a Band object, OR they can have a
> Musician object, or later on there'll be more choices.
>
> I want there to be one URL to edit that data. For example, they could
> go to http://www.example.com/edit-profile and based upon what type of
> an object the user has, they will be presented a specific ModelView.
> So if the user goes to that URL and they are a Musician, they will be
> presented my MusicianProfileUpdateView. If they are a Band, they will
> be presented my BandProfileUpdatedView. And so forth
>
> I'm just really not sure what the simplest way to do this is. My views
> have quite a bit of custom logic and overrides so in a best case
> scenario, I'd be able to do the following:
>
> if Band.objects.filter(user = user).exists():
> return BandProfileUpdateView
> elif Musician.objects.filter(user = user).exists():
>return MusicianProfileUpdateView
>
> Currently, I just give them different URLs but I think it's a horrible
> approach from a User-experience point of view. I'm open to any
> suggestions, and if it's something pretty complex then feel free to
> throw in a short snippet example.
>
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: create object instance with ManyToManyField

2011-10-28 Thread Jaroslav Dobrek
Hello Leonardo,

thanks your your answer.

> n = Company(name=my_name, country=my_country, isin=my_isin)
> n.save()
> n.indices.add(my_indices)

This causes that the company object has all indices in my_indices
(such as Dow Jones S&P 100, Dax, ...) as *choices*.  I.e. someone who
manipulates these objects via the admin interface is now able to
choose one or several of them and save the object again. What I want
to do is choose one or several of the indices in my program and then
save the object.

Jaroslav

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



Re: Django inline admin max_num, extra not working

2011-10-28 Thread Jose
Hi Tom,

Thanks for your reply.

Yes I want to have just one user profile.

And yes I have tried both OneToOne field and ForeignKey with
unique=True but it makes no difference in both cases I have this
problem

Regards,

José

On Oct 28, 11:41 am, Tom Evans  wrote:
> On Fri, Oct 28, 2011 at 9:47 AM, Jose  wrote:
> > I have extended the User model as explained here and in many other
> > sites.
>
> > However, when defining the User Profile Inline in admin.py, no matter
> > what values I use for max_num or extra, in the admin site it will
> > always show one inline for the user profile I have already created and
> > another blank one (User Profile #2).
>
> > The only way it does a difference is if I use extra=-1 in which case I
> > only get the blank form.
>
> > I have searched a lot in the Internet but found no solution. I am
> > using Django 1.2.3
>
> > I appreciate your help.
>
> What do you want to happen, just to have exactly the one user profile
> inline for each user?
>
> If you define the UserProfile as having a OneToOneField instead of a
> ForeignKey, then that would happen by default.
>
> Cheers
>
> Tom

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



changelist_view

2011-10-28 Thread kichawa
How can i call changelist_view from my_app.views ? I'd like to save the 
render html into the datebase.

i need sth like that: http://paste.ofcode.org/MVDJR2RhjnNL5QCBDVK3w6

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/XnRvo9ZuLIcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: create object instance with ManyToManyField

2011-10-28 Thread Leonardo Giordani
The add() method of a ManyToMany field adds the indexes of the given
objects to the field.
If you add a list, each index in the list is added to the field.

In the admin interface, when you edit a Company object, you see a
convenient automagically-created
menu which lists all Index object in your application, and there you
can add or remove them.

But you can add Indexes with the snipped I gave you; if you pass as
"my_indices" some of the
available Indexes and then edit the object through the admin interface
you'll see the ones you added
as selected (in blue).

*Choices* in the admin interface are build through an automatic query;
Django sees that you use a m2m field
and populates it with TheTypeYouReference.objects.all() . But this is
a service of the forms in the admin interface.
Django objects have nothing to do with "choices", they simply know
that you are attaching the index of some
other object to the object you are creating.

Feel free to ask again if the matter is not clear.


2011/10/28 Jaroslav Dobrek :
> Hello Leonardo,
>
> thanks your your answer.
>
>> n = Company(name=my_name, country=my_country, isin=my_isin)
>> n.save()
>> n.indices.add(my_indices)
>
> This causes that the company object has all indices in my_indices
> (such as Dow Jones S&P 100, Dax, ...) as *choices*.  I.e. someone who
> manipulates these objects via the admin interface is now able to
> choose one or several of them and save the object again. What I want
> to do is choose one or several of the indices in my program and then
> save the object.
>
> Jaroslav
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Hi all,

I'm trying to add a bit of jQuery to a page in a Django site. It seems
that my jQuery scripts are simply not loaded, while JS scripts work
perfectly.
Evan Firebug does not see the jQuery file as loaded.

This is what I do in base.html

   
       
       
       {% block javascript %}{% endblock %}

and in my page

{% block javascript %}


{% endblock %}

and my tabs.js is

$(document).ready(function() {
$('li').addClass("active");
}

If I edit jquery-1.6.4.js and add something as alert(), this works
perfectly. Other JS scripts work like a charm.

Any suggestion?

Thank you

Leo

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Andre Terra
Hello, Leonardo

First, which django version are you using? I recommend using the contrib
staticfiles app to handle your static files [1]. Once you get the hang of
it, it will pay off.

Second, see that you aren't getting 404 errors in the js URL. Using the dev
server, you can easily read through the status codes returned when loading a
view. A different solution (sometimes quicker) is hitting Ctrl+U in firefox
and clicking through the links in  to see the kind of errors you're
getting.

Finally, if none of that works you could try loading jQuery through the
Google Libraries Api [2]. Good luck!


Cheers,
AT

[1]
https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
[2] http://code.google.com/apis/libraries/devguide.html#jquery

On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Hi all,
>
> I'm trying to add a bit of jQuery to a page in a Django site. It seems
> that my jQuery scripts are simply not loaded, while JS scripts work
> perfectly.
> Evan Firebug does not see the jQuery file as loaded.
>
> This is what I do in base.html
>
>
> type="text/css">
>
>{% block javascript %}{% endblock %}
>
> and in my page
>
> {% block javascript %}
> 
> 
> {% endblock %}
>
> and my tabs.js is
>
> $(document).ready(function() {
>$('li').addClass("active");
> }
>
> If I edit jquery-1.6.4.js and add something as alert(), this works
> perfectly. Other JS scripts work like a charm.
>
> Any suggestion?
>
> Thank you
>
> Leo
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Hi, thank you for your detailed answer.

1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
for sure, thanks.
2. I'm getting no errors at all, other JS files in that directory load
perfectly. Firefox can reach them in source view.
3. I'll try it, but it seems to me strange not being able to load and
use jQuery as other JS scripts.

Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
error I cannot spot?

No one is experiencing the problem?

2011/10/28 Andre Terra :
> Hello, Leonardo
>
> First, which django version are you using? I recommend using the contrib
> staticfiles app to handle your static files [1]. Once you get the hang of
> it, it will pay off.
>
> Second, see that you aren't getting 404 errors in the js URL. Using the dev
> server, you can easily read through the status codes returned when loading a
> view. A different solution (sometimes quicker) is hitting Ctrl+U in firefox
> and clicking through the links in  to see the kind of errors you're
> getting.
>
> Finally, if none of that works you could try loading jQuery through the
> Google Libraries Api [2]. Good luck!
>
>
> Cheers,
> AT
>
> [1]
> https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
> [2] http://code.google.com/apis/libraries/devguide.html#jquery
>
> On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>  wrote:
>>
>> Hi all,
>>
>> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> that my jQuery scripts are simply not loaded, while JS scripts work
>> perfectly.
>> Evan Firebug does not see the jQuery file as loaded.
>>
>> This is what I do in base.html
>>
>>    
>>        > type="text/css">
>>        
>>        {% block javascript %}{% endblock %}
>>
>> and in my page
>>
>> {% block javascript %}
>> 
>> 
>> {% endblock %}
>>
>> and my tabs.js is
>>
>> $(document).ready(function() {
>>    $('li').addClass("active");
>> }
>>
>> If I edit jquery-1.6.4.js and add something as alert(), this works
>> perfectly. Other JS scripts work like a charm.
>>
>> Any suggestion?
>>
>> Thank you
>>
>> Leo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Andre Terra
I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
isn't being loaded, shouldn't you be getting a 404 error for the
jquery-1.6.4.js file?


Cheers,
AT

On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Hi, thank you for your detailed answer.
>
> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
> for sure, thanks.
> 2. I'm getting no errors at all, other JS files in that directory load
> perfectly. Firefox can reach them in source view.
> 3. I'll try it, but it seems to me strange not being able to load and
> use jQuery as other JS scripts.
>
> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
> error I cannot spot?
>
> No one is experiencing the problem?
>
> 2011/10/28 Andre Terra :
> > Hello, Leonardo
> >
> > First, which django version are you using? I recommend using the contrib
> > staticfiles app to handle your static files [1]. Once you get the hang of
> > it, it will pay off.
> >
> > Second, see that you aren't getting 404 errors in the js URL. Using the
> dev
> > server, you can easily read through the status codes returned when
> loading a
> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
> firefox
> > and clicking through the links in  to see the kind of errors you're
> > getting.
> >
> > Finally, if none of that works you could try loading jQuery through the
> > Google Libraries Api [2]. Good luck!
> >
> >
> > Cheers,
> > AT
> >
> > [1]
> >
> https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
> >
> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
> >  wrote:
> >>
> >> Hi all,
> >>
> >> I'm trying to add a bit of jQuery to a page in a Django site. It seems
> >> that my jQuery scripts are simply not loaded, while JS scripts work
> >> perfectly.
> >> Evan Firebug does not see the jQuery file as loaded.
> >>
> >> This is what I do in base.html
> >>
> >>
> >> >> type="text/css">
> >>
> >>{% block javascript %}{% endblock %}
> >>
> >> and in my page
> >>
> >> {% block javascript %}
> >> 
> >> 
> >> {% endblock %}
> >>
> >> and my tabs.js is
> >>
> >> $(document).ready(function() {
> >>$('li').addClass("active");
> >> }
> >>
> >> If I edit jquery-1.6.4.js and add something as alert(), this works
> >> perfectly. Other JS scripts work like a charm.
> >>
> >> Any suggestion?
> >>
> >> Thank you
> >>
> >> Leo
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/django-users?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
You are right, sorry.

jQuery is loaded, I can see it in Firefox and in Firebug.
If I write this statement

$(document).ready(function() {
}

in a working JS file, that file stops working, can be reached through
Firefox (it is loaded) but not by Firebug.


2011/10/28 Andre Terra :
> I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
> isn't being loaded, shouldn't you be getting a 404 error for the
> jquery-1.6.4.js file?
>
>
> Cheers,
> AT
>
> On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani
>  wrote:
>>
>> Hi, thank you for your detailed answer.
>>
>> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
>> for sure, thanks.
>> 2. I'm getting no errors at all, other JS files in that directory load
>> perfectly. Firefox can reach them in source view.
>> 3. I'll try it, but it seems to me strange not being able to load and
>> use jQuery as other JS scripts.
>>
>> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
>> error I cannot spot?
>>
>> No one is experiencing the problem?
>>
>> 2011/10/28 Andre Terra :
>> > Hello, Leonardo
>> >
>> > First, which django version are you using? I recommend using the contrib
>> > staticfiles app to handle your static files [1]. Once you get the hang
>> > of
>> > it, it will pay off.
>> >
>> > Second, see that you aren't getting 404 errors in the js URL. Using the
>> > dev
>> > server, you can easily read through the status codes returned when
>> > loading a
>> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
>> > firefox
>> > and clicking through the links in  to see the kind of errors
>> > you're
>> > getting.
>> >
>> > Finally, if none of that works you could try loading jQuery through the
>> > Google Libraries Api [2]. Good luck!
>> >
>> >
>> > Cheers,
>> > AT
>> >
>> > [1]
>> >
>> > https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
>> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
>> >
>> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>> >  wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> >> that my jQuery scripts are simply not loaded, while JS scripts work
>> >> perfectly.
>> >> Evan Firebug does not see the jQuery file as loaded.
>> >>
>> >> This is what I do in base.html
>> >>
>> >>    
>> >>        > >> type="text/css">
>> >>        
>> >>        {% block javascript %}{% endblock %}
>> >>
>> >> and in my page
>> >>
>> >> {% block javascript %}
>> >> 
>> >> 
>> >> {% endblock %}
>> >>
>> >> and my tabs.js is
>> >>
>> >> $(document).ready(function() {
>> >>    $('li').addClass("active");
>> >> }
>> >>
>> >> If I edit jquery-1.6.4.js and add something as alert(), this works
>> >> perfectly. Other JS scripts work like a charm.
>> >>
>> >> Any suggestion?
>> >>
>> >> Thank you
>> >>
>> >> Leo
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Sorry Andy and thank for your patience,

as I though the problem is simply simply bad JQuery.

$(document).ready(function() {
   $('li').addClass("active");
}

what about some ");" to close statements?

Thanks

2011/10/28 Andre Terra :
> I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
> isn't being loaded, shouldn't you be getting a 404 error for the
> jquery-1.6.4.js file?
>
>
> Cheers,
> AT
>
> On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani
>  wrote:
>>
>> Hi, thank you for your detailed answer.
>>
>> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
>> for sure, thanks.
>> 2. I'm getting no errors at all, other JS files in that directory load
>> perfectly. Firefox can reach them in source view.
>> 3. I'll try it, but it seems to me strange not being able to load and
>> use jQuery as other JS scripts.
>>
>> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
>> error I cannot spot?
>>
>> No one is experiencing the problem?
>>
>> 2011/10/28 Andre Terra :
>> > Hello, Leonardo
>> >
>> > First, which django version are you using? I recommend using the contrib
>> > staticfiles app to handle your static files [1]. Once you get the hang
>> > of
>> > it, it will pay off.
>> >
>> > Second, see that you aren't getting 404 errors in the js URL. Using the
>> > dev
>> > server, you can easily read through the status codes returned when
>> > loading a
>> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
>> > firefox
>> > and clicking through the links in  to see the kind of errors
>> > you're
>> > getting.
>> >
>> > Finally, if none of that works you could try loading jQuery through the
>> > Google Libraries Api [2]. Good luck!
>> >
>> >
>> > Cheers,
>> > AT
>> >
>> > [1]
>> >
>> > https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
>> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
>> >
>> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>> >  wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> >> that my jQuery scripts are simply not loaded, while JS scripts work
>> >> perfectly.
>> >> Evan Firebug does not see the jQuery file as loaded.
>> >>
>> >> This is what I do in base.html
>> >>
>> >>    
>> >>        > >> type="text/css">
>> >>        
>> >>        {% block javascript %}{% endblock %}
>> >>
>> >> and in my page
>> >>
>> >> {% block javascript %}
>> >> 
>> >> 
>> >> {% endblock %}
>> >>
>> >> and my tabs.js is
>> >>
>> >> $(document).ready(function() {
>> >>    $('li').addClass("active");
>> >> }
>> >>
>> >> If I edit jquery-1.6.4.js and add something as alert(), this works
>> >> perfectly. Other JS scripts work like a charm.
>> >>
>> >> Any suggestion?
>> >>
>> >> Thank you
>> >>
>> >> Leo
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread angelika
Alright, I'm gonna give PostgreSQL a try over the weekend, I'll let
you know how it works out.
Thanks, guys!
/Angelika

On Oct 28, 12:49 pm, Kurtis Mullins  wrote:
> I'd give PostgreSQL a shot and see if it magically works for you. It's an
> awesome database. If you have any problems with it though, here's the "easy
> way out" I took. I just installed Mac Ports and never had another problem.
> Of course, you'll have to make sure you're using the Mac Ports tools you
> install (Python, easy_install/pip) and not the ones that come with OSX. More
> information here:
>
> http://www.macports.org/
>
> Some of the packages you'll need include Python, setup tools, and the
> MySQL-python connector. Let me know if you decide to go this route and I'll
> be happy to help you along the way! There's also lots of good info that can
> be found with google.
>
> Good luck!
>
>
>
>
>
>
>
> On Fri, Oct 28, 2011 at 5:47 AM, Andre Terra  wrote:
> > PostgreSQL is great, you will have no regrets!
>
> > Cheers,
> > AT
>
> > On Fri, Oct 28, 2011 at 6:13 AM, angelika wrote:
>
> >> Thank you all for your help and suggestions. Last time I installed
> >> Django it took a full two days and I was nearly in tears at the end.
> >> Most of the time was spend trying to solve the problems that Kurtis is
> >> talking about, with the MySQLdb package. Although I am usually not a
> >> person who takes shortcuts, this time I'm really looking for the
> >> easiest way to just get the darn thing to work.
>
> >> creecode, I tried the commands you suggested first. No matter which
> >> version I switched to, it still said No module named django, which
> >> seems weird but there it is. So I ran sudo easy_install django, just
> >> to see if it could be that easy. When the install was done, it seemed
> >> to work at first. I could run import django, no problem. I started the
> >> tutorial on djangoproject.com and got as far as setting up a db and
> >> running python manage.py runserver, before the dreaded
> >> "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> >> module: No module named MySQLdb" started showing up. God damn it.
>
> >> At this point I thinking maybe I should just switch to using
> >> PostgreSQL instead, if that would solve the problem. What do you guys
> >> think?
>
> >> /Angelika
>
> >> On Oct 27, 6:12 pm, Andre Terra  wrote:
> >> > IMHO, If you can't understand how imports and sys.path work, it's best
> >> to
> >> > put the Django book aside and read up on the basics of installing and
> >> > running Python.
>
> >> > Cheers,
> >> > AT
>
> >> > On Thu, Oct 27, 2011 at 1:55 PM, creecode  wrote:
> >> > > Angelika may not want to get into virtualenv and virtualenvwrapper at
> >> this
> >> > > point.  If you're just getting into Python/Django it may be more
> >> overhead
> >> > > than you want to deal with conceptually at this time.  If your project
> >> is
> >> > > simple or you're just learning then you may want to wait until you
> >> feel the
> >> > > need for these tools.
>
> >> > > Don't get me wrong these tools are fantastic and I use them myself!
>
> >> > > Toodle-loo..
> >> > > creecode
>
> >> > >  --
> >> > > You received this message because you are subscribed to the Google
> >> Groups
> >> > > "Django users" group.
> >> > > To view this discussion on the web visit
> >> > >https://groups.google.com/d/msg/django-users/-/uzKtIhXl5qMJ.
>
> >> > > To post to this group, send email to django-users@googlegroups.com.
> >> > > To unsubscribe from this group, send email to
> >> > > django-users+unsubscr...@googlegroups.com.
> >> > > For more options, visit this group at
> >> > >http://groups.google.com/group/django-users?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread creecode
Hello Angelika,

On Friday, October 28, 2011 2:13:20 AM UTC-7, angelika wrote:

creecode, I tried the commands you suggested first. No matter which 
> version I switched to, it still said No module named django, which 
> seems weird but there it is.


If your curious about where the old Django install may have gotten to you 
could try on the command line...

sudo find -x / -name django -print

So I ran sudo easy_install django, just 
> to see if it could be that easy. When the install was done, it seemed 
> to work at first. I could run import django, no problem. I started the 
> tutorial on djangoproject.com and got as far as setting up a db and 
> running python manage.py runserver, before the dreaded 
> "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb 
> module: No module named MySQLdb" started showing up. God damn it.
>

If you are just doing local development for learning I think you can bypass 
the database install, at least that is what the Django Quick Install docs 
indicate.

At this point I thinking maybe I should just switch to using 
> PostgreSQL instead, if that would solve the problem. What do you guys 
> think?


You could give it a go but if you're just wanting to get through the 
tutorial is does seem like overkill.  I've just tried installing Postgres 
on Mac OS X for the first time and it wasn't smooth sailing by any means.  
Part of the issues were related to installing the Postgres server on an 
older OS version and hardware.  I did install psycopg2 on recent hardware 
with current Lion and a fair amount of hair pulling.  psycopg2 is a 
connector so that Django, through Python, will be able to talk to a 
Postgres server.  It does the same job that MySQLdb does for MySQL.

Toodle-loo.
creecode

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/efYSJuk-DIwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help in adding jQuery to my pages

2011-10-28 Thread Andre Terra
Oh, that's right! Too often I miss the closing );, especially when *reading*
code.

It's very unfortunate javascript didn't have someone like Guido van Rossum
as BDFL. Life for web developers would surely be easier if it too were
developed with "be as readable as English" as a goal.

Glad to know you got it sorted out.

Take care!

AT

On Fri, Oct 28, 2011 at 12:13 PM, Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Sorry Andy and thank for your patience,
>
> as I though the problem is simply simply bad JQuery.
>
> $(document).ready(function() {
>   $('li').addClass("active");
> }
>
> what about some ");" to close statements?
>
> Thanks
>
> 2011/10/28 Andre Terra :
> > I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
> > isn't being loaded, shouldn't you be getting a 404 error for the
> > jquery-1.6.4.js file?
> >
> >
> > Cheers,
> > AT
> >
> > On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani
> >  wrote:
> >>
> >> Hi, thank you for your detailed answer.
> >>
> >> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
> >> for sure, thanks.
> >> 2. I'm getting no errors at all, other JS files in that directory load
> >> perfectly. Firefox can reach them in source view.
> >> 3. I'll try it, but it seems to me strange not being able to load and
> >> use jQuery as other JS scripts.
> >>
> >> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
> >> error I cannot spot?
> >>
> >> No one is experiencing the problem?
> >>
> >> 2011/10/28 Andre Terra :
> >> > Hello, Leonardo
> >> >
> >> > First, which django version are you using? I recommend using the
> contrib
> >> > staticfiles app to handle your static files [1]. Once you get the hang
> >> > of
> >> > it, it will pay off.
> >> >
> >> > Second, see that you aren't getting 404 errors in the js URL. Using
> the
> >> > dev
> >> > server, you can easily read through the status codes returned when
> >> > loading a
> >> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
> >> > firefox
> >> > and clicking through the links in  to see the kind of errors
> >> > you're
> >> > getting.
> >> >
> >> > Finally, if none of that works you could try loading jQuery through
> the
> >> > Google Libraries Api [2]. Good luck!
> >> >
> >> >
> >> > Cheers,
> >> > AT
> >> >
> >> > [1]
> >> >
> >> >
> https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
> >> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
> >> >
> >> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
> >> >  wrote:
> >> >>
> >> >> Hi all,
> >> >>
> >> >> I'm trying to add a bit of jQuery to a page in a Django site. It
> seems
> >> >> that my jQuery scripts are simply not loaded, while JS scripts work
> >> >> perfectly.
> >> >> Evan Firebug does not see the jQuery file as loaded.
> >> >>
> >> >> This is what I do in base.html
> >> >>
> >> >>
> >> >> >> >> type="text/css">
> >> >>
> >> >>{% block javascript %}{% endblock %}
> >> >>
> >> >> and in my page
> >> >>
> >> >> {% block javascript %}
> >> >>  type="text/javascript">
> >> >> 
> >> >> {% endblock %}
> >> >>
> >> >> and my tabs.js is
> >> >>
> >> >> $(document).ready(function() {
> >> >>$('li').addClass("active");
> >> >> }
> >> >>
> >> >> If I edit jquery-1.6.4.js and add something as alert(), this works
> >> >> perfectly. Other JS scripts work like a charm.
> >> >>
> >> >> Any suggestion?
> >> >>
> >> >> Thank you
> >> >>
> >> >> Leo
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >> Groups
> >> >> "Django users" group.
> >> >> To post to this group, send email to django-users@googlegroups.com.
> >> >> To unsubscribe from this group, send email to
> >> >> django-users+unsubscr...@googlegroups.com.
> >> >> For more options, visit this group at
> >> >> http://groups.google.com/group/django-users?hl=en.
> >> >>
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Django users" group.
> >> > To post to this group, send email to django-users@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/django-users?hl=en.
> >> >
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/django-users?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-us

update other objects when saving an object:

2011-10-28 Thread Tim
Hi,
I've modeled a Book that has Chapters, with each Chapter having an ordering 
'sequence'. 
So when someone decides the first chapter in the book should become the 
third, they can just change the sequence number.
That's fine, but when that happens, I want the other chapters to 
automatically change their sequence to reflect the change.

To accomplish this I thought I could add a custom 'save' method to my 
Chapter model, but I get the message:
'Manager isn't accessible via ChapterMembership instances'

My code seems straightforward enough:

class ChapterMembership(models.Model):
chapter = models.ForeignKey(Chapter, blank=True, null=True)
book = models.ForeignKey(Book, blank=True, null=True)
sequence = models.PositiveIntegerField()

def save(self):
chapters = self.objects.filter(book=self.book) # get all instances 
for the related book
sequences = [x.sequence for x in chapters] # a list of all the 
sequence numbers
if self.sequence in sequences: #if we have a duplicate sequence 
take care of it
for chapter in chapters: 
if self.sequence == chapter.sequence:
chapter.sequence = chapter.sequence + 1
chapter.save() # makes this a recursive method
super(ChapterMembership, self).save()

I suppose I'm missing something basic, but I haven't seen an example like 
this in my searches.
Can anyone see what I'm doing wrong?
thanks,
--Tim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Aq-9KyCuDHEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Comparing two ManyToMany fields for same entries

2011-10-28 Thread Kevin
Hello,

  I am building a model which shares a relation with another model
using a ManyToManyField.  What I need to do, is find out which models
are on both on two seperate ManyToManyField lists.  Here is a simple
example of what I am trying to do:

Person:
  friends=ManyToManyField(self)

To find out this persons direct friends, Person.friends...
To find out which friends this Person shares in common with another
Person, 

Person0:
  Person1
  Person6
  Person3
  Person8

Person1:
  Person2
  Person6

What would be the most optimized QuerySet to find out that both
Person0 and Person1 are both friends with Person6?

Is there a specific Django app perhaps that can ease develop of this
type of data relations between objects?

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database management commands

2011-10-28 Thread Ian Clelland
On Fri, Oct 28, 2011 at 2:35 AM, Daniele Procida  wrote:

> COuld it still be the case that the issue is the result of the older Django
> database having used one engine by default, and the new one the other?
>
>
That is possible -- in a MySQL shell, run "SHOW TABLE STATUS", and you can
see the engine used by all of your tables.


-- 
Regards,
Ian Clelland


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



Re: No module named django after upgrade to os x Lion

2011-10-28 Thread Kurtis
Okay, I think I've got the exact steps down needed to get this running
right. If these are actually it, I'm not sure if I had any other
prerequisites I can't think of at the moment, then it's a matter of
copying and pasting 3 lines into your terminal. (Less than 5-10
minutes total)

1. Install "Brew" (http://mxcl.github.com/homebrew/)
2. Use Brew to Install mysql-connector-c
3. Install MySQL-python

Open up your terminal and follow these steps. If you are unsure of
anything during the process, then feel free to read more information
on what these are. Google is your friend here :)

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install mysql-connector-c
sudo easy_install mysql-python

Hopefully that works for you! Good luck.

On Oct 28, 12:19 pm, creecode  wrote:
> Hello Angelika,
>
> On Friday, October 28, 2011 2:13:20 AM UTC-7, angelika wrote:
>
> creecode, I tried the commands you suggested first. No matter which
>
> > version I switched to, it still said No module named django, which
> > seems weird but there it is.
>
> If your curious about where the old Django install may have gotten to you
> could try on the command line...
>
> sudo find -x / -name django -print
>
> So I ran sudo easy_install django, just
>
> > to see if it could be that easy. When the install was done, it seemed
> > to work at first. I could run import django, no problem. I started the
> > tutorial on djangoproject.com and got as far as setting up a db and
> > running python manage.py runserver, before the dreaded
> > "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No module named MySQLdb" started showing up. God damn it.
>
> If you are just doing local development for learning I think you can bypass
> the database install, at least that is what the Django Quick Install docs
> indicate.
>
> At this point I thinking maybe I should just switch to using
>
> > PostgreSQL instead, if that would solve the problem. What do you guys
> > think?
>
> You could give it a go but if you're just wanting to get through the
> tutorial is does seem like overkill.  I've just tried installing Postgres
> on Mac OS X for the first time and it wasn't smooth sailing by any means.  
> Part of the issues were related to installing the Postgres server on an
> older OS version and hardware.  I did install psycopg2 on recent hardware
> with current Lion and a fair amount of hair pulling.  psycopg2 is a
> connector so that Django, through Python, will be able to talk to a
> Postgres server.  It does the same job that MySQLdb does for MySQL.
>
> Toodle-loo.
> creecode

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



Re: Comparing two ManyToMany fields for same entries

2011-10-28 Thread Kevin
Just thought I'd add another example using Python script:

Person0 = Person()
Person1 = Person()
Person2 = Person()
Person0.friends.add(Person2)
Person2.friends.add(Person0)
Person2.friends.add(Person1)
Person1.friends.add(Person2)

Now, I would like to do the following, but it seems to fail:

Person0.friends.all() in Person1.friends.all().  I would like it to
say if Person0 and Person1 share another friend in common.

Person0 and Person2 are friends
Person1 and Person2 are friends
Person0 and Person1 are NOT friends, but share a friend in common.
How does one find out that even though Person0 and Person1 are not
friends, they do share Person2 as a friend.

I can use my eye on a Python shell to see that Person2 exists on both
Peson0 and Person1, but how does one make the code see it?

Sorry for having to clarify this so much, I'm just not sure that my
last post actually explained it properly.

Thanks.

On Oct 28, 12:30 pm, Kevin  wrote:
> Hello,
>
>   I am building a model which shares a relation with another model
> using a ManyToManyField.  What I need to do, is find out which models
> are on both on two seperate ManyToManyField lists.  Here is a simple
> example of what I am trying to do:
>
> Person:
>   friends=ManyToManyField(self)
>
> To find out this persons direct friends, Person.friends...
> To find out which friends this Person shares in common with another
> Person, 
>
> Person0:
>   Person1
>   Person6
>   Person3
>   Person8
>
> Person1:
>   Person2
>   Person6
>
> What would be the most optimized QuerySet to find out that both
> Person0 and Person1 are both friends with Person6?
>
> Is there a specific Django app perhaps that can ease develop of this
> type of data relations between objects?
>
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to load data to auth_permissions from initial_data.json when the auth_groups is also loaded from fixture?

2011-10-28 Thread ycseattle
Hi, 

In my application, I have fixed groups (like admin, staff, subscribers) 
etc, and this data in auth_groups is not intended to change in the program, 
so I am loading them in initial_data.json. I also want to load data into 
auth_group_permissions as the application is not expected to change it. The 
problem is that I noticed the table auth_permissions is generated by 
Django, so the permissions IDs will be dynamic (especially when I add new 
models as it seems the permissions are ordered by the model names). Is 
there a way to load my definition of group permissions through 
initial_data.json, or am I stuck with running a piece of code to do this? 

Thanks,
Yi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/D1x0zXQVzAcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Long usernames in auth_user?

2011-10-28 Thread Ian Clelland
On Wed, Oct 26, 2011 at 3:00 PM, Kurtis Mullins wrote:

> Check out userena as well. But a custom authentication back-end was the
> approach I originally took. And to answer your question, yes -- your chances
> of finding people w/ email addresses longer than 75 chars are less than
> finding people w/ 30 chars -- but still a limitation none-the-less as there
> is no limitation on how long an email address can be.
>
>
Not quite correct -- from RFC-3696:

   In addition to restrictions on syntax, there is a length limit on
   email addresses.  That limit is a maximum of 64 characters (octets)
   in the "local part" (before the "@") and a maximum of 255 characters
   (octets) in the domain part (after the "@") for a total length of 320
   characters.  Systems that handle email should be prepared to process
   addresses which are that long, even though they are rarely
   encountered.

320 characters suffices for any valid email address.


-- 
Regards,
Ian Clelland


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



Re: Comparing two ManyToMany fields for same entries

2011-10-28 Thread Brett Epps
Try this:

for friendof0 in Person0.friends.all():
for friendof1 in Person1.friends.all():
if friendof0 == friendof1:
# Person 0 and Person 1 share a friend.
else:
# They have no shared friends.

Brett


On 10/28/11 12:59 PM, "Kevin"  wrote:

>Just thought I'd add another example using Python script:
>
>Person0 = Person()
>Person1 = Person()
>Person2 = Person()
>Person0.friends.add(Person2)
>Person2.friends.add(Person0)
>Person2.friends.add(Person1)
>Person1.friends.add(Person2)
>
>Now, I would like to do the following, but it seems to fail:
>
>Person0.friends.all() in Person1.friends.all().  I would like it to
>say if Person0 and Person1 share another friend in common.
>
>Person0 and Person2 are friends
>Person1 and Person2 are friends
>Person0 and Person1 are NOT friends, but share a friend in common.
>How does one find out that even though Person0 and Person1 are not
>friends, they do share Person2 as a friend.
>
>I can use my eye on a Python shell to see that Person2 exists on both
>Peson0 and Person1, but how does one make the code see it?
>
>Sorry for having to clarify this so much, I'm just not sure that my
>last post actually explained it properly.
>
>Thanks.
>
>On Oct 28, 12:30 pm, Kevin  wrote:
>> Hello,
>>
>>   I am building a model which shares a relation with another model
>> using a ManyToManyField.  What I need to do, is find out which models
>> are on both on two seperate ManyToManyField lists.  Here is a simple
>> example of what I am trying to do:
>>
>> Person:
>>   friends=ManyToManyField(self)
>>
>> To find out this persons direct friends, Person.friends...
>> To find out which friends this Person shares in common with another
>> Person, 
>>
>> Person0:
>>   Person1
>>   Person6
>>   Person3
>>   Person8
>>
>> Person1:
>>   Person2
>>   Person6
>>
>> What would be the most optimized QuerySet to find out that both
>> Person0 and Person1 are both friends with Person6?
>>
>> Is there a specific Django app perhaps that can ease develop of this
>> type of data relations between objects?
>>
>> 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-users@googlegroups.com.
>To unsubscribe from this group, send email to
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

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



Re: update other objects when saving an object:

2011-10-28 Thread Brett Epps
Hi Tim,

The problem is your use of the self keyword when trying to get at the 
ChapterMembership manager.  Instead of:

chapters = self.objects.filter…

Try:

chapters = ChapterMembership.objects.filter…

Hope that helps,

Brett

From: Tim mailto:jtim.arn...@gmail.com>>
Reply-To: mailto:django-users@googlegroups.com>>
Date: Fri, 28 Oct 2011 10:03:42 -0700
To: mailto:django-users@googlegroups.com>>
Subject: update other objects when saving an object:

Hi,
I've modeled a Book that has Chapters, with each Chapter having an ordering 
'sequence'.
So when someone decides the first chapter in the book should become the third, 
they can just change the sequence number.
That's fine, but when that happens, I want the other chapters to automatically 
change their sequence to reflect the change.

To accomplish this I thought I could add a custom 'save' method to my Chapter 
model, but I get the message:
'Manager isn't accessible via ChapterMembership instances'

My code seems straightforward enough:

class ChapterMembership(models.Model):
chapter = models.ForeignKey(Chapter, blank=True, null=True)
book = models.ForeignKey(Book, blank=True, null=True)
sequence = models.PositiveIntegerField()

def save(self):
chapters = self.objects.filter(book=self.book) # get all instances for 
the related book
sequences = [x.sequence for x in chapters] # a list of all the sequence 
numbers
if self.sequence in sequences: #if we have a duplicate sequence take 
care of it
for chapter in chapters:
if self.sequence == chapter.sequence:
chapter.sequence = chapter.sequence + 1
chapter.save() # makes this a recursive method
super(ChapterMembership, self).save()

I suppose I'm missing something basic, but I haven't seen an example like this 
in my searches.
Can anyone see what I'm doing wrong?
thanks,
--Tim



--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Aq-9KyCuDHEJ.
To post to this group, send email to 
django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

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



Re: Comparing two ManyToMany fields for same entries

2011-10-28 Thread Kevin
Thanks.  Is this way good for database optimization though?  I guess I
could use select_related().  I was hoping there was a QuerySet I could
run.

I made this one, although I'm not sure if it works correctly:

Person.objects.filter(name='Person1').filter(friends__friends__name='Person0')
This outputs "Person1", if I interchange Person0 with Person2, it
outputs no results.  If I use Person1 in both instances, it outputs
'Person1'.
Does this QuerySet return the results I want, or should I use Brett's
suggestion?

Thanks again.

On Oct 28, 1:21 pm, Brett Epps  wrote:
> Try this:
>
> for friendof0 in Person0.friends.all():
>     for friendof1 in Person1.friends.all():
>         if friendof0 == friendof1:
>             # Person 0 and Person 1 share a friend.
>         else:
>             # They have no shared friends.
>
> Brett
>
> On 10/28/11 12:59 PM, "Kevin"  wrote:
>
> >Just thought I'd add another example using Python script:
>
> >Person0 = Person()
> >Person1 = Person()
> >Person2 = Person()
> >Person0.friends.add(Person2)
> >Person2.friends.add(Person0)
> >Person2.friends.add(Person1)
> >Person1.friends.add(Person2)
>
> >Now, I would like to do the following, but it seems to fail:
>
> >Person0.friends.all() in Person1.friends.all().  I would like it to
> >say if Person0 and Person1 share another friend in common.
>
> >Person0 and Person2 are friends
> >Person1 and Person2 are friends
> >Person0 and Person1 are NOT friends, but share a friend in common.
> >How does one find out that even though Person0 and Person1 are not
> >friends, they do share Person2 as a friend.
>
> >I can use my eye on a Python shell to see that Person2 exists on both
> >Peson0 and Person1, but how does one make the code see it?
>
> >Sorry for having to clarify this so much, I'm just not sure that my
> >last post actually explained it properly.
>
> >Thanks.
>
> >On Oct 28, 12:30 pm, Kevin  wrote:
> >> Hello,
>
> >>   I am building a model which shares a relation with another model
> >> using a ManyToManyField.  What I need to do, is find out which models
> >> are on both on two seperate ManyToManyField lists.  Here is a simple
> >> example of what I am trying to do:
>
> >> Person:
> >>   friends=ManyToManyField(self)
>
> >> To find out this persons direct friends, Person.friends...
> >> To find out which friends this Person shares in common with another
> >> Person, 
>
> >> Person0:
> >>   Person1
> >>   Person6
> >>   Person3
> >>   Person8
>
> >> Person1:
> >>   Person2
> >>   Person6
>
> >> What would be the most optimized QuerySet to find out that both
> >> Person0 and Person1 are both friends with Person6?
>
> >> Is there a specific Django app perhaps that can ease develop of this
> >> type of data relations between objects?
>
> >> 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-users@googlegroups.com.
> >To unsubscribe from this group, send email to
> >django-users+unsubscr...@googlegroups.com.
> >For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Comparing two ManyToMany fields for same entries

2011-10-28 Thread Kevin
I think the filter I used does work to detect related friends, here is
a Pythonic example of the same code, but done differently without
filters:

Person.objects.get(name='Person1').friends.get().friends.all()

Instead of returning back 'Person1', when using filters, this returns
back 'Person0'.

Person.objects.get(name='Sean').friends.get().friends.get(name='Person0')

My next question, which would be better optimized for database hits:

* Brett's example
* using the filter version
* using the Pythonic version, but use select_related(depth=2) option?

I am trying to make sure the database hits are optimized as this will
be queries multiple times per page hit for different models.  Also,
which would be faster to make sure the page loads are not burden when
lots of these types of queries go through?

Thanks.

On Oct 28, 1:34 pm, Kevin  wrote:
> Thanks.  Is this way good for database optimization though?  I guess I
> could use select_related().  I was hoping there was a QuerySet I could
> run.
>
> I made this one, although I'm not sure if it works correctly:
>
> Person.objects.filter(name='Person1').filter(friends__friends__name='Person0')
> This outputs "Person1", if I interchange Person0 with Person2, it
> outputs no results.  If I use Person1 in both instances, it outputs
> 'Person1'.
> Does this QuerySet return the results I want, or should I use Brett's
> suggestion?
>
> Thanks again.
>
> On Oct 28, 1:21 pm, Brett Epps  wrote:
>
> > Try this:
>
> > for friendof0 in Person0.friends.all():
> >     for friendof1 in Person1.friends.all():
> >         if friendof0 == friendof1:
> >             # Person 0 and Person 1 share a friend.
> >         else:
> >             # They have no shared friends.
>
> > Brett
>
> > On 10/28/11 12:59 PM, "Kevin"  wrote:
>
> > >Just thought I'd add another example using Python script:
>
> > >Person0 = Person()
> > >Person1 = Person()
> > >Person2 = Person()
> > >Person0.friends.add(Person2)
> > >Person2.friends.add(Person0)
> > >Person2.friends.add(Person1)
> > >Person1.friends.add(Person2)
>
> > >Now, I would like to do the following, but it seems to fail:
>
> > >Person0.friends.all() in Person1.friends.all().  I would like it to
> > >say if Person0 and Person1 share another friend in common.
>
> > >Person0 and Person2 are friends
> > >Person1 and Person2 are friends
> > >Person0 and Person1 are NOT friends, but share a friend in common.
> > >How does one find out that even though Person0 and Person1 are not
> > >friends, they do share Person2 as a friend.
>
> > >I can use my eye on a Python shell to see that Person2 exists on both
> > >Peson0 and Person1, but how does one make the code see it?
>
> > >Sorry for having to clarify this so much, I'm just not sure that my
> > >last post actually explained it properly.
>
> > >Thanks.
>
> > >On Oct 28, 12:30 pm, Kevin  wrote:
> > >> Hello,
>
> > >>   I am building a model which shares a relation with another model
> > >> using a ManyToManyField.  What I need to do, is find out which models
> > >> are on both on two seperate ManyToManyField lists.  Here is a simple
> > >> example of what I am trying to do:
>
> > >> Person:
> > >>   friends=ManyToManyField(self)
>
> > >> To find out this persons direct friends, Person.friends...
> > >> To find out which friends this Person shares in common with another
> > >> Person, 
>
> > >> Person0:
> > >>   Person1
> > >>   Person6
> > >>   Person3
> > >>   Person8
>
> > >> Person1:
> > >>   Person2
> > >>   Person6
>
> > >> What would be the most optimized QuerySet to find out that both
> > >> Person0 and Person1 are both friends with Person6?
>
> > >> Is there a specific Django app perhaps that can ease develop of this
> > >> type of data relations between objects?
>
> > >> 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-users@googlegroups.com.
> > >To unsubscribe from this group, send email to
> > >django-users+unsubscr...@googlegroups.com.
> > >For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

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



Admin Custom Template

2011-10-28 Thread Vishnu vg
Hi Django guys,

I want to customize an admin form. I heard that we can customize django
admin template by putting template file called template change_list.html in
template folder. My model is like this cms.model.application. So for the
application model how can i create custom templates in admin. Please help me

-- 
Regards

Vishnu V.G
Software Programmer/ IT Consultant
Mobile : 9544455735

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



Re: update other objects when saving an object:

2011-10-28 Thread Tim
Hi Brian,
That helps indeed! The code is working now; seems like I need to work on 
the logic, but now I'm getting somewhere.

thanks,
--Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/wfnEAcgtri0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Comparing two ManyToMany fields for same entries

2011-10-28 Thread Brett Epps
I'm going to guess that my version is slow since a new query would be run
for each row returned by the initial one.

Check out an app called django-debug-toolbar.  It has a view that will
show you all of the SQL queries generated as a page is built.  It will
also tell you how long each query took to run.  This should allow you to
compare the three methods.

Brett


On 10/28/11 1:44 PM, "Kevin"  wrote:

>I think the filter I used does work to detect related friends, here is
>a Pythonic example of the same code, but done differently without
>filters:
>
>Person.objects.get(name='Person1').friends.get().friends.all()
>
>Instead of returning back 'Person1', when using filters, this returns
>back 'Person0'.
>
>Person.objects.get(name='Sean').friends.get().friends.get(name='Person0')
>
>My next question, which would be better optimized for database hits:
>
>* Brett's example
>* using the filter version
>* using the Pythonic version, but use select_related(depth=2) option?
>
>I am trying to make sure the database hits are optimized as this will
>be queries multiple times per page hit for different models.  Also,
>which would be faster to make sure the page loads are not burden when
>lots of these types of queries go through?
>
>Thanks.
>
>On Oct 28, 1:34 pm, Kevin  wrote:
>> Thanks.  Is this way good for database optimization though?  I guess I
>> could use select_related().  I was hoping there was a QuerySet I could
>> run.
>>
>> I made this one, although I'm not sure if it works correctly:
>>
>> 
>>Person.objects.filter(name='Person1').filter(friends__friends__name='Pers
>>on0')
>> This outputs "Person1", if I interchange Person0 with Person2, it
>> outputs no results.  If I use Person1 in both instances, it outputs
>> 'Person1'.
>> Does this QuerySet return the results I want, or should I use Brett's
>> suggestion?
>>
>> Thanks again.
>>
>> On Oct 28, 1:21 pm, Brett Epps  wrote:
>>
>> > Try this:
>>
>> > for friendof0 in Person0.friends.all():
>> > for friendof1 in Person1.friends.all():
>> > if friendof0 == friendof1:
>> > # Person 0 and Person 1 share a friend.
>> > else:
>> > # They have no shared friends.
>>
>> > Brett
>>
>> > On 10/28/11 12:59 PM, "Kevin"  wrote:
>>
>> > >Just thought I'd add another example using Python script:
>>
>> > >Person0 = Person()
>> > >Person1 = Person()
>> > >Person2 = Person()
>> > >Person0.friends.add(Person2)
>> > >Person2.friends.add(Person0)
>> > >Person2.friends.add(Person1)
>> > >Person1.friends.add(Person2)
>>
>> > >Now, I would like to do the following, but it seems to fail:
>>
>> > >Person0.friends.all() in Person1.friends.all().  I would like it to
>> > >say if Person0 and Person1 share another friend in common.
>>
>> > >Person0 and Person2 are friends
>> > >Person1 and Person2 are friends
>> > >Person0 and Person1 are NOT friends, but share a friend in common.
>> > >How does one find out that even though Person0 and Person1 are not
>> > >friends, they do share Person2 as a friend.
>>
>> > >I can use my eye on a Python shell to see that Person2 exists on both
>> > >Peson0 and Person1, but how does one make the code see it?
>>
>> > >Sorry for having to clarify this so much, I'm just not sure that my
>> > >last post actually explained it properly.
>>
>> > >Thanks.
>>
>> > >On Oct 28, 12:30 pm, Kevin  wrote:
>> > >> Hello,
>>
>> > >>   I am building a model which shares a relation with another model
>> > >> using a ManyToManyField.  What I need to do, is find out which
>>models
>> > >> are on both on two seperate ManyToManyField lists.  Here is a
>>simple
>> > >> example of what I am trying to do:
>>
>> > >> Person:
>> > >>   friends=ManyToManyField(self)
>>
>> > >> To find out this persons direct friends, Person.friends...
>> > >> To find out which friends this Person shares in common with another
>> > >> Person, 
>>
>> > >> Person0:
>> > >>   Person1
>> > >>   Person6
>> > >>   Person3
>> > >>   Person8
>>
>> > >> Person1:
>> > >>   Person2
>> > >>   Person6
>>
>> > >> What would be the most optimized QuerySet to find out that both
>> > >> Person0 and Person1 are both friends with Person6?
>>
>> > >> Is there a specific Django app perhaps that can ease develop of
>>this
>> > >> type of data relations between objects?
>>
>> > >> 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-users@googlegroups.com.
>> > >To unsubscribe from this group, send email to
>> > >django-users+unsubscr...@googlegroups.com.
>> > >For more options, visit this group at
>> > >http://groups.google.com/group/django-users?hl=en.
>
>-- 
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To post to this group, send email to django-users@googlegroups.com.
>To unsubscribe from this group, send email to
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group 

CacheMiddleware with generation-style caching

2011-10-28 Thread jonathan
Hi all,

I'm trying to implement a generation-style caching system with django
[1].  I found django-jimmypage [2] which implements an alternative
version of @cache_page, and it uses johnny-cache [3] for an "infinite"
cache timeout.  However, most of the code in django-jimmypage appears
quite similar to what we've got in the default CacheMiddleware, so I'm
trying to implement this without jimmypage by making the following
minor tweaks:

1) Update settings.py to use the johnny backend for infinite-timeout
support and instruct the cache to use a custom key function:

CACHES = {
'default': {
'BACKEND': 'johnny.backends.filebased.FileBasedCache',
'LOCATION': 'c:\cache',
'KEY_FUNCTION': 'utils.cache.make_key',
'TIMEOUT': 0
}
}

CACHE_GENERATION_KEY = 'generation'

2) Write a custom key function to include the "generation" in the key:

def make_key(key, key_prefix, version):
from django.conf import settings
from django.core.cache.backends.base import default_key_func

if key != settings.CACHE_GENERATION_KEY:
from django.core.cache import cache
return default_key_func(key, key_prefix,
str(cache.get(settings.CACHE_GENERATION_KEY, 1)) + '.' + str(version))
else:
return default_key_func(key, key_prefix, version)

3) Connect to some signals to increment the generation:

def new_cache_generation(sender, **kwargs):
from django.conf import settings
from django.core.cache import cache
try:
cache.incr(settings.CACHE_GENERATION_KEY)
except ValueError:
cache.set(settings.CACHE_GENERATION_KEY, 1)

from django.db.models.signals import post_save, pre_delete
post_save.connect(new_cache_generation)
pre_delete.connect(new_cache_generation)

So far, this part works quite well--no crazy hacking of django. :)

However, my trouble is with CACHE_MIDDLEWARE_SECONDS.  From what I can
tell, CACHE_MIDDLEWARE_SECONDS defines *both* the cache timeout *and*
the HTTP headers.  For my purposes, this means that if I set
CACHE_MIDDLEWARE_SECONDS = 0 (meaning I want an infinite cache), then
the HTTP Cache-Control headers include max-age=0 which is not what I
want.  I'd prefer to define the cache timeout via the cache's TIMEOUT
field, and define the Cache-Control via CACHE_MIDDLEWARE_SECONDS.
'Course, if a view explicitly uses @cache_page() to define a non-
infinite (non-zero) custom timeout, then that timeout should
reasonably impact both the cache timeout and the Cache-Control.

So my question is: does it seem reasonable for me to tweak django to
only use CACHE_MIDDLEWARE_SECONDS for the Cache-Control headers?
Obviously, I can make this change locally, but I'd like to know if I'm
missing something and if this change has any chance of making it
upstream. :)

Thanks!

Jonathan

[1]
http://assets.en.oreilly.com/1/event/27/Accelerate%20your%20Rails%20Site%20with%20Automatic%20Generation-based%20Action%20Caching%20Presentation%201.pdf
[2] https://github.com/yourcelf/django-jimmypage
[3] http://packages.python.org/johnny-cache/

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



Django Standalone Template

2011-10-28 Thread Stefan Lisowski
Hi Django folks -

I'm new to Django, and I just want to use the template system now,
independent of the rest of Django. But I can't get it to see a
template. Even the system templates as was suggested when I started
Googling for my error.

>>> import django.template
>>> django.conf.settings.configure(TEMPLATE_DIRS=('C:/Python26/Lib/site-packages/django/contrib/admin/templates/admin'),TEMPLATE_DEBUG=True,
>>>  DEBUG=True)
>>> import django.template.loader as loader
>>> loader.get_template("base.html")
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python26\lib\site-packages\django\template\loader.py", line
157, in get_template
template, origin = find_template(template_name)
  File "c:\python26\lib\site-packages\django\template\loader.py", line
138, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: base.html
>>> exit()
C:\Program Files (x86)\Microsoft Visual Studio 8\VC>ls C:/Python26/Lib/
site-packages/django/contrib/admin/templates/admin | grep base
base.html
base_site.html

Any ideas?

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