Re: template modules like joomla

2009-09-15 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Alessandro Ronchi declared:
>> Alessandro Ronchi declared:
>>> I need to give the possibility to the administrator to manage portions
>>> of templates in pages, and let him to change that portions for every
>>> page.
>>> Joomla does this thing with modules: I need something similar. Is it 
>>> possible?

>> Store your templates in the DB!

> Do you have any example / documentation?

I don't have a very concrete example, but the high level thinking is
pretty easy to write out.  Typically, you would store your templates in
some kind of templates directory on the file system.  This doesn't work
well for your problem, as you want Admin type people to be able to edit
the templates, and you might even want some kind of revision control on
them.

Instead, you can make a table in your DB in which to stuff the
templates.  Maybe something like this:

class WebTemplate(models.Model):
template = models.TextField()
version = models.PositiveIntegerField(unique=True)
# Use this to store which page the template is for, like 'home'
page = models.CharField(max_length=)

When you create your template object, make it from the text in the
template field, and look for the entry with the highest version.  When
somebody edits the template, you just create a new instance and
increment the version number.  Make sense?  If you don't need revision
control, then you can simplify this, but I think it's pretty simple as is!

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqvtRAACgkQw3vjPfF7QfX09ACggLQsUDZFq9WGJDTEnJmJjuu3
PMAAoIcABdyc/wH95bzASXfGYOB+vlNU
=dQnM
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: template modules like joomla

2009-09-15 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Alessandro Ronchi declared:
> I need to give the possibility to the administrator to manage portions
> of templates in pages, and let him to change that portions for every
> page.
> Joomla does this thing with modules: I need something similar. Is it possible?

Store your templates in the DB!

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqvpxMACgkQw3vjPfF7QfXeowCfZaiZNnuu0KiBfioce5E03tu0
6xwAoIKHd7cBMviPa3jB1NdJ8OJoU4lK
=PxW7
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: python manage.py syncdb error (L@@K)

2009-09-14 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

about2flip declared:
>   File "E:\djproj\ifriends\..\ifriends\People\models.py", line 8
> def_str_(self):
>   ^
> SyntaxError: invalid syntax

Looks like you are missing a space between def and __str__(self).
Should be:

def __str__(self):

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkquVXQACgkQw3vjPfF7QfWv0wCgpOOEuw8YRPIM9zElRgS/HG99
p7gAnRcYX4JRp/GvN/Tl658QemjYxYm6
=BAKR
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 ORM - Table Changes

2009-09-10 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thomas declared:
> I've been teaching myself Django over the past couple of days.  Thus
> far, everything has been going smoothly, as I typically do a lot of
> non-web based Python coding, so am familiar with the language.
> However, Django's DB API is my first look into ORM and how it works.
> 
> I understand the basics; how to create models and run a syncdb to
> generate tables.  I understand how to query, update/insert, etc. the
> data by instantiating the class model and using the API methods
> against it.  All nice and well.
> 
> Where I get lost fast is when I need to make changes to a table.  For
> example, say I want to change the name of a column from 'foo' to
> 'bar'.  I can run an ALTER TABLE in SQL and do this easily, but I
> thought the idea of ORM was that you weren't supposed to be using SQL
> directly.  I.e. is there a way to change a column name (or a table
> name, or a attribute type, etc.) from within ORM, i.e. from within the
> model class; or do I have to run the SQL, then change the model to
> 'match' that SQL, and then run a syncdb.
> 
> I love the concept of being able to access data through objects, but
> am just confused as what 'workflow' I should be following when doing
> something like changing a column name.
> 
> Sorry for the basic question.  Google hasn't been much help when
> getting into these details.  I can sort of 'figure it out' by running
> the SQL, matching the model class and going from there... but wasn't
> sure if that was the best, or only way.

The ORM is an interface to generating the tables and executing data
queries, but Django does not handle migration of DB schemas for you.
One way to handle that is to run ALTER TABLE yourself.  Another way to
do it is to dump the data from your DB to a serialized format (like
JSON), alter that dump using REGEXes, build a brand new DB (using
syncdb), and then load the serialized data into it.  The latter is
typically how we do it for our projects.

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqpYzkACgkQw3vjPfF7QfUHowCfeDLkBbAIkCpi++7l/KdNXZBJ
bb8Anju+Y99nzjXr2zMXCmUu0AdDORxQ
=sDyK
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 & flex

2009-08-31 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

