Re: manipulator.save() and manytomany relationship

2006-03-29 Thread limodou

On 3/30/06, yml <[EMAIL PROTECTED]> wrote:
>
> I don't set any value for the profile_id. This attribute where added by
> django, I guess in order to have a "primary key".
> If I comment the line with set_localisation (which is my many to many
> relation) I do not get this error so I do not see why I should care
> about this with this additional attribute.
>
> since I am creating a new profile how can I know whick is the next
> available integer for my primary key. I was expecting to have it
> automatically managed by Dango.
>

If you print new_data['localisation'], I think you can get a list of
string format ids. So in M-R branch, you should get all the objects
according to the ids, just like:

objs = localisations.get_in_bulk(new_data['localisation'])

I'm not sure that if the new_data['localisation'] is a integer list,
because the ID field is a integer data type, so maybe you should
convert a string list to a integer list, just like:

a = map(int, new_data['localisation'])

and

temp.set_localisation(objs)

--
I like python!
My Blog: http://www.donews.net/limodou
My Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

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



Re: manipulator.save() and manytomany relationship

2006-03-29 Thread yml

I don't set any value for the profile_id. This attribute where added by
django, I guess in order to have a "primary key".
If I comment the line with set_localisation (which is my many to many
relation) I do not get this error so I do not see why I should care
about this with this additional attribute.

since I am creating a new profile how can I know whick is the next
available integer for my primary key. I was expecting to have it
automatically managed by Dango.


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



Re: Custom templatetags are ignored. Why ?

2006-03-29 Thread Max Battcher

ak wrote:
> After a bit of research I found that my templatetags dir has
> __init__.pyc file and it tells me that django tried to include this
> directory but my news_tags.py file has no .pyc

Sounds like you have a syntax error in news_tags.py.  Try importing it 
within a Python shell.  Basically:

python manage.py shell
 >>> from myproject.myapp.templatetags import news_tags

-- 
--Max Battcher--
http://www.worldmaker.net/
"I'm gonna win, trust in me / I have come to save this world / and in 
the end I'll get the grrrl!" --Machinae Supremacy, Hero (Promo Track)

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



Re: Custom templatetags are ignored. Why ?

2006-03-29 Thread ak

Sorry guys it was my stupidity :)
I should have written
 {% load news_tags %} 
instead of
 {% load "news_tags" %}


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



Re: manipulator.save() and manytomany relationship

2006-03-29 Thread yml

hello limodou,

you have been of great help till now, thank you for your time.

I tried list because I was not working without:

 temp.set_localisation(list(new_data['localisation']))
=
error page with: list(new_data['localisation'])
===
OperationalError at /profiles/create_manip/
(1048, "Column 'profile_id' cannot be null")
Request Method: POST
Request URL:http://localhost:8000/profiles/create_manip/
Exception Type: OperationalError
Exception Value:(1048, "Column 'profile_id' cannot be null")
Exception Location: C:\Python24\lib\site-packages\MySQLdb\cursors.py
in _do_query, line 193
Traceback (innermost last)

*
c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\handlers\base.py
in get_response
66. # Apply view middleware
67. for middleware_method in self._view_middleware:
68. response = middleware_method(request, callback,
callback_args, callback_kwargs)
69. if response:
70. return response
71.
72. try:
73. response = callback(request, *callback_args,
**callback_kwargs) ...
74. except Exception, e:
75. # If the view raised an exception, run it through exception
76. # middleware, and if the exception middleware returns a
77. # response, use that. Otherwise, reraise the exception.
78. for middleware_method in self._exception_middleware:
79. response = middleware_method(request, e)
  ▶ Local vars
  Variable  Value
  DEBUG
  True
  INTERNAL_IPS
  ()
  ROOT_URLCONF
  'votreservice.urls'
  callback
  
  callback_args
  ()
  callback_kwargs
  {}
  db
  
  e
  <_mysql_exceptions.OperationalError instance at 0x01597468>
  exceptions
  
  mail_admins
  
  middleware_method
  >
  path
  '/profiles/create_manip/'
  request
  , POST:,
