Accessing Child Meta Attributes from Abstract Model Class

2009-08-31 Thread Brett Epps

Hi,

I've got an abstract base class like this:

class Base(models.Model):

class Meta:
abstract = True

def save(self, *args, **kwargs):
print dir(self.Meta)
super(Base, self).save(*args, **kwargs)

and a child model class inheriting from it like this:

class Child(Base):

class Meta:
verbose_name_plural = "children"

When save() is called on an instance of Child, Base.save() prints the
attributes of Base.Meta instead of Child.Meta (as I may be wrongly
expecting).  I have tried changing Child.Meta to extend from Base.Meta
with the same result.

So far, the workaround seems to be to use self._meta in Base.save()
instead of self.Meta, which allows me to access the attributes of
Child.Meta.  I've noticed that the django-mptt project (on Google
Code) does this.  Is this the correct way for a base class to access a
child class's Meta attributes?

Brett

--~--~-~--~~~---~--~~
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.core.handlers.wsgi not found

2012-02-04 Thread Brett Epps
Sometimes it can help to print sys.path in your WSGI file.  (The output
should end up in the apache error log.)  That should tell you where Python
is looking for modules.  If the Django install path is not listed, you may
need to reinstall Django.

How was Django installed originally?

Brett


On 2/4/12 6:53 PM, "larry.mart...@gmail.com" 
wrote:

>I am trying to deploy my django app on a newly setup CentOS box. I
>have successfully deployed it on ubuntu and on a Mac.
>
>I get these errors in the apache error log:
>
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1] mod_wsgi
>(pid=13616): Target WSGI script '/usr/local/myapp/scripts/myapp.wsgi'
>cannot be loaded as Python module.
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1] mod_wsgi
>(pid=13616): Exception occurred processing WSGI script '/usr/local/
>myapp/scripts/myapp.wsgi'.
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1] Traceback (most
>recent call last):
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1]   File "/usr/
>local/myapp/scripts/myapp.wsgi", line 8, in 
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1] import
>django.core.handlers.wsgi
>[Sat Feb 04 17:43:28 2012] [error] [client 127.0.0.1] ImportError: No
>module named django.core.handlers.wsgi
>
>
>From command line python the import works:
>
>$ python
>Python 2.6.6 (r266:84292, Dec  7 2011, 20:38:36)
>[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
 import django.core.handlers.wsgi

>
>
>I also have this warning in the apache log:
>
>[Sat Feb 04 17:41:12 2012] [warn] mod_wsgi: Compiled for Python/2.6.2.
>[Sat Feb 04 17:41:12 2012] [warn] mod_wsgi: Runtime using Python/
>2.6.6.
>
>
>I've checked permissions, and wsgi.py and every dir in the path to it
>is 755.
>
>Anyone know why my app isn't finding it?
>
>TIA!
>-larry
>
>-- 
>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: Dynamic settings variables (dynamic global variable)

2012-02-08 Thread Brett Epps
I'd recommend caching the data using Django's caching framework and either
the local memory or memcached backend.  To update the cache, write a
management command that runs periodically as a cron job.  (If you find
yourself needing more sophisticated background task management, check out
Celery.)

Brett


On 2/8/12 4:14 PM, "bfrederi"  wrote:

>I have some data that I retrieve using urllib and then cache on a
>different server that I frequently use through my site. Since it gets
>used so frequently, I was wondering why it might be a good/bad idea to
>make the urllib request in the settings.py. It's data that gets
>changed infrequently, but should update every once in a while, but I'd
>prefer that it stayed in local memory as much as possible, since it
>gets used so much. Any advice on how to make a dynamic global variable
>like that is much appreciated.
>
>Thanks,
>Brandon
>
>-- 
>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: Django setup on Win7 - can't import some things

2012-02-13 Thread Brett Epps
Hi Bob,

It sounds like you're using the 1.3 or later version of the tutorial.
Class-based generic views were added in 1.3.  Try this link for the
correct version:

https://docs.djangoproject.com/en/1.2/intro/tutorial01/

(Note the 1.2 in the URL.)

Hope that helps,

Brett


On 2/13/12 10:35 AM, "LostInTheTrees"  wrote:

>I am trying to get started with Django and having some trouble. I'm
>using Django 1.2 to reserve the ability to go to Google's app engine
>if I want. I have python 2.7 installed and working on Win7. I
>unstalled Django 1.2 using the install script and it copied Django
>into the site-packages directory.
>
>I have been working through the tutorial and am just about finished.
>However, in the last step, the tutorial uses generic views. When I run
>it, I get "cannot import name DetailView". The import command,
>straight from the tutorial is "from django.views.generic import
>DetailView, ListView".
>
>Early on, I could not execute django-admin.py. I had already installed
>PIL and I had read about *.pth files in .../site-packages/*. So I
>created a file django.pth. In it I put the single line "django\bin".
>After this, django-admin.py could be easily executed.
>
>Do I have to add more lines to django.pth? Is there something else I
>missed?
>
>-Bob
>
>-- 
>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: What is the simplest way to install MySQL-python on Lion 10.7 with Xcode 4.3?

2012-02-27 Thread Brett Epps
I think your problem might be solved in this SO post:

http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loade
d-libmysqlclient-18-dylib

By the way, I'd highly recommend using Homebrew instead of MacPorts and
pip/virtualenv instead of sudo easy_install.

Brett


On 2/27/12 2:01 PM, "Bryan"  wrote:

>I am setting up Python and Django on os X 10.7 from a virgin install
>and Xcode 4.3.
>
>I tried using the default install of Python:
>/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
>
>$ sudo easy_install MySQL-python
>Searching for MySQL-python
>Reading http://pypi.python.org/simple/MySQL-python/
>Reading http://sourceforge.net/projects/mysql-python/
>Reading http://sourceforge.net/projects/mysql-python
>Best match: MySQL-python 1.2.3
>Downloading 
>http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.
>3.tar.gz
>Processing MySQL-python-1.2.3.tar.gz
>Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/
>easy_install-da_8kh/MySQL-python-1.2.3/egg-dist-tmp-CA6FMW
>warning: no files found matching 'MANIFEST'
>warning: no files found matching 'ChangeLog'
>warning: no files found matching 'GPL'
>In file included from _mysql.c:36:
>/usr/local/mysql/include/my_config.h:329:1: warning: "SIZEOF_SIZE_T"
>redefined
>In file included from /System/Library/Frameworks/Python.framework/
>Versions/2.7/include/python2.7/Python.h:9,
> from pymemcompat.h:10,
> from _mysql.c:29:
>/System/Library/Frameworks/Python.framework/Versions/2.7/include/
>python2.7/pymacconfig.h:43:1: warning: this is the location of the
>previous definition
>In file included from _mysql.c:36:
>/usr/local/mysql/include/my_config.h:422:1: warning: "HAVE_WCSCOLL"
>redefined
>In file included from /System/Library/Frameworks/Python.framework/
>Versions/2.7/include/python2.7/Python.h:8,
> from pymemcompat.h:10,
> from _mysql.c:29:
>/System/Library/Frameworks/Python.framework/Versions/2.7/include/
>python2.7/pyconfig.h:891:1: warning: this is the location of the
>previous definition
>_mysql.c: In function Œ_mysql_server_init¹:
>_mysql.c:253: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:278: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_ResultObject_Initialize¹:
>_mysql.c:405: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_escape_string¹:
>_mysql.c:986: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:988: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_string_literal¹:
>_mysql.c:1016: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:1025: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:1027: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_escape_sequence¹:
>_mysql.c:: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_row_to_dict¹:
>_mysql.c:1298: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:1300: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c: In function Œ_mysql_row_to_dict_old¹:
>_mysql.c:1336: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>_mysql.c:1338: warning: implicit conversion shortens 64-bit value into
>a 32-bit value
>zip_safe flag not set; analyzing archive contents...
>Adding MySQL-python 1.2.3 to easy-install.pth file
>
>Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-
>macosx-10.7-intel.egg
>Processing dependencies for MySQL-python
>Finished processing dependencies for MySQL-python
>#
>
>When I tried to run the server, I got the following Traceback:
>Traceback (most recent call last):
>  File "/Users/Bryan/work/osqa/forum_modules/mysqlfulltext/
>__init__.py", line 8, in 
>import MySQLdb
>  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line
>19, in 
>  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in
>
>  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in
>__bootstrap__
>ImportError: dlopen(/Users/Bryan/.python-eggs/MySQL_python-1.2.3-py2.7-
>macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded:
>libmysqlclient.18.dylib
>  Referenced from: /Users/Bryan/.python-eggs/MySQL_python-1.2.3-py2.7-
>macosx-10.7-intel.egg-tmp/_mysql.so
>  Reason: image not found
>Traceback (most recent call last):
>  File "/Users/Bryan/work/osqa/forum_modules/mysqlfulltext/
>__init__.py", line 8, in 
>import MySQLdb
>  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line
>19, in 
>  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in
>
>  File "build/bdist.macosx-10.7-intel/eg

Re: How to generate common blocks?

2012-02-27 Thread Brett Epps
Consider writing custom template tags for the common parts (assuming
they're dynamic).

https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/

Brett


On 2/27/12 2:25 PM, "Paul"  wrote:

>I have a question regarding the use of the template mechanism.
>
>Say i'm using a common website layout with header, footer and in the
>center three columns. Only the center is specific to the request (so
>the specific view function will generate the center block), i'm not
>sure however what the best way is to generate the common blocks in the
>side bars. Lets say i want to have multiple blocks with dynamic
>contents (such as a random selected review or frequently searched
>items). I guess is can call specific functions to generate the common
>blocks but i would have to do so for each view function? This doesn't
>make sense to me because quickly blocks will be generated that are not
>actually used; would it be possible to do something smart? Like
>specifying block-functions inside the template code?
>
>Many thanks for any directions!
>
>Paul
>
>-- 
>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: Looking for a job in the Arctic Circle

2011-09-30 Thread Brett Epps
Might be too warm or too far south for you, but consider Wisconsin.  We get 
plenty of snow here.

Brett

From: Kevin Renskers mailto:i...@bolhoed.net>>
Reply-To: mailto:django-users@googlegroups.com>>
Date: Fri, 30 Sep 2011 06:27:30 -0700
To: mailto:django-users@googlegroups.com>>
Cc: <2...@weholt.org>
Subject: Re: Looking for a job in the Arctic Circle

I don't think many people will ever understand why I'd want to move to the 
Arctic region. But, I really don't understand how many people would like to 
live in Spain, France or Italy. Me, I like long, cold winters with lots of 
snow. I don't like hot summers. I'm just weird I guess :)

Reykjavik and Tromsø are not that cold by the way. Reykjavik has an average low 
of minus 3 in january, Tromsø minus 7.

--
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/-/I00h3_up_a8J.
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: Simple input forms which show more than one row - easy/possible in django?

2011-10-05 Thread Brett Epps
Hi Chris,

Once you've defined a model for your data, you can use a ModelForm [1] to
automatically generate a form for that model.

You might also want to check out the admin site [2], which displays data
in a tabular format similar to what you describe.

1. https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
2. https://docs.djangoproject.com/en/dev/ref/contrib/admin/

Brett


On 10/5/11 9:44 AM, "Chris G"  wrote:

>I want to create a simple data entry form on a web page that shows all
>the columns of a database across the page (there aren't many columns,
>they will fit!) and a number of rows down the page.
>
>I.e. I want a data entry form that looks like MS Access 'tabular'
>format, as follows:-
>
>Col1Row1Col2Row1Col3Row1Col4Row1Col5Row1
>Col1Row2Col2Row2Col3Row2Col4Row2Col5Row2
>Col1Row3Col2Row3Col3Row3Col4Row3Col5Row3
>Col1Row4Col2Row4Col3Row4Col4Row4Col5Row4
>Col1Row5Col2Row5Col3Row5Col4Row5Col5Row5
>Col1Row6Col2Row6Col3Row6Col4Row6Col5Row6
>New DataNew DataNew DataNew DataNew Data
>
>
>Can django do this easily in a 'ready made' sort of way or do I have to
>actually create the form and all its fields?
>
>-- 
>Chris Green
>
>-- 
>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: Combining Querysets from different, but similar models

2011-10-05 Thread Brett Epps
I had a similar need and solved it with a separate table of activity feed
items.  Here's the code for the Item model:

class Item(models.Model):

object_id = models.PositiveIntegerField(db_index=True)
content_type = models.ForeignKey(ContentType)
content_object = generic.GenericForeignKey('content_type', 'object_id')
...
[your common feed item fields go here]

Then I ensured that each model that could show up in the activity feed
added a new Item object in its save() method.  The result is that you can
pull the feed with one query, which could help a lot if you're mashing
together several models.  The downside is that you need to make sure the
items table stays in sync with the data from the models it is merging
together.


Brett


On 10/5/11 8:37 AM, "Steven Smith"  wrote:

>I'm working on a site that has a requirement for a "recent activity"
>feed on the homepage. Usually, I'd just do a MyFoo.objects.order_by('-
>created') and all would be well. But "activity" is actually from
>several models. They all have some fields in common, like the
>timestamp, since they all have the same abstract base class, but
>they're definitely different things.
>
>What's the cheapest way to do my queries and mix the results into one
>feed? Ideally, the name of the model, or some other differentiating
>attribute would be exposed so that I can use it in my template loop as
>a style hook. Models in question are below...
>
>
>class TrackableModel(models.Model):
>created = models.DateTimeField(auto_now_add=True)
>modified = models.DateTimeField(auto_now=True)
>created_by = models.ForeignKey(User, blank=True, null=True)
>history = models.TextField(blank=True)
>notes = models.TextField(blank=True)
>is_active = models.BooleanField(blank=True, default=True)
>
>class Meta:
>abstract = True
>
>
>class Review(TrackableModel):
>book = models.ForeignKey('Textbook')
>course = models.ForeignKey('TaughtCourse', blank=True, null=True)
>should_buy = models.BooleanField(blank=True)
>rating_prep = models.DecimalField(blank=True, null=True,
>max_digits=2, decimal_places=1)
>rating_hw = models.DecimalField(blank=True, null=True,
>max_digits=2, decimal_places=1)
>rating_inclass = models.DecimalField(blank=True, null=True,
>max_digits=2, decimal_places=1)
>can_share = models.BooleanField(blank=True, default=True)
>comments = models.TextField(blank=True)
>
>
>class MarketplacePosting(TrackableModel):
>book = models.ForeignKey('Textbook', blank=True, null=True)
>school = models.ForeignKey('School', blank=True, null=True)
>location = models.CharField(max_length=255, blank=True,
>verbose_name="Sale location")
>condition = models.CharField(max_length=15, blank=True,
>choices=CONDITION_CHOICES)
>contains_highlighting = models.BooleanField(blank=True)
>price = models.DecimalField(blank=True, null=True, max_digits=6,
>decimal_places=2)
>comments = models.TextField(blank=True)
>is_sold = models.BooleanField(blank=True)
>
>-- 
>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: Registering a model in the admin

2011-10-05 Thread Brett Epps
Could you show us the contents of your admin.py file?  Did you remember to
call admin.site.register(ModelClass, ModelClassAdmin) for that model?

Brett


On 10/5/11 6:09 AM, "Haffi"  wrote:

>Hi, I'm registering a new model in the admin but it just won't show
>up. I'm doing this in production, I added the model to models.py and
>mirrored the changes in the DB. I registered it in admin.py just as
>all the other models and restarted Apache but it won't show up and if
>I try the URL it's supposed to be in I just get a permission denied
>error. 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.
>

-- 
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: encrypt and decrypt data in django.

2011-10-05 Thread Brett Epps
Hi Nghia,

The common pattern is to extend django.contrib.auth.models.User by creating 
your own "profile" model with the fields you need [1].  Then you can set the 
AUTH_PROFILE_MODULE setting and access the profile from User objects through 
the User.get_profile method.  The Python standard library has modules related 
to encryption [2].

  1.  
https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
  2.  http://docs.python.org/library/crypto.html

Hope that helps,

Brett

From: Le Huu Nghia mailto:lehuunghi...@gmail.com>>
Reply-To: mailto:django-users@googlegroups.com>>
Date: Wed, 5 Oct 2011 19:34:39 +0800
To: mailto:django-users@googlegroups.com>>
Subject: encrypt and decrypt data in django.

Dear All,

i want to create a table to store information of user ,
That includes (username , password, ...)  this table must be diffrent from 
admin table.
(ex some personal info so on)

can you give me an advice which lib of django to encrypt and decrypt , look 
like the table admin of django.

Thanks a lot.
Nghia


--
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: setting site-name variable

2011-10-05 Thread Brett Epps
Which "site-name" variable are you referring to?  Usually you'll want to
place global settings in your settings.py file.  Then you can access them
elsewhere like this:

from django.conf import settings
print settings.[name of setting]

Also, you might be interested in the sites framework [1], which is useful
for running multiple websites using the same Django project.

1. https://docs.djangoproject.com/en/dev/ref/contrib/sites/

Brett


On 10/5/11 12:14 AM, "ANU"  wrote:

>1. Can one set "site-name" variable in __init__.py file? How?
>2. Is there any method to set globally "site-name" variable so that in
>the app, no further setting for this variable is needed?
>
>-- 
>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: memcached not working with django

2011-10-07 Thread Brett Epps
Have you configured Django to use memcached in your CACHES setting?  If
so, can you post that?  Also, what are you caching?

Brett


On 10/7/11 8:10 AM, "tino"  wrote:

>Hello,
>
>I am trying to implement memcached on my django site.
># telnet localhost 11211
>Trying 127.0.0.1...
>Connected to localhost.localdomain (127.0.0.1).
>Escape character is '^]'.
>stats
>STAT pid 22537
>STAT uptime 31523
>STAT time 1317992962
>STAT version 1.4.5
>STAT pointer_size 64
>STAT rusage_user 0.00
>STAT rusage_system 0.00
>STAT curr_connections 10
>STAT total_connections 41
>STAT connection_structures 11
>STAT cmd_get 0
>STAT cmd_set 0
>STAT cmd_flush 0
>STAT get_hits 0
>STAT get_misses 0
>STAT delete_misses 0
>STAT delete_hits 0
>STAT incr_misses 0
>STAT incr_hits 0
>STAT decr_misses 0
>STAT decr_hits 0
>STAT cas_misses 0
>STAT cas_hits 0
>STAT cas_badval 0
>STAT auth_cmds 0
>STAT auth_errors 0
>STAT bytes_read 190
>STAT bytes_written 23756
>STAT limit_maxbytes 67108864
>STAT accepting_conns 1
>STAT listen_disabled_num 0
>STAT threads 4
>STAT conn_yields 0
>STAT bytes 0
>STAT curr_items 0
>STAT total_items 0
>STAT evictions 0
>STAT reclaimed 0
>END
>
>As you can see the cmd_get value is 0 in telnet stats. Can anybody
>please advice?
>
>-- 
>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: memcached not working with django

2011-10-07 Thread Brett Epps
Disregard my reply, I see that you solved your problem already.  (I missed
the rest of the thread until now.)

Brett


On 10/7/11 10:40 AM, "Brett Epps"  wrote:

>Have you configured Django to use memcached in your CACHES setting?  If
>so, can you post that?  Also, what are you caching?
>
>Brett
>
>
>On 10/7/11 8:10 AM, "tino"  wrote:
>
>>Hello,
>>
>>I am trying to implement memcached on my django site.
>># telnet localhost 11211
>>Trying 127.0.0.1...
>>Connected to localhost.localdomain (127.0.0.1).
>>Escape character is '^]'.
>>stats
>>STAT pid 22537
>>STAT uptime 31523
>>STAT time 1317992962
>>STAT version 1.4.5
>>STAT pointer_size 64
>>STAT rusage_user 0.00
>>STAT rusage_system 0.00
>>STAT curr_connections 10
>>STAT total_connections 41
>>STAT connection_structures 11
>>STAT cmd_get 0
>>STAT cmd_set 0
>>STAT cmd_flush 0
>>STAT get_hits 0
>>STAT get_misses 0
>>STAT delete_misses 0
>>STAT delete_hits 0
>>STAT incr_misses 0
>>STAT incr_hits 0
>>STAT decr_misses 0
>>STAT decr_hits 0
>>STAT cas_misses 0
>>STAT cas_hits 0
>>STAT cas_badval 0
>>STAT auth_cmds 0
>>STAT auth_errors 0
>>STAT bytes_read 190
>>STAT bytes_written 23756
>>STAT limit_maxbytes 67108864
>>STAT accepting_conns 1
>>STAT listen_disabled_num 0
>>STAT threads 4
>>STAT conn_yields 0
>>STAT bytes 0
>>STAT curr_items 0
>>STAT total_items 0
>>STAT evictions 0
>>STAT reclaimed 0
>>END
>>
>>As you can see the cmd_get value is 0 in telnet stats. Can anybody
>>please advice?
>>
>>-- 
>>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 with implementing dynamic views/models

2011-10-10 Thread Brett Epps
I may be misunderstanding your question, but it sounds like you need to
use Page.objects.get or Page.objects.filter (in your view function) to
look up the particular objects that you want to send to the template.

Brett


On 10/10/11 9:53 AM, "xenses"  wrote:

>This may seem like a very simple question and I have just missed the
>answer in the piles of documentation and tutorials that I've read over
>the past two days. I'm new to Django and trying to implement an
>internal site at work, and I'm the only Python/Django person we have,
>so this is all on me.
>
>What I am doing is this: I have a set of .html files, templates, which
>are named testn.html (i.e. test1.html, test2.html, etc) Each template
>extends base.html, but they each have at least 2 divs that I need to
>populate with HTML that is entered in the admin interface and stored
>in the Page model. What I need to do is this:
>
>from the url parse what test is being requested:
>
>url(r'^test(\d{1})/$', test),
>
>cal the test view:
>
>def test(request, testn):
>try:
>testn = str(testn)
>return direct_to_template(request, template="test%s.html" %
>testn)
>except ValueError:
>raise Http404()
>
>And then return the template, but with the correct object attached to
>it, filtered by name.  I can't find a way to do this, all that I can
>find are ways that make me grab all the objects (and where do I do
>this? In models.py or views.py? There are conflicting thoughts on
>this). I really just need to grab the one object, and if it has the
>fields I need, to populate the template with them. Is there an easy
>way to do this that won't require me to loop over all objects?
>
>Thank you so much for any help or insight!
>--Laura C.
>
>-- 
>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 with implementing dynamic views/models

2011-10-10 Thread Brett Epps
The direct_to_template() function can take an extra_context keyword
argument (a dict). So:

direct_to_template(request, template='blah.html', extra_context={'foo':
bar})

Would let you use {{ foo }} in a template to output the value of the
variable bar.

By the way, as a replacement for direct_to_template, there's
django.shortcuts.render [1], which is a little more concise.  (Usually,
you use direct_to_template in urls.py, since it is a full-fledged generic
view function.)

1. 
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcu
ts.render

Hope that helps,


Brett


On 10/10/11 12:21 PM, "xenses"  wrote:

>That is exactly what I want to do, I can't seem to understand exactly
>how to implement that and have it populate in the template. Do I just
>define the variable in the views and then in the template use
>{{ variable_name }} where I need it? Because I tried that first and it
>didn't work. So, maybe I'm just not sure what it is I'm doing
>exactly ;)
>
>Thanks for any help!
>
>On Oct 10, 1:09 pm, Brett Epps  wrote:
>> I may be misunderstanding your question, but it sounds like you need to
>> use Page.objects.get or Page.objects.filter (in your view function) to
>> look up the particular objects that you want to send to the template.
>>
>> Brett
>>
>> On 10/10/11 9:53 AM, "xenses"  wrote:
>>
>>
>>
>>
>>
>>
>>
>> >This may seem like a very simple question and I have just missed the
>> >answer in the piles of documentation and tutorials that I've read over
>> >the past two days. I'm new to Django and trying to implement an
>> >internal site at work, and I'm the only Python/Django person we have,
>> >so this is all on me.
>>
>> >What I am doing is this: I have a set of .html files, templates, which
>> >are named testn.html (i.e. test1.html, test2.html, etc) Each template
>> >extends base.html, but they each have at least 2 divs that I need to
>> >populate with HTML that is entered in the admin interface and stored
>> >in the Page model. What I need to do is this:
>>
>> >from the url parse what test is being requested:
>>
>> >url(r'^test(\d{1})/$', test),
>>
>> >cal the test view:
>>
>> >def test(request, testn):
>> >try:
>> >testn = str(testn)
>> >return direct_to_template(request, template="test%s.html" %
>> >testn)
>> >except ValueError:
>> >raise Http404()
>>
>> >And then return the template, but with the correct object attached to
>> >it, filtered by name.  I can't find a way to do this, all that I can
>> >find are ways that make me grab all the objects (and where do I do
>> >this? In models.py or views.py? There are conflicting thoughts on
>> >this). I really just need to grab the one object, and if it has the
>> >fields I need, to populate the template with them. Is there an easy
>> >way to do this that won't require me to loop over all objects?
>>
>> >Thank you so much for any help or insight!
>> >--Laura C.
>>
>> >--
>> >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 with implementing dynamic views/models

2011-10-11 Thread Brett Epps
Try it with {'page': page} as your extra_context. The keys in a context
dict should always be strings.

Brett


On 10/11/11 8:29 AM, "xenses"  wrote:

>I thank you for your help and apologize for my naivete, however I
>still am not seeing that tag populate in the template. Here is my view
>function in its entirety:
>
> def test(request, testn):
>try:
>testn = str(testn)
>page = Page.objects.filter(name = "test%s" % testn)
>return direct_to_template(request, template="test%s.html" %
>testn, extra_context={page:page})
>except ValueError:
>raise Http404()
>
>I am using {page:page} because anything else returns errors in debug
>mode.
>in my template I have :
>
>{{ page.leaderboard }}
>
>the page object looks like this:
>
>class Page(models.Model):
>name = models.CharField(max_length=25, verbose_name='Page Name')
>leaderboard = models.TextField(max_length=500, null=True,
>blank=True, verbo\
>se_name='Leaderboard Tag')
>rectangle = models.TextField(max_length=500, null=True,
>blank=True, verbose\
>_name='300x250 Tag')
>rectangle2 = models.TextField(max_length=500, null=True,
>blank=True, verbos\
>e_name='Additional 300x250')
>
>def __unicode__(self):
>    return self.name
>
>I know that once I figure this out, I'm going to feel rather daft and
>I appreciate all the help you've given me! Thanks so much!
>
>
>On Oct 10, 2:56 pm, Brett Epps  wrote:
>> The direct_to_template() function can take an extra_context keyword
>> argument (a dict). So:
>>
>> direct_to_template(request, template='blah.html', extra_context={'foo':
>> bar})
>>
>> Would let you use {{ foo }} in a template to output the value of the
>> variable bar.
>>
>> By the way, as a replacement for direct_to_template, there's
>> django.shortcuts.render [1], which is a little more concise.  (Usually,
>> you use direct_to_template in urls.py, since it is a full-fledged
>>generic
>> view function.)
>>
>> 
>>1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s..
>>.
>> ts.render
>>
>> Hope that helps,
>>
>> Brett
>>
>> On 10/10/11 12:21 PM, "xenses"  wrote:
>>
>>
>>
>>
>>
>>
>>
>> >That is exactly what I want to do, I can't seem to understand exactly
>> >how to implement that and have it populate in the template. Do I just
>> >define the variable in the views and then in the template use
>> >{{ variable_name }} where I need it? Because I tried that first and it
>> >didn't work. So, maybe I'm just not sure what it is I'm doing
>> >exactly ;)
>>
>> >Thanks for any help!
>>
>> >On Oct 10, 1:09 pm, Brett Epps  wrote:
>> >> I may be misunderstanding your question, but it sounds like you need
>>to
>> >> use Page.objects.get or Page.objects.filter (in your view function)
>>to
>> >> look up the particular objects that you want to send to the template.
>>
>> >> Brett
>>
>> >> On 10/10/11 9:53 AM, "xenses"  wrote:
>>
>> >> >This may seem like a very simple question and I have just missed the
>> >> >answer in the piles of documentation and tutorials that I've read
>>over
>> >> >the past two days. I'm new to Django and trying to implement an
>> >> >internal site at work, and I'm the only Python/Django person we
>>have,
>> >> >so this is all on me.
>>
>> >> >What I am doing is this: I have a set of .html files, templates,
>>which
>> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each
>>template
>> >> >extends base.html, but they each have at least 2 divs that I need to
>> >> >populate with HTML that is entered in the admin interface and stored
>> >> >in the Page model. What I need to do is this:
>>
>> >> >from the url parse what test is being requested:
>>
>> >> >url(r'^test(\d{1})/$', test),
>>
>> >> >cal the test view:
>>
>> >> >def test(request, testn):
>> >> >try:
>> >> >testn = str(testn)
>> >> >return direct_to_template(request, template="test%s.html" %
>> >> >testn)
>> >> >except ValueError:
>> >> >raise Http404()
>>
&g

Re: Add to database

2011-10-11 Thread Brett Epps
I think you need to look up a specific Proyecto object before trying to
add users to it. So:

proyecto = Proyecto.objects.get(...)
for i in request.POST.getlist('usuarios'):
usuario = User.objects.get(id=i)
proyecto.usuarios.add(usuario)

Hope that helps,

Brett


On 10/11/11 4:15 AM, "jose osuna perez"  wrote:

> I have reviewed the document
>https://docs.djangoproject.com/en/dev/topics/db/queries/
>but I can not insert the field users, the models.py table, I try as
>follows, is this what was spinning in the other issue, not the
>complete code, thanks:
>
>for i in request.POST.getlist('usuarios'):
>  usuario=User.objects.get(id=i)
> Proyectos.usuarios.add(usuario)
>
>And my models.py file it's the next:
>
>class Proyectos(models.Model):
>titulo=models.CharField(max_length=100)
>creacion=models.DateField(default=datetime.datetime.now)
>estado=models.CharField(max_length=30)
>objetivo=models.TextField(null=True)
>conclusion=models.TextField(null=True)
>porcentaje=models.IntegerField()
>modificado=models.DateTimeField(default=datetime.datetime.now)
>autor=models.IntegerField()
>usuarios=models.ManyToManyField(User)
>proyectos_rel=models.ManyToManyField("self")
>documentos=models.ManyToManyField(Documentos)
>class Meta:
>db_table='Proyectos'
>def __unicode__(self):
>return self.titulo
>
>Thanks you
>
>-- 
>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 with implementing dynamic views/models

2011-10-11 Thread Brett Epps
The reason for that output is that page is a list, not a single object.
If you want a specific page, use Page.objects.get instead of
Page.objects.filter.

Brett


On 10/11/11 11:30 AM, "Laura C."  wrote:

>that at least gave me an output, but the output is: []
>
>I have a potential to need 3 attributes from each object in each
>template, so the mapping may not be what I need. If I pass in a
>context object, I thought that I should have handles for
>object.attribute ?  Or maybe I need to map the dict before passing it?
>
>
>
>On Tue, Oct 11, 2011 at 11:57 AM, Brett Epps  wrote:
>>
>> Try it with {'page': page} as your extra_context. The keys in a context
>> dict should always be strings.
>>
>> Brett
>>
>>
>> On 10/11/11 8:29 AM, "xenses"  wrote:
>>
>> >I thank you for your help and apologize for my naivete, however I
>> >still am not seeing that tag populate in the template. Here is my view
>> >function in its entirety:
>> >
>> > def test(request, testn):
>> >try:
>> >testn = str(testn)
>> >page = Page.objects.filter(name = "test%s" % testn)
>> >return direct_to_template(request, template="test%s.html" %
>> >testn, extra_context={page:page})
>> >except ValueError:
>> >raise Http404()
>> >
>> >I am using {page:page} because anything else returns errors in debug
>> >mode.
>> >in my template I have :
>> >
>> >{{ page.leaderboard }}
>> >
>> >the page object looks like this:
>> >
>> >class Page(models.Model):
>> >name = models.CharField(max_length=25, verbose_name='Page Name')
>> >leaderboard = models.TextField(max_length=500, null=True,
>> >blank=True, verbo\
>> >se_name='Leaderboard Tag')
>> >rectangle = models.TextField(max_length=500, null=True,
>> >blank=True, verbose\
>> >_name='300x250 Tag')
>> >rectangle2 = models.TextField(max_length=500, null=True,
>> >blank=True, verbos\
>> >e_name='Additional 300x250')
>> >
>> >def __unicode__(self):
>> >return self.name
>> >
>> >I know that once I figure this out, I'm going to feel rather daft and
>> >I appreciate all the help you've given me! Thanks so much!
>> >
>> >
>> >On Oct 10, 2:56 pm, Brett Epps  wrote:
>> >> The direct_to_template() function can take an extra_context keyword
>> >> argument (a dict). So:
>> >>
>> >> direct_to_template(request, template='blah.html',
>>extra_context={'foo':
>> >> bar})
>> >>
>> >> Would let you use {{ foo }} in a template to output the value of the
>> >> variable bar.
>> >>
>> >> By the way, as a replacement for direct_to_template, there's
>> >> django.shortcuts.render [1], which is a little more concise.
>>(Usually,
>> >> you use direct_to_template in urls.py, since it is a full-fledged
>> >>generic
>> >> view function.)
>> >>
>> >>
>> 
>>>>1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s
>>>>..
>> >>.
>> >> ts.render
>> >>
>> >> Hope that helps,
>> >>
>> >> Brett
>> >>
>> >> On 10/10/11 12:21 PM, "xenses"  wrote:
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> >That is exactly what I want to do, I can't seem to understand
>>exactly
>> >> >how to implement that and have it populate in the template. Do I
>>just
>> >> >define the variable in the views and then in the template use
>> >> >{{ variable_name }} where I need it? Because I tried that first and
>>it
>> >> >didn't work. So, maybe I'm just not sure what it is I'm doing
>> >> >exactly ;)
>> >>
>> >> >Thanks for any help!
>> >>
>> >> >On Oct 10, 1:09 pm, Brett Epps  wrote:
>> >> >> I may be misunderstanding your question, but it sounds like you
>>need
>> >>to
>> >> >> use Page.objects.get or Page.objects.filter (in your view
>>function)
>> >>to
>> >> >> look up the particular objects that you want to send to the
>>templa

Re: django-admin py extension on fedora

2011-10-21 Thread Brett Epps
Perhaps Django is packaged differently on Fedora.  Did you install it
using yum?  I'd recommend installing with pip to avoid such issues, and to
ensure you're getting the latest version.

Brett


On 10/21/11 6:01 AM, "flebber"  wrote:

>Just want to double check something really minor.
>
>The django-admin.py command on my system(fedora 15) will only invoke
>without the py extension. Is this okay? the django book shows the
>command with the extension.
>
>my command line:
>
>[sayth@sayth django]$ django-admin.py startproject mysite
>bash: django-admin.py: command not found
>[sayth@sayth django]$ django-admin startproject mysite
>[sayth@sayth django]$
>
>
>Sayth
>
>-- 
>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: Django as a Standalone Desktop Application

2011-10-21 Thread Brett Epps
Hi,

Could you tell us more about the utility you want to create?  It sounds like 
Django might not be the appropriate tool in this case.

Brett

From: Ivo Brodien mailto:i...@brodien.de>>
Reply-To: mailto:django-users@googlegroups.com>>
Date: Fri, 21 Oct 2011 19:46:49 +0200
To: Django users 
mailto:django-users@googlegroups.com>>
Subject: Django as a Standalone Desktop Application

Hi,

I want to write a little utility for somebody and I would like to use Django to 
develop it.

At the moment the utility does not need/or never will have to be running on a 
web server.

I would like to build a little standalone desktop app, so that I can send the 
Django App and everything that is needed (Python,MySQL/SqLite) with one 
Installer/Folder for Windows.

Searching google I found 
“dbuilder.py”

Looks like what I am looking for, but I was wondering if you have any 
experience or suggestions. Maybe there is a newer tool or some state-of-the-art 
way to do it? dbuilder.py was last updated in 2008.

Something like XAMMP or MAMP with support for python and mysqldb would be nice.

Thanks!

PS: I am developing on Mac OS X but could use a virtualized Windows if there is 
need.


--
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 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 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
>>
>> > >>

Re: Reg. Basic django.db.models

2011-11-04 Thread Brett Epps
Hi Ganesh,

Here are some examples:

Filter: SELECT * FROM device WHERE locked = true - returns a QuerySet
which can be evaluated as a list of Device objects
Get: SELECT * FROM device WHERE id = (value of id variable) LIMIT 1 -
returns a single Device object
All: SELECT * FROM schedule - returns a QuerySet which can be evaluated as
a list of Schedule objects

These are only approximations.  For example, get() does not imply a
"LIMIT", since Django looks for cases where multiple objects were returned
and throws an exception.  But hopefully this helps you understand how the
ORM maps to SQL queries.

Here's the relevant part of the documentation [1], in case you haven't
found it yet.

Brett


1. https://docs.djangoproject.com/en/dev/topics/db/queries/

On 11/3/11 11:40 PM, "Ganesh Kumar"  wrote:

>Hi,
>
>I'm a new to Django. I know mysql queries.
>I cant understand django queries, Basically My understanding
>complicated to the django queries. please guide me.
>
>Device.objects.filter(device_id = device_id)[0]
>Device->table
>device-->column
>
>Device.objects.filter(locked = True)
>
>Device.objects.get(device_id = id)
>
>Schedule.objects.all()
>
>filter method what type 0f content return.--> equivalent sql quires
>get method what exactly doing---> equivalent quires
>all method what exactly doing -> equivalent sql quires
>
>
>please guide me..
>
>-Ganesh
>Did I learn something today? If not, I wasted it.
>
>-- 
>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: firstof as

2011-11-07 Thread Brett Epps
Instead of adding a template tag, you could handle this in the class for
obj.  Just have get_votes() cache its result and use the cached value
after the first time get_votes() is called.  In the template, always call
get_votes().

Brett


On 11/7/11 4:12 PM, "Nikolas Stevenson-Molnar" 
wrote:

>Ah, ok; I see what you want to do. I'm not aware of any way to do this,
>other than as you mentioned a custom template tag.
>
>On 11/7/2011 2:04 PM, bax...@gretschpages.com wrote:
>>
>> On Nov 7, 3:50 pm, Nikolas Stevenson-Molnar 
>> wrote:
>>> Assuming obj is iterable, you can do: {% with
>>> obj.0.thingobj.get_something as thing %}
>>>
>>> ...is that what you mean?
>> Not exactly, no. In my particular case, it's more of a check to see if
>> it's available, and if not, do a bit more work to get something that
>> will fill the current need. Or, in other words, maybe I'm storing it
>> locally, or maybe I'm not.
>>
>> Another example:
>>
>> {% with firstof obj.votes obj.get_votes as votes %}
>> Which would then let me do something with votes: "There have been
>> {{ votes }} vote{{ votes|pluralize }}.
>>
>
>-- 
>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: admindocs app - almost, but not, working

2011-11-07 Thread Brett Epps
If this is a bug in Django, you should file a Trac ticket for it here:

https://code.djangoproject.com/newticket

Brett


On 11/7/11 3:40 PM, "lorin"  wrote:

>In case anybody else cares, there seems to be a mismatch between the
>template and the urls for the admindocs module. I solved this problem
>by editing the file django/contrib/admindocs/templates/admin_doc/
>index.html
>and changing each of the links. Models should go to docmodels, Views
>to docviews, etc.
>
>Hope this helps somebody else.
>
>On Nov 4, 3:45 pm, lorin  wrote:
>> I followed the instructions to activate the admindocs (https://
>> docs.djangoproject.com/en/dev/ref/contrib/admin/admindocs/#overview)
>> and now I see a link Documentation, next to Welcome, myname in the
>> admin, and that goes to a nice page at admin/doc. But none of the
>> hyperlinks go to working pages (Tags, Filters, Models, Views,
>> Bookmarklets). E.g. Models goes to admin/models/ and results in a Page
>> not found (404) with a very short message "The requested admin page
>> does not exist."
>>
>> Using the development server.
>>
>> 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.
>

-- 
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: setting up openlayers proxy.cgi

2011-11-14 Thread Brett Epps
Django itself won't run a CGI script for you.  You'll need to run it with
another web server like Apache or nginx.  (Usually the default
installation of Apache has a cgi-bin directory where you can place CGI
scripts.)  You can run one of these servers at the same time as running
manage.py run server, but you'll need to use different ports.

Hope this helps,

Brett


On 11/13/11 2:21 PM, "Daryl"  wrote:

>I need to know how to setup a proxy.cgi script  on my Local Django
>Development setup and can't seem to find the right information to do
>it.
>The closest i've gotten to running any cgi script is when it just
>displays the source code on the webpage...which isn't exactly
>'running' is it?
>Is it ok to run a cgi server and the Django runserver at the same
>time? Is that the problem?
>I'd really appreciate any help with this as its taken up a lot of my
>time and I need the proxy setup for an Openlayers project. Yes, I did
>try and post this question on Geodjango Users, but didn't even get it
>published...
>
>-- 
>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: Django + ajax waiting page, can not redirect to result page

2011-12-14 Thread Brett Epps
I think the problem is that your  tag is incorrect. You're using
the same one to load jQuery and to add your code, so your JavaScript is
not getting run. The file "please_wait.html" should look like this:




Please wait.