solar declared:
> Is there a 'common' way to build apps with django and a Adobe Flex  
> frontend?
> I'm about to do just that, and I'm a bit overwhelmed by the number of  
> choices that you get by multiplying
> communication layers (REST, XML-RPC, SOAP) times data formats (XML,  
> JSON, etc.) times Flex microarchitectures (Cairngorm, RestfulX, etc.).
> Obviously, not all of the above combine, but nevertheless... some of  
> them are probably dead ends, and I'm wondering what people on the  
> list usually choose for building "rich clients" on a django backend.

My quick reply to you about this is that we're using Flex with Django
over the AMF protocol.  We're using PyAMF to accomplish the RPC
protocol, and have implemented various object managers to be used over
that protocol to set and retrieve data.  The AMF protocol allows the use
of ordinary Python data types, so no need to worry about XML or JSON -
just use strings, dicts, and lists as usual!

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqcFykACgkQw3vjPfF7QfU05gCgi9iJnXiOIWLxrE51Zjd4zdJ3
P6oAniM4sPAXmNj0IYDzuwgPX5qt+2u+
=fGXU
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Python FOR loop syntax question

2009-08-21 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Joshua Russo declared:
> Why does this not work?
>   >>> import decimal
>   >>> tst = {'myTst': (decimal.Decimal, 0)}
>   >>> for k, v in tst:
>   ...  print('%s: %s' % (k, v))
>   ...
>   Traceback (most recent call last):
> File "", line 1, in 
>   ValueError: too many values to unpack
>   >>>
>  
> I'm assuming the problem is with the tuple. How do I itterate through a
> dictionary with a tuple as it's value?

Try this instead:

>>> import decimal
>>> tst = {'myTst': (decimal.Decimal, 0)}
>>> for key in tst.keys():
>>> print('%s: %s'%(tst[key][0], tst[key][1]))

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqPEZAACgkQw3vjPfF7QfXq2wCgkmYmswYSqRdvUMuUQMw1gou8
3t8AoIjmSFub7TW+Cv5RhHxhlmDkt9Xa
=klxH
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Error in setting up psycopg2

2009-08-21 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Simon Lee declared:
> Hi Thomas,
> 
> Ok, I put in the "assert False, os.getuid()". The error log logged the
> following:
> 
> [Fri Aug 21 23:37:48 2009] [error] [client 127.0.0.1] assert
> False, os.getuid()
> [Fri Aug 21 23:37:48 2009] [error] [client 127.0.0.1] AssertionError:
> 70
> 
> Then, I go the shell and entered "su - 70". It asked for the password.
> I entered my root password, that's the only password that I set before
> and the only password I know. But it said the password is wrong. I
> cannot go any further as your advised. What should I do? I am not too
> familiar with using Linux. Please help.

The problem is that su wants a username and you are giving it a user id.
 You can look in /etc/passwd to see what user has UID 70 and then su -
.

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqO58wACgkQw3vjPfF7QfVV7gCfTU3JLho3zVZ7viiHWJefkF6z
o1wAnjgRLCGgNF4sGSL5d/iSyhMtph9/
=hkaK
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Bulk data insert

2009-08-20 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Abiel declared:
> Is there an efficient way to use Django models to load a large number
> of records into a database without falling back on raw SQL? Creating a
> large number of model objects and then saving each one individually is
> very slow (I imagine Django is running INSERT and COMMIT each time?).
> 
> Thanks very much.

You can use python manage.py loaddata with a JSON file (and a few other
encodings as well).  Also, check out python manage.py dumpdata for the
reverse operation.  I've also managed to code up a CSV import system for
my project...

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqNnP0ACgkQw3vjPfF7QfVoOACgkgUSeUWVn56T0CCGAHVyx3cv
VYMAoKCCknAxWx4zUDFL3fvhLfhRqTnY
=Hr+Y
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Counting results

2009-08-05 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

When ideas fail declared:
> Hi, I was wondering what is the simpliest way to count the number of
> objects returned in a QuerySet?
> 
> Basically i have a blog and i want to count the number of comment
> relating to each post and display it, the blog posts are shown on a
> seperate page to the comments but i guess you would still have to
> create the query set in the posts view so that you can count the
> results.

Try appending '.count()' to the end of your query!

http://docs.djangoproject.com/en/dev/ref/models/querysets/#count

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkp5opQACgkQw3vjPfF7QfWLIgCfXtC6uKghLldclw6euN5CeeEl
qB0AoIgMZ4b7CB5wX4hWGazTsx1jjUOT
=fo+f
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: How to tell if a fields was modified