COOKIES:{'sessionid': '5736d4edabff367ea3267c90ed4207fe'},
META:{'ALLUSERSPROFILE': 'C:\\Documents and Settings\\All Users',
'APPDATA': 'C:\\Documents and Settings\\yml\\Application Data',
'APR_ICONV_PATH': 'C:\\Program Files\\Subversion\\iconv', 'BOOKSHELF':
'C:\\IFOR\\WIN\\BIN\\EN_US', 'CATHEIGHTMMOFSCREEN': '215',
'CATWIDTHMMOFSCREEN': '290', 'CLASSPATH': 'C:\\Program
Files\\Java\\jdk1.5.0_05\\jre\\lib\\ext\\QTJava.zip',
'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
'COMPUTERNAME': 'FOUDREDDS', 'COMSPEC':
'C:\\WINDOWS\\system32\\cmd.exe', 'CONTENT_LENGTH': '91',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
'DJANGO_SETTINGS_MODULE': 'votreservice.settings', 'DS3AGN':
'FRCQD511', 'DS3CONF': 'Bureautique', 'DS3OS': 'WinXP', 'DS3TYPEMAT':
'IBMThinkT42', 'DS3USER': 'tmp', 'FP_NO_HOST_CHECK': 'NO',
'GATEWAY_INTERFACE': 'CGI/1.1', 'HELP': 'C:\\IFOR\\WIN\\BIN',
'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Documents and Settings\\yml',
'HTTP_ACCEPT':
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE':
'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3', 'HTTP_CONNECTION': 'keep-alive',
'HTTP_COOKIE': 'sessionid=5736d4edabff367ea3267c90ed4207fe',
'HTTP_HOST': 'localhost:8000', 'HTTP_KEEP_ALIVE': '300',
'HTTP_REFERER': 'http://localhost:8000/profiles/create_manip/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr;
rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1', 'I4_INSTALL_DRIVE': 'C:',
'I4_LANG': 'EN_US', 'IPF_PATH32': 'C:\\IFOR\\WIN\\BIN\\EN_US',
'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.5.0_05\\bin', 'LIB':
'C:\\Program Files\\SQLXML 4.0\\bin\\', 'LOGONSERVER': 'FOUDREDDS',
'NLSPATH': 'C:\\IFOR\\LS\\MSG\\%L\\%N', 'NUMBER_OF_PROCESSORS': '1',
'OS': 'Windows_NT', 'PATH': 'C:\\Perl\\bin\\;C:\\Program Files\\Common
Files\\VERITAS Shared;C:\\VERITASNetBackup\\bin;C:\\PROGRAM
FILES\\THINKPAD\\UTILITIES;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program
Files\\ATI Technologies\\ATI Control Panel;C:\\Program Files\\Resource
Pro Kit\\;C:\\IFOR\\WIN\\BIN;C:\\IFOR\\WIN\\BIN\\EN_US;C:\\Program
Files\\ATI Technologies\\Fire GL 3D Studio Max;C:\\Program Files\\ATI
Technologies\\Fire GL Control Panel;C:\\Program Files\\Microsoft SQL
Server\\90\\Tools\\binn\\;E:\\users\\src_Install\\IronPython\\IronPython-0.7.3\\bin;C:\\Python24;C:\\Python24\\Scripts;C:\\cygwin;C:\\Program
Files\\HTML Help Workshop;E:\\instal\\SmarTeam\\BIN;C:\\Program
Files\\Microsoft SQL
Server\\80\\Tools\\Binn\\;E:\\users\\src_Install\\Nant\\nant-0.85-rc3\\bin;C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322;C:\\cygwin\\bin;c:\\Program
Files\\MySQL\\MySQL Server 5.0\\bin;C:\\Program
Files\\Java\\jdk1.5.0_05\\bin;c:\\Program
Files\\QuickTime\\QTSystem\\;C:\\Program Files\\Subversion\\bin',
'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH',
'PATH_INFO': '/profiles/create_manip/', 

Re: follow relationship

2006-03-29 Thread Ned Batchelder




What I've done in these cases is to define a Constants class:
    class Constants:
    """ Construct one of these with keyword arguments, and you can use the
    attributes.
    """
        def __init__(self, **kwargs):
    for k, v in kwargs.items():
    setattr(self, k, v)

    def choices(self):
    return list(self.__dict__.items())
(I guess Enumeration would be a better name), then I can define a list
of constants:
    kBranchKind = Constants(
    main = 1,
    aux = 2,
    dead = 3
    )
Then in the code, you can use kBranchKind.dead, and in your model, you
can use:
class Branch(meta.Model):
trunk = meta.ForeignKey(Trunk)
kind = meta.IntegerField(choices=kBranchKind.choices())
It keeps the list of choices in one place, gives you run-time errors if
you mistype the constant name (string literals would not), and it works
just as well with strings for the values.

--Ned.

Ivan Sagalaev wrote:

  Todd O'Bryan wrote:

  
  
Your comment at the end got me thinking, though. Writing

trunk.get_branch(kind__exact=2)

is not very illuminating, but you're correct that the value 'Dead'  
could get changed later. In Java, I'd use constants for the integer  
values

public static final int DEAD = 2;

but that seems to violate DRY, because the semantics is already  
listed in the choices list. I like using integers for what end up  
being enumerated types because they don't take much space in the  
database and, as you mentioned, it's easy to change the English  
version without having to do anything to the db representation.

Is there a better way to do this kind of thing?
 


  
  This got me thinking too :-)

Generally when I need a constant in Python I don't hesitate to use 
string values for constants which are both values and names. So I'd have

BRANCH_KINDS = (('main', 'Main'), ('aux', 'Auxiliary'), ('dead', 
'Dead'),)

I think it won't even hurt performance in DB lookups if you create index 
for this field. However this implies changing  the field to CharField 
which won't become a  box in admin and in automatic manipulators 
(if I'm not mistaken). A lookup table for branch kinds would solve this:

class BranchKind(meta.Model):
  id = meta.SlugField(primary_key=True)
  title = meta.CharField(maxlength=50)

You can then do something like

  trunk.get_branch(pk='dead')





.

  


-- 
Ned Batchelder, http://nedbatchelder.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  -~--~~~~--~~--~--~---





Re: manipulator.save() and manytomany relationship

2006-03-29 Thread limodou

On 3/30/06, yml <[EMAIL PROTECTED]> wrote:
>
> Hello djangonauts,
>
> I wrote my first manipulator and there is still some part that I am not
> understanding.
> I have the feeling that I am missing something obvious in the save
> function of my manipulator but I am unable to improve it.
>
> I would be glad if someone could explain me how to set_localisation to
> my "Profile" ?
> I am a bit lost there.
> Thank you for your help
>
>
> ===
> Here it is the error message I am getting:
> =
> TypeError at /profiles/create_manip/
> list objects are unhashable
> Request Method: POST
> Request URL:http://localhost:8000/profiles/create_manip/
> Exception Type: TypeError
> Exception Value:list objects are unhashable
> Exception Location:
> 
> c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\meta\__init__.py
> in method_set_many_to_many, line 1138
>
> =
> Here it is my manipulator
> =
> class announceManagerProfileManipulator(formfields.Manipulator):
> def __init__(self, pk=None):
> self.fields = (
> #formfields.SelectField(field_name='user',
> is_required=True, choices=[('','---')] + [(o.id, o) for o in
> users.get_list()]),
> formfields.TextField(field_name='pseudo', is_required=True,
> maxlength=30),
> #formfields.RadioSelectField(field_name='gender',
> radio_admin=True, choices=[('','---')] + [(o.id, o) for o in
> genders.get_list()]),
> formfields.RadioSelectField(field_name='gender',
> choices=[(o.id, o) for o in genders.get_list()]),
> formfields.TextField(field_name='address', maxlength=300),
> formfields.TextField(field_name='phonenumber',
> maxlength=10),
>
> formfields.CheckboxField(field_name='want_to_publised_personal_info'),
> #formfields.SelectField(field_name='memberShipLevel',
> is_required=True, radio_admin=True, choices=[('','---')] + [(o.id,
> o) for o in membershiplevels.get_list()]),
> formfields.RadioSelectField(field_name='memberShipLevel',
> is_required=True, choices=[(o.id, o) for o in memberships.get_list()]),
> formfields.SelectMultipleField(field_name='localisation',
> choices=[(o.id, o) for o in localisations.get_list()], size=5, ),
> )
>
> def save(self, new_data, current_user):
>
> temp = Profile(
> user=current_user,
> pseudo=new_data['pseudo'],
>
> #want_to_publised_personal_info=new_data['want_to_publised_personal_info'],
>
> memberShipLevel=memberships.get_object(pk=new_data['memberShipLevel']),
> want_to_publised_personal_info=False,
> )
> if new_data['localisation']:
> temp.set_localisation([list(new_data['localisation'])])
> ###  <=== This is where my problem is locating
> if new_data['gender']:
> temp.gender=
> genders.get_object(id__exact=new_data['gender'])
> temp.address = new_data['address']
> temp.phonenumber = new_data['phonenumber']
> if new_data['want_to_publised_personal_info']:
> temp.want_to_publised_personal_info=
> new_data['want_to_publised_personal_info']
> temp.is_default_profile=True
> temp.save()
> return temp
>
>