2009-07-24 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Matias declared:
> How can I tell which model fields have been modified (this is, the 
> difference between the Model instance and the data originally retrieved 
> from the database) from inside the model's save() method?

You can always retrieve the model by it's primary key from the db, and
then compare self to it.  Something like:

def save(stuff_and_junk):
existing_instance = self.__class__.objects.get(id=self.id)
if existing_instance.attribute != self.attribute:
print 'Holy Crap!'
super(self.__class__, self).save(stuff_and_junk)

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpp5RwACgkQw3vjPfF7QfWmUgCePIAaqGQ6XFWtdEKa86V98Xij
bnUAnjn758cASuyP8wCPkbOEV6Oa3ZGQ
=NqNX
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: TransactionMiddleware not working

2009-07-21 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Parag Shah declared:
> I am using MySql. I believe it does support transactions.

MySQL only supports transactions if you are using INNODB tables.  This
is not the default.

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkplzMAACgkQw3vjPfF7QfWmzwCfY/kP3fEltHzOEfBQc/BZ+HrN
ufAAnjgRqhFwDbPym+4fo1NxiR1mrBgu
=mSLk
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: unittest DB questions

2009-07-13 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Shawn Milochik declared:
> My Django app uses postgres. I've defined TEST_DATABASE_NAME in  
> settings and created that database in postgres. However, I haven't  
> given my Django DB user permission to create and destroy databases --  
> just to own the database. So, I can't run manage.py test, because it  
> fails to delete the database.
> 
> Is there an easy way to tell manage.py to use an in-memory sqlite3  
> database instead?
> 
> Or, even better, how do I get around this issue without giving my  
> Django DB user postgres admin privileges? I'd (obviously) rather that  
> my tests run with the same database backend as the real deal.
> 
> Is it just pointless to disallow my Django db user from administering  
> the postgres installation, since the only thing valuable on it is the  
> live site data anyway?

I highly highly recommend that you separate your development, testing,
and production instances of your DB and web server.  You should never
ever develop or test on a production system!

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpbUr8ACgkQw3vjPfF7QfXgRwCfVWCYz7z0jUtZ4ybw3CIK23OD
wqYAnjQh9fM4FZszyjRsxH3aDcIKf8yG
=Wt12
-END PGP SIGNATURE-

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

2009-07-09 Thread Randy Barlow

Javier Guerra wrote:
> On Thu, Jul 9, 2009 at 5:52 PM, Randy Barlow<rbar...@americanri.com> wrote:
>> sjtirtha declared:
>>> class Media(Document):
>>>link = 
>>>type = 
>>>class Meta:
>>>abstract = True
>>>
>>> class Image(Media):
>>> size = .
>> You should know that this will generate three DB tables.  The media and
>> document tables will share primary keys, with the media table defining
>> any fields not found in the document table.
> 
> that's what the 'abstract = True' avoids

Ah yes, good catch.  I had missed that Meta class!


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

2009-07-09 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

sjtirtha declared:
> Hi,
> 
> I'm new in Django and now I'm already facing the issue with Model
> Inheritance.
> Here is my imagination, how the model should like
> 
> class Document(models.Model):
>name = ...
>type   = 
> 
> 
> class Media(Document):
>link = 
>type = 
>class Meta:
>abstract = True
> 
> class Image(Media):
> size = .
> 
> Is this Model possible? It should only generate two DB tables
> (Document and Image), where Image inherits the attributes from Media.

You probably shouldn't have "type = ..." on both classes.  My experience
with Django is that it doesn't like this, because it won't know which
one to use when you have an instance of Media.  Unlike most Python
objects, Django model objects don't know what their most specific type
is, and thus can't determine whether they are a Document or a Media.
Hopefully, this will be fixed soon!

You should know that this will generate three DB tables.  The media and
document tables will share primary keys, with the media table defining
any fields not found in the document table.

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpWdJEACgkQw3vjPfF7QfV1BQCfd+GVi7/iL3T4/isD2ouTtWFj
QpQAoJrOLkWdSRU5QyXfPqnJH5LgiNKg
=izFF
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Admin login needs to be https

2009-07-08 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

bax...@gretschpages.com declared:
> I need my admin login page to be https rather than http.
> 
> I'm using  SSLRedirect middleware, and it works beautifully every
> place else I need an https page. Problem is, on the admin login, I
> can't find the URL.
> 
> I don't care if the admin as a whole is https. Honestly, I think I'd
> prefer it wasn't, since I feel like that would open up a whole new can
> of worms. But I need that login page to go to https.
> 
> Suggestions?