It seems that you are using 0.91 version. And you want to deal
manytomany field before temp object saved. I'm using M-R branch now.
But I do these things after saving the temp object. And I see that:

temp.set_localisation([list(new_data['localisation'])])

And why you put list(new_data['localisation']) to [] I don't
understand. I think

temp.set_localisation(new_data['localisation'])

maybe enough. You can try again.

--
I like python!
My Blog: http://www.donews.net/limodou
My Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

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



Re: limit_choices_to

2006-03-29 Thread Luke Plant

On Monday 27 March 2006 16:50, [EMAIL PROTECTED] wrote:

> I've just used the first bit of Luke's wheeze- storing the user.id
> and stuffing it in the model's save method.
> I had to put 'null-True' in the model to get the user.id bit of this
> to work. Otherwise the 'if self.officer_id is None:' always failed.
> Left a comment on the web site, Luke.

Cheers - I responded on my blog.

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: limit_choices_to

2006-03-29 Thread Luke Plant

On Sunday 26 March 2006 21:01, tonemcd wrote:

> I think that this http://lukeplant.me.uk/blog.php?id=1107301634 might
> be helpful. There's also been some traffic on limit_choices_to in the
> group recently (although not strictly relevent to your problem I
> think)

Note that this blog entry assumes magic-removal.  I think the middleware 
bit should work in trunk, but I don't know.  In your situation (yml), I 
think you need to create some kind of 'LazyUser' object in the style of 
LazyDate.  The LazyUser object would use my get_current_user() 
function.  Implementation is left as an exercise for the reader :-)

Also, re: limit_choices_to - it wasn't working on m-r until r2547 (March 
22), but it should be fixed now.

Regards,

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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



Re: Overthinking urls.py?

2006-03-29 Thread Todd O'Bryan

Is it possible to do it all in urls.py? I don't know much about  
Python, yet, but could you have two way look-up. urls.py has the URL- 
 >View handled. Could you stick in a dictionary based on classes (and  
PKs, maybe) that would return the appropriate URL?

Todd

On Mar 29, 2006, at 10:38 AM, Adrian Holovaty wrote:

>
> On 3/29/06, James Bennett <[EMAIL PROTECTED]> wrote:
>> On 3/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>> And now you're encoding URLs (which are, in my mind, definitely
>>> presentation-related) in the models?
>>
>> It's not something new; it's been this way since the first public
>> release of Django. Adrian and others have said elsewhere that it's  
>> not
>> nice and they'd love to see a better way to handle this, but no-one's
>> yet come up with one that works.
>
> Yeah, precisely. Elegant solutions are quite welcome!
>
> Adrian
>
> --
> Adrian Holovaty
> holovaty.com | djangoproject.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
-~--~~~~--~~--~--~---



Re: OneToOneField

2006-03-29 Thread Joseph Kocherhans

On 3/29/06, Joseph Kocherhans <[EMAIL PROTECTED]> wrote:
>
> If someone would file a ticket for this (if they haven't already) that
> would be great. I'll look at it in a few days if no one else has. I'm
> trying to wrap up some other project this week.

Oops. Nevermind about filing a ticket. I missed this:

http://code.djangoproject.com/ticket/1547

Joseph

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



Re: How to get vote total in poll tutorial

2006-03-29 Thread JHeasly

>
> Then you probably want it to read:
>  choices.get_values(fields=['poll', 'votes'], poll_id__exact=1)
>
> i.e.   your "field" is "poll_id" and the lookuptype is "exact"
> which translates to "poll_id__exact", and THEN the equals sign
> and what value you are asking it to match.
>
> --
> Glenn

Figured it out; poll_id maps from polls_choices to the polls_polls
primary key, so I tried using the Django primary-key shortcut (see
below) and now it works.

choices.get_values(fields=['poll', 'votes'], poll_id__exact=1)

as suggested above, doesn't work: (TypeError: got unexpected keyword
argument 'poll_id__exact'), but ...

choices.get_values(fields=['poll', 'votes'], poll__pk=1)

 ... does! Not sure why though.

Just as an "exercise left to the reader" sort of thing, I was trying to
figure out how to make the lookup work without the pk shortcut, i.e.:

choices.get_values(fields=['poll', 'votes'], poll__poll_id__exact=1)

but it fails: TypeError: got unexpected keyword argument
'polls__poll_id__exact'

I'm stumped!

John


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



Re: Searching in a foreign table field

2006-03-29 Thread Jaime G. Wong

  Thanks Tabo, that's it.

On Wed, Mar 29, 2006 at 09:00:39PM -, Gustavo Picon wrote:
> 
> You have to specify in what field of the FK object you want the search
> to work. For instance if there is a "name" field in the Song model, you
> may want to try:
> 
> search_fields = ('song__name', ),
> 
> Hope that helps.
> 
> 
> 

-- 
Jaime G. Wong Chacaltana
E-Mail: [EMAIL PROTECTED]
Web   : http://jgwong.org/

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



Re: OneToOneField

2006-03-29 Thread Joseph Kocherhans

On 3/29/06, layik <[EMAIL PROTECTED]> wrote:
>
> Hello there,
>
> sorry to bother you.
>
> I was wondering if you have solved your OneToOne problem. if so could
> let me know how I could solve it as well??
> thanks
>
>
> ChaosKCW wrote:
> > Agreeded, I am trying to use OneToOne in MR branch and get the same
> > problems.
> >
> > I have:
> >
> > class Employee(models.Model):
> >user = models.OneToOneField(User, verbose_name='Employees User ID')
> >...
> >
> > And get the following error when trying to view the object in admin:
> >
> > Request Method:   GET
> > Request URL:  http://127.0.0.1:8000/admin/traininglog/employee/
> > Exception Type:   OperationalError
> > Exception Value:  no such column: auth_user.username
> > Exception Location:
> >   
> > c:\programming\python24\lib\site-packages\django-0.91-py2.4.egg\django\db\backends\sqlite3\base.py
> > in execute, line 62
> >
> > Any Ideas ?

If you specify ordering, this should be fixed... kinda. Django is
trying to sort on a column in the auth_users table, but it doesn't
join to that table for some reason.

class MyClass(models.Model)
user = OneToOneField(User)

class Admin:
ordering = ('user_id',)

This will force the admin system to order by the user_id column of the
myclass table. Unfortunately, this will cause a validation error when
you run any manage.py commands, but manage.py runserver will still
work. You can temporarily comment it out when running syncdb.

If someone would file a ticket for this (if they haven't already) that
would be great. I'll look at it in a few days if no one else has. I'm
trying to wrap up some other project this week.

Joseph

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



Re: Overthinking urls.py?

2006-03-29 Thread Adrian Holovaty

On 3/29/06, James Bennett <[EMAIL PROTECTED]> wrote:
> On 3/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > And now you're encoding URLs (which are, in my mind, definitely
> > presentation-related) in the models?
>
> It's not something new; it's been this way since the first public
> release of Django. Adrian and others have said elsewhere that it's not
> nice and they'd love to see a better way to handle this, but no-one's
> yet come up with one that works.

Yeah, precisely. Elegant solutions are quite welcome!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.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
-~--~~~~--~~--~--~---



Re: follow relationship

2006-03-29 Thread Ivan Sagalaev

Todd O'Bryan wrote:

>Your comment at the end got me thinking, though. Writing
>
>trunk.get_branch(kind__exact=2)
>
>is not very illuminating, but you're correct that the value 'Dead'  
>could get changed later. In Java, I'd use constants for the integer  
>values
>
>public static final int DEAD = 2;
>
>but that seems to violate DRY, because the semantics is already  
>listed in the choices list. I like using integers for what end up  
>being enumerated types because they don't take much space in the  
>database and, as you mentioned, it's easy to change the English  
>version without having to do anything to the db representation.
>
>Is there a better way to do this kind of thing?
>  
>
This got me thinking too :-)

Generally when I need a constant in Python I don't hesitate to use 
string values for constants which are both values and names. So I'd have

BRANCH_KINDS = (('main', 'Main'), ('aux', 'Auxiliary'), ('dead', 
'Dead'),)