If you are using Apache for this, you can configure it to redirect for
that URL.  Something like this:


RedirectMatch (.*) https://example.com$1


- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpU/LoACgkQw3vjPfF7QfVspgCdF5mPkA4TDW8ZOpGBXJKpvyra
QSgAnjIbddh6dWjlqs7O7ZVnmILpLszV
=DFyj
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: How to code for multiple sub-types of a model

2009-07-01 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Daniele Procida declared:
> Which of these is a more satisfactory solution? Is there another way?

Hey Daniele, I have a third suggestion for you that I think is best
suited for your problem, and this is the way we do it in our product.
Create a Group model, and place a many to many relationship between it
and your User model.  This way you can test for Group membership to see
if a person is a researcher, etc.  If you want to see all researchers,
you just query for all the Users in the research group.  This is nicer
than using inheritance, since Django doesn't do polymorphism the way you
would expect an ordinary Python class to do (i.e., there's no easy way
to find the most specific type of a User model*)

* We've solved this problem too, by creating a super class for all our
models, and storing the "final type" of all our models.  That way, if we
did have a User and a ResearchUser, if we had queried for the User, we
can call a special method we made on the user,
user.downcast_completely(), and it will give us back the ResearchUser
version of the object.  Neato, eh?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpLsQwACgkQw3vjPfF7QfWR7gCgkpyI61HmqG7x89CqgyXQvdmK
ck8AoJpxOwkHwm762DDZ1zt6R4hBH2ll
=xQh1
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 and PyAMF - RemotingError

2009-06-25 Thread Randy Barlow

Noxxan wrote:
> I'm trying to place in my app an amf gateway,
> so I make one gateway with code:
> 
> #-*- coding: utf-8 -*-
> from pyamf.remoting.gateway.django import DjangoGateway
> 
> from my.views import some_view
> 
> services = {
> 'some_service.hello': some_view.get_smt,
> }
> 
> echoGateway = DjangoGateway(services)
> 
> there's also file some_view.py, with content:
> 
> #-*- coding: utf-8 -*-
> from module.models import MyOwnModel
> 
> def get_smt(request):
> return MyOwnModel.objects.all()
> 
> And here's the problem, I receive an error message:
> 
> pyamf.remoting.RemotingError: HTTP Gateway reported status 500
> Internal Server Error
> 
> When I change return of get_smt view to, by example return 123,
> error didn't occur.
> 
> I have PyAmf 0.4.2, Python 2.5.2 and latest stable Django.
> 
> What may causes the problem?

Many things can cause the problem you are seeing.  I would suggest to 
turn Debug=True, and then navigate to the URL for that view.  You should 
be able to see a traceback, which will give you a better clue about what 
the problem is.

--~--~-~--~~~---~--~~
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: annotate over period of time