I think it won't even hurt performance in DB lookups if you create index 
for this field. However this implies changing  the field to CharField 
which won't become a  box in admin and in automatic manipulators 
(if I'm not mistaken). A lookup table for branch kinds would solve this:

class BranchKind(meta.Model):
  id = meta.SlugField(primary_key=True)
  title = meta.CharField(maxlength=50)

You can then do something like

  trunk.get_branch(pk='dead')


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



Re: Mysterious thread problem

2006-03-29 Thread yuri

Yip, we had the same problem, it's to do with the time change that
happened 2 days ago. To cut a long story short, set the timezone in
your settings file to TIME_ZONE = ""
Django will then use the timezone returned by windows.

The problem is that in django.conf.settings.py, line 64, it sets the TZ
variable. The timezone it tries to set is from the postgres database,
i.e. the link given in the settings file. These however are not valid
for mysql, so mysql resets it to GMT. So, the thread reloads, thinking
that the timestamp for a file has changed. And it keeps doing it over
and over.


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



Re: Get objects in _manipulator_validate_.....() methods

2006-03-29 Thread Matthew Flanagan

On 3/29/06, Rudolph <[EMAIL PROTECTED]> wrote:
>
> I'm writing a _manipulator_validate_.() method. These methods
> become methods for the manipulator of a model and will be validated
> before save() is called. Any exception of  validators.ValidationError
> will very nicely be displayed in the admin interface (if your raise
> such an exception in _pre_save, it won't work that way :-( ).
>
> By Googling around I discovered that self.original_object points to the
> old object. Which can be very helpfull. But I would also like to access
> other objects from the same model (by using get_object or get_list on
> the module). Is there a way to do this? It must be possible (for
> example to check if the new value is unique for the whole model, or to
> check if a value exists in another field of another object).
>
> I'm using the current trunk but willing to change to Magic Removal if
> that solves it.
>
> Thanks in advance!
>
> R.
>
>

No need to use magic removal. Just import you model modules inside of
the _manipulator_validate_...() method like so:

class Foo(meta.Model):
myfield = meta.CharField(maxlength=30)

def _manipulator_validate_myfield(self, field_data, all_data):
from django.models.myapp import foos
...

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



Re: admin apache solved? / now mysql problem

2006-03-29 Thread abe


Andy Dustman wrote:
> On 3/28/06, abe <[EMAIL PROTECTED]> wrote:
> > Andy Dustman wrote:
> > > On 3/28/06, abe <[EMAIL PROTECTED]> wrote:
> > > > Andy Dustman wrote:
> > > > > On 3/28/06, abe <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > > OperationalError: (2002, "Can't connect to local MySQL server 
> > > > > > through
> > > > > > socket '/var/lib/mysql/mysql.sock' (13)")
> > > > >
> > > > > This indicates your MySQL server isn't running,
> > > > I think it is, since the admin site works fine if I use
> > > > manage.py runserver , doesn't it also use the server?
> > > >
> > > > %myproject]# ps -eadf|grep sql
> > > > root 18240 18044  0 12:32 pts/200:00:00 /bin/sh
> > > > /usr/bin/mysqld_safe
> > > > mysql18268 18240  0 12:32 pts/200:00:00 /usr/libexec/mysqld
> > > > --basedir=/usr --datadir=/var/lib/mysql --user=mysql
> > > > --pid-file=/var/run/mysqld/mysqld.pid --skip-locking
> > > > --socket=/var/lib/mysql/mysql.sock
> > > >
> > > > unless 'MYSQL server' means somthing different from mysqld ??
> > > >
> > > >
> > > > > and you are using DATABASE_HOST="localhost".
> > > > well I use ='', but that should be the same
> > > >
> > > > but isn't that correct, since mysqld runs on the same host as django?
> > >
> > > Make sure apache can read /var/ilbmysql/mysql.sock. I'm a little
> > how do I do that? I can't 'become' apache
> > from the permissions it looks readable
> >
> > myproject$ ls -lst /var/lib/mysql/mysql.sock
> > 4 srwxrwxrwx  1 mysql mysql 0 Mar 28 12:32 /var/lib/mysql/mysql.sock
> > myproject$ ls -lst /tmp/mysql.sock
>
> But is the parent directory world-readable? i.e. ls -ld /var/lib/mysql

looks so:
ls -ld /var/lib/mysql
drwxr-xr-x  5 mysql mysql 4096 Mar 29 10:30 /var/lib/mysql


> > there a link to it in /tmp :
> > 4 lrwxrwxrwx  1 mysql mysql 25 Mar 23 16:58 /tmp/mysql.sock ->
> > /var/lib/mysql/mysql.sock
> > [EMAIL PROTECTED] myproject]$
> >
> > > surprised to see it put the socket there, since (on Gentoo)
> > > /var/lib/mysql is only accessible by the user the mysql server runs
> > > as, so it puts the socket (which needs to be world-readable and
> > > writable) in /var/run.
> >
> > >
> > > When you run manage.py runserver, are you running as root?
> > yes (should I?), but I can also run as myself, doesn't matter
>
> You probably shoudn't run it as root on general principle. Make sure
> you can access it as a non-root user. The error indicates it did not
> get as far as the authentication phase so I am still leaning towards
> filesystem permissions.

> You're not running a chroot apache by any chance, are you?
not that I know, but I didn't setup the system myself.
how do I to find out?

> SELinux? Some sort of virtualization?
idem. it's a scientific linux installlation (RHEL-like), I saw the
selinux libraries are installed.

> I guess you could try 127.0.0.1 for the database host which will make it use 
> TCP
> and see if that makes a difference.

Ah, that helped!
but I also had to change the mysqld that I'm running
from  /usr/bin/mysqld_safe (mysql 4) to
/usr/local/mysql/bin/mysqld_safe (mysql 5)

although the sockets they use are the same, and I still use mysqldb
that is
compiled with the mysql.h from mysql4

I can login to the admin site now, great!
but it seems that the css files are not accessible  because there is no
layout .
I copied the dir
/usr/lib/python2.3/site-packages/Django-0.91-py2.3.egg/django/contrib/admin/media/css

to /var/www// (where my project is, wasn't able to use it under my
own dir) but that didn't help

according to the admin page it expects the css in //css :



my settings.py has:
ADMIN_MEDIA_PREFIX = 'zbdb/'



thanks for the help and patience, 

-E


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



Re: What is Caching my DB

2006-03-29 Thread Michael Twomey
On 3/28/06, Siah <[EMAIL PROTECTED]> wrote:
>
> Thank you Michael,
>
> I must add that on my laptop using django's runserver command, this
> problem does not exist.
>
> I am still stock, so all help is greatly appreciated,

Ok, so much for that theory :)

Another possibility might be some kind of client side caching going
on. There might either be an overly aggressive proxy in between the
browser and the site, or the browser might be set to cache pages too
much.

One way to verify this is to watch the logs as someone browses the
site. If they are getting the behaviour you are seeing but you don't
see any requests made to the server at the same time then it's
probably a browser caching or proxy issue. You should see a request
for every page viewed and every item edited, probably with a 200
response code.

Michael

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



Re: ANN:Woodlog Testing

2006-03-29 Thread yml

hello limodou,

I was think to start developing something similar to add it to a portal
I am working on.
Of course I would have done it with a less talent than you.   :-)

Are you going to open source it that I could learn from your source and
use it

Good job


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



Re: admin apache solved? / now mysql problem

2006-03-29 Thread abe


Todd O'Bryan wrote:
> On Mar 28, 2006, at 8:20 AM, Andy Dustman wrote:
> > On 3/28/06, abe <[EMAIL PROTECTED]> wrote:
> >
> >> OperationalError: (2002, "Can't connect to local MySQL server through
> >> socket '/var/lib/mysql/mysql.sock' (13)")
> >
> > This indicates your MySQL server isn't running, and you are using
> > DATABASE_HOST="localhost".
>
> We saw this problem because the mysql.sock file was in /tmp/ instead
> of /var/lib/mysql. A symbolic link from /var/lib/mysql/mysql.sock to /
> tmp/mysql.sock solved the problem.

this is already the case, see my previous post. 

-E


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



Re: Assigning default value for field in admin

2006-03-29 Thread Daniel Bimschas

Hey that looks great! Thanks a lot, it will do for my purposes!


2006/3/27, tonemcd <[EMAIL PROTECTED]>:
>
> This looks like it might help,
> http://lukeplant.me.uk/blog.php?id=1107301634 although it's not exactly
> what you're after...
>
> Cheers,
> Tone
>
>
>
>

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



Re: Overthinking urls.py?

2006-03-29 Thread James Bennett

On 3/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> And now you're encoding URLs (which are, in my mind, definitely
> presentation-related) in the models?

It's not something new; it's been this way since the first public
release of Django. Adrian and others have said elsewhere that it's not
nice and they'd love to see a better way to handle this, but no-one's
yet come up with one that works.

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

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



Re: Flatpages and comments - question

2006-03-29 Thread ak

Ok found the answer myself. I added at the bottom of content block:
{% if flatpage.enable_comments %}
 {% load comments %}
{% free_comment_form for  flatpages.flatpages flatpage.id %}

etc ...


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



Re: Overthinking urls.py?

2006-03-29 Thread limodou