2009-04-22 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Johannes Wilm wrote:
> At first I tried this (using postgresql):
> 
> queryset=PrecioPrueba.objects.filter(producto=producto).filter
> (mercado=mercado).filter(fecha__range[start_date,end_date]).extra
> (select={'fecha':"date_trunc('"+frecuencia+'",fecha)"}).values
> ('fecha','producto','mercado','maximo','minimo').annotate(maximo=Avg
> ('maximo'),minimo=Avg('minimo')).order_by('fecha')
> 
> but that just gave me all the values with the date set to the first of
> the month, so I figured django isn't up for the job yet. Instead I
> tried doing it this way:

This filter is not doing what I think you want.  When you
.filter().filter().filter(), it's doing an OR operation, not an AND
operation, so you are filtering for all PrecioPrubas with
producto=producto OR mercado=mercado, when I think you want to filter
for all the price points for a particular product in a particular
market, which is an AND operation.  Try filter(mercado=mercado,
producto=producto, etc...) instead!

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknvQGwACgkQw3vjPfF7QfWc7QCfTi6yJ2gqjzSnP+vMTN3vEgzD
PjgAnRgnV+3AgGpJUPN7TvG41QjwnbNm
=OAOG
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: OperationError: fe_sendauth: no password supplied

2009-04-08 Thread Randy Barlow

LeeRisq wrote:
> I have also tried entering a password (same one I use to logon to the
> network) in settings.py, but when I do that I get this:
>   

 This is almost certainly your problem.  You need a username and a 
password to the database you are using.  It sounds like you are trying 
to use some kind of single sign on credentials from your workplace, when 
those might not be sufficient to access a particular DB.  If you don't 
have root access to the DB engine you are using, you should contact 
someone who does, or make your own development DB on your local machine.

--~--~-~--~~~---~--~~
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: OperationError: fe_sendauth: no password supplied

2009-04-08 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

LeeRisq wrote:
> I've been following along with the Djangobook. When I try to configure
> the postgresql db, I get that error. I've tried tracing the problem
> myself and have been unsuccessful.
> 
> From Chapter 5:
> 
>>>> from django.db import connection
>>>> cursor = connection.cursor()
> 
> Then I get the error. Any ideas?

Did you configure a DB password in settings.py?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkncuYsACgkQw3vjPfF7QfXX7wCfcq7OxcPcI1ceKHXi50bHtYZI
vtIAoI49bOHYFLp32TK4zob6gWGF8Go9
=KcXT
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: ManyToManyField() causes bugs when using 'ModelName' instead of 'self'

2009-04-02 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jumpfroggy wrote:
> Summary: django should throw an exception when a model has its own
> name as the 'to' field of a ManyToMany() insead of 'self'.

> Have I missed anything?  I may be misunderstanding the problem here,
> but I have managed to fix my problem and figure this could save others
> from the same trap.  I'd like to get some input before submitting a
> ticket.

Hey Jumpfroggy!  I can sympathize with you as I spent some time a few
days ago stumbling around on this same problem.  I don't have a problem
with requiring self to be there (though I do think using the model
class's name is more natural, self is OK too), but it would indeed be
helpful if there were an exception.  Perhaps you could bring this up on
django-developers?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknVLP8ACgkQw3vjPfF7QfUeiACbB9AUfTAEQPdzFacx8drbvgyt
774An0+ccYiqKfQiLy3IO5hHQo2IEvfJ
=UKTq
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: avoid cascade delete

2008-11-17 Thread Randy Barlow

On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]>
declared:
> I have two models, links and groups. A Link has an optional foreign
> key Group.
> 
> When I delete a Group, Django by default deletes all Links that
> referenced the Group that is being deleted.
> 
> How do I avoid the default behavior that does a cascade delete. Of
> course I could use the cursor but would am hoping there is some option
> I don't know of for delete().

Funny that you ask this question, because I just spent two days undoing
the Django cascading delete on my end.  If you look at the delete()
method in the Django code, it only makes three calls.  The first two
gather a list of all the objects that Django wants to delete.
Basically, I wrote a new delete() method that iterates through those
objects, finds all the references to the object that you want to delete
and sets them to null.  It then saves them.  After this, you need to
run those first two lines again to regather the objects you want to
delete (this time, only the one object should appear), and then you can
finally delete them.

I would argue this is more desireable than using clear() explicitly,
because you don't have to know anything about your models with this
method.  Any time you have to remember to set a certain
relationship to null, you are bound to forget about another
relationship between your objects, and you'll get cascading delete on
something you didn't expect, and you won't have even noticed that it
happened!

-- 
Randy Barlow
http://electronsweatshop.com

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: sessionid

2008-07-10 Thread Randy Barlow

Bobby Roberts wrote:
> disregard... figured it out.

Hey Bobby!  Just a note - it's generally a good idea to post the
solution to your problem when you get it, so that when people search the
archives who might have the same question as you, they can find it more
easily.  Glad you got it though!

-- 
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DB relations and delete question

2008-07-03 Thread Randy Barlow

Jad wrote:
> Lets say we have Accounts that is referenced profile, group, interest
> tables.
> 
> If I delete the account ID 1 would the related data to that account in
> profile, group and interest table be deleted in all cases of relation?
>  One to one, one to many, many to many? same question applies to
> update

My understanding is that deletion is a cascading operation, following
all relations in the database.  So use it very carefully!

-- 
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use django0.97 with cmemcached

2008-06-09 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

mohamed nadir belkhelfa wrote:
> I want to use cmemcached with Django 0.97 but the import of cmemcached in
> source code  cause the following error
> 
> Can't extract file(s) to egg cache The following error occurred while trying
> to extract file(s) to the Python egg cache: [Errno 13] Permission denied:
> '/mnt/.eggcache/python_libmemcached-0.13.1-py2.5-linux-i686.egg-tmp' The
> Python egg cache directory is currently set to: /mnt/.eggcache Perhaps your
> account does not have write access to this directory? You can change the
> cache directory by setting the PYTHON_EGG_CACHE environment variable to
> point to an accessible directory.
> 
> I need to add certainly  something in the configuration of Django but I dont
> know what is it.
> another thing I use Django with lighttpd.

...so does your user have write permissions to that directory?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhNNPYACgkQw3vjPfF7QfWj4wCgoouymTWdkKZef4dxsIOKVxIn
zEYAnRoCMMtGzRhKzhvt/uI22q6E+EwM
=7Iq6
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Setting a ManyToMany default

2008-06-04 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Peter Rowell wrote:
> I guess I don't understand where this constructor lives in the food
> chain. It can't exist prior to the first save() of the object because
> we don't have the id before that. I tried putting it *in* the save()
> and it did nothing. (BTW, that last one really bothers me.)
> 
> Or are you talking about a constructor for the edit form? That might
> work, if I can figure out how to inject it at the right place.
> 
> I think I need to stare at the db/forms code for a while.

Hmm, maybe I am wrong on this.  I'm new to Django/Python, but not to
object oriented design (I'm a C++ guy), so take what I say with a grain
of salt.  This may not be allowed in the models.py, but if it is,
perhaps having an __init__ function in your Vineyard class could allow
you to set pinot noir as the default, unless it is passed another type
of wine.  Would anybody care to comment on whether this is possible?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhG05sACgkQw3vjPfF7QfUfbgCgl/fd6/xtpSOMZZb60zzqU75i
sZsAnjxp32Ua3WU2jB+Uc1iBIhoeEsQQ
=/LpA
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Setting a ManyToMany default

2008-06-04 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Peter Rowell wrote:
> class Varietal(models.Model):
>   name = models.CharField()
> 
> class Vineyard(models.Model):
>   name = models.CharField()
>   varietals = models.ManyToManyField(Varietal)
> 
> This site is devoted almost exclusively to Pinot Noir, so 90% of the
> Vineyards are planted to Pinot Noir, but some are also planted to
> Pinont Gris, Gamay Noir, etc.
> 
> 1. Is it possible to express a default for a ManyToMany field? How?
> Docs? Having a callable here (e.g., default=some_function) feels about
> right, but the problem is that it needs to be called when we are first
> creating the new object, which means it hasn't been saved yet, so it
> has no id, and therefore we don't have enough info to do a
> vineyard.varietals.add()

> Am I missing something really obvious?

How about writing your own constructor that takes an argument of type
and has a default value assigned there?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhGn78ACgkQw3vjPfF7QfWkIwCfZNY2LsS5Z7qmIQMRdW/7WMKn
MgUAoKZnclcxqr9cS7/NTxp6ywFrrhei
=1cLs
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dev server won't run. (Complete Newbie)

2008-05-27 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

anndr0id wrote:
> So I've never used Linux or Django or Python before. I've got this
> huge project dumped into my lap and so far I've got ubuntu 7.10
> command prompt running on my PC through VMWare and the Django server
> up. This is the first day I've got into any of this so please excuse
> my total lack of knowledge about anything in regards to this.
> 
> I've gotten to the python manage.py runserver part, and the message
> comes up with no errors. "Development server is running at 
> http://127.0.0.1:8000
> (I've also tried setting this to port 80) and I'm getting nothing
> through the web browser nor am I able to connect via any other way.
> I've got no clue why this isn't working and there is nothing in the
> documentation or in the search for this group for that matter that
> addresses this issue.
> 
> Any suggestions?

Are you running the web browser inside the VM, or on the host machine?

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg8SnIACgkQw3vjPfF7QfWllACfc6HCH6+tZ6mHpYqb8b5XeK87
5pEAn0KtEhZ3dVQ3Hycl5TwtiiHuc3yl
=kgqQ
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to add files to the django built-in webserver

2008-05-22 Thread Randy Barlow

Turns out that this can be done with what is described at [1].

[1] http://www.djangoproject.com/documentation/static_files/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to add files to the django built-in webserver

2008-05-22 Thread Randy Barlow

Hi all, I'm new to the group with a fairly simple question.  I'd like
to use the Django webserver to demo a site I'm working on, and I would
like to be able to add a file I've created to the document root.  The
file is a simple crossdomain.xml file for flash, and I'd like it to be
accessible at http://myDjangoServer.domain.com/crossdomain.xml.  How
would I do this?  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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---