On 3/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Adrian Holovaty wrote:
> > The convention is to put the URL-creation logic in your models, in a
> > get_absolute_url() method. Here's a quick example:
> >
> > class Person(meta.Model):
> > gender = meta.CharField(maxlength=1) # 'm' or 'f'
> > full_name = meta.CharField(maxlength=50)
> >
> > def get_absolute_url(self):
> > return '/people/%s/%s/' % (self.gender,
> > self.full_name.lower().replace(' ', ''))
>
> I find this *really* surprising. All discussions and examples I've seen
> so far are quite strict about the fact that models should be separate
> from presentation logic. See the various discussions about "how can my
> model get access to request.user?" here in this group. These arguments
> made (make) perfect sense to me.
>
> And now you're encoding URLs (which are, in my mind, definitely
> presentation-related) in the models? To me, this seems strange and
> unnatural. Why should a "Book" model care wether it has a view that
> lives under "/library" or under "/amazon/shoppingcart" or under
> "/thingtostopthetablefromwobbling" ? It's a book. It has properties. It
> knows how to tell me its title.
>
> But it shouldn't care wether it's being read or being used to prop up
> furniture.
>
> Or am I misunderstanding something here?
>
> Daniel
>

Because I think model in Django is not a simple data wrapper layer,
but also a representation layer in many situations. If you don't want
model do much, so you need do such things(create url) in other places.
And if there is not a good way to create url, I think create url by
model itself is a handy way.

And I think there should be a good way to create url, which will
consider different applications, functions, and object_ids. Even
user_id in it.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

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



Re: Overthinking urls.py?

2006-03-29 Thread [EMAIL PROTECTED]

Adrian Holovaty wrote:
> The convention is to put the URL-creation logic in your models, in a
> get_absolute_url() method. Here's a quick example:
>
> class Person(meta.Model):
> gender = meta.CharField(maxlength=1) # 'm' or 'f'
> full_name = meta.CharField(maxlength=50)
>
> def get_absolute_url(self):
> return '/people/%s/%s/' % (self.gender,
> self.full_name.lower().replace(' ', ''))

I find this *really* surprising. All discussions and examples I've seen
so far are quite strict about the fact that models should be separate
from presentation logic. See the various discussions about "how can my
model get access to request.user?" here in this group. These arguments
made (make) perfect sense to me.

And now you're encoding URLs (which are, in my mind, definitely
presentation-related) in the models? To me, this seems strange and
unnatural. Why should a "Book" model care wether it has a view that
lives under "/library" or under "/amazon/shoppingcart" or under
"/thingtostopthetablefromwobbling" ? It's a book. It has properties. It
knows how to tell me its title.

But it shouldn't care wether it's being read or being used to prop up
furniture.

Or am I misunderstanding something here?

Daniel


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



Re: OneToOneField

2006-03-29 Thread layik

Hello there,

sorry to bother you.

I was wondering if you have solved your OneToOne problem. if so could
let me know how I could solve it as well??
thanks


ChaosKCW wrote:
> Agreeded, I am trying to use OneToOne in MR branch and get the same
> problems.
>
> I have:
>
> class Employee(models.Model):
>user = models.OneToOneField(User, verbose_name='Employees User ID')
>...
>
> And get the following error when trying to view the object in admin:
>
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/admin/traininglog/employee/
> Exception Type:   OperationalError
> Exception Value:  no such column: auth_user.username
> Exception Location:
>   
> c:\programming\python24\lib\site-packages\django-0.91-py2.4.egg\django\db\backends\sqlite3\base.py
> in execute, line 62
> 
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: OneToOneField

2006-03-29 Thread layik

might be a too late reply but could any of you tell me what MR Branch
or svn Trunk that you are tlkaing about is?

I am sorry I dont know any of them.

I still have the problem unsolved.

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



checklist

2006-03-29 Thread Jiri Barton

Hello there,

I want to display a checklist dynamically:

1 apple [ ]
3 pears [ ]
8 plums [ ]

([ ] stands for checkboxes)

The items are generated on the fly. I can create the form fields in a
manipulator __init__ dynamically, such as in:

for item in items:
self.fields.append(CheckboxField(fieldname="%s-%s" % (item.name,
item.number)))

Then, in the template:

{% for row in form %}
{{ row }}
{% endfor %}

This does not work because ``form`` is not a a list. How could I solve
this?

Then, I need to be able to display the labels next to the checkboxes.
But I cannot include them in self.fields because they are just texts.
How can I do it? I mean, do I need to create my own LabelField?

Thank you in advance.


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