Re: Specifying column names for ManyToMany fields

2010-08-16 Thread Russell Keith-Magee
On Fri, Aug 6, 2010 at 2:54 AM, Steven L Smith  wrote:
> Hello,
>
> I've been charged with creating a front-end in Django for a MSSQL
> database. It
> has to stay in MSSQL for various other reasons, so just using our
> normal
> Postgres stuff won't work.
>
> It is all working, except for the internal names of ManyToMany Fields.
> Our DBA
> likes to follow the CamelCaseStyle, and Django likes the
> underscore_style.
>
> The two options I've found are:
>
> 1.) Define the field like this, using through:
> websites = models.ManyToManyField('Website',
> through='DepartmentsWebsites',
> blank=True, null=True)
>
> The problem there is that a lot of the ORM is disabled when you use
> "through",
> and the admin won't display the MultipleSelectWidgets for a table that
> uses
> "through".
>
>
> 2.) Define the field like this, using "db_table":
> websites = models.ManyToManyField('Website',
> db_table='Departments_Websites',
> blank=True, null=True)
>
> The problem there is that the Departments_Websites table contains
> columns
> called ID, DepartmentID, and WebsiteID, but Django is still looking
> for id,
> department_id, and website_id.
>
> Any thoughts? Or would it be a LOT more difficult than just telling
> the DBA
> that we have to be slightly inconsistent in our naming schemes?

Apologies for taking so long to respond.

This is quite an old issue; it was originally logged as #785. The
solution you propose in (2) is closest to the originally proposed
solution.

However, #785 was closed when #6095 (m2m intermediate tables) was
introduced; rather than add lots of new parameters to ManyToManyField,
the decision was made to use a manually created m2m through model for
the purposes of table customization.

In this case, the situation you describe in (1) is a bug -- a simple
through model *should* be able to use the MultipleSelect widget, but
can't.

I'm inclined to call this an extension of #9475 -- a proposal to
ensure that the add()/remove() shortcuts continue to work with m2m
fields if the through model doesn't add anything beyond the basic
foreign keys to other models. At present, if you manually define a
through model, you lose the add()/remove() shortcuts on the m2m
relation. However, this limitation is only strictly required if the
through model has addition fields with non-default/non-nullable
values. This is essentially the same condition that would be
preventing the use of the MultipleSelect widget in admin.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: DjangoDash 2010 is done! Check out the projects done in 48 hours.

2010-08-16 Thread Stephen McDonald
I'm sure there are more entries than this, but here are the ones that
were posted around finishing time in IRC:

http://servertail.com/
http://transphorm.me/
http://www.buzz-fire.com/
http://dash.manoria.com/
http://ratemyflight.org/ <-- my team's
http://www.ihatexml.com/
http://repocracy.com/
http://permachart.appspot.com/
http://dashline.chronosbox.org/
http://readthedocs.org/
http://phonetapapp.appspot.com/
http://www.ihatexml.com/
http://hashfeedr.com/
http://drinkfindr.com/

Cheers,
Steve

On Aug 16, 4:07 pm, iJames  wrote:
> Hi programmers!
>
> I didn't see a posting about DjangoDash so I thought I would mention
> it since I didn't participate and so I'm awake.  And also because I
> didn't know about it but for a single podcast I happened to listen to.
>
> Kudos to the awesome teams who burned up the commits!
>
> DjangoDash 2010 was 48 hours of straight programming from a blank git-
> hub to a full working application.
>
> I just took a peek at some of the apps, it's an awesome testimonial to
> what can be done with some good thinking and planning, 48 hours of
> good coding, and an awesome framework like Django.
>
> Check it out here:  http://www.djangodash.com
>
> Now back to my own Django project.  It sure seems like I could be
> finishing it faster...  :-P
>
> James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Best OS - VPS environment

2010-08-16 Thread Dan
I have been using CentOS 5 to run Django sites with Apache + Mod WSGI
mostly in VPS environments.

I want to upgrade to a new OS as CentOS runs an old version of python
and it seems that it's not so easy to upgrade it.

What do people recommend?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.3

2010-08-16 Thread Ian Lewis
Kenneth,

>From my experience, South works well with mysql. However because
sqlite doesn't provide support for some schema alterations such as
dropping columns, it is as you said, pretty touchy.

Ian

On Mon, Aug 16, 2010 at 2:52 PM, Kenneth Gonsalves  wrote:
> On Mon, 2010-08-16 at 10:28 +1000, Lachlan Musicman wrote:
>> As I understand it the Django devs have requested it's integration,
>> and the
>> South dev has responded "I would like the South code to be cleaner and
>> smarter". I could be wrong about this.
>
> from what I see on IRC, it does not play well with mysql and sqllite - I
> have never used it.
> --
> regards
> Kenneth Gonsalves
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Best OS - VPS environment

2010-08-16 Thread Vali Lungu
My development environment includes Ubuntu 9.10 and 10.04. I'm also using
virtualenvs, but not w/ Apache. I'm using Nginx instead.
This configuration has been working flawlessly for me, and I'm implementing
it on all production servers too. It's quite fast and flexible, and quite
easy to install.

See http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/ for
more info. However, please note that the instructions concerning daemontools
are completely screwed up in this article (it's actually much simpler to set
it up).

On Mon, Aug 16, 2010 at 10:54 AM, Dan  wrote:

> I have been using CentOS 5 to run Django sites with Apache + Mod WSGI
> mostly in VPS environments.
>
> I want to upgrade to a new OS as CentOS runs an old version of python
> and it seems that it's not so easy to upgrade it.
>
> What do people recommend?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Best OS - VPS environment

2010-08-16 Thread Kenneth Gonsalves
On Mon, 2010-08-16 at 01:54 -0700, Dan wrote:
> What do people recommend?

debian lenny
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Best OS - VPS environment

2010-08-16 Thread Alex
FreeBSD

On Mon, Aug 16, 2010 at 12:39 PM, Kenneth Gonsalves wrote:

> On Mon, 2010-08-16 at 01:54 -0700, Dan wrote:
> > What do people recommend?
>
> debian lenny
> --
> regards
> Kenneth Gonsalves
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: content_object and comments

2010-08-16 Thread bruno desthuilliers
On 16 août, 08:14, shacker  wrote:
> I'm trying to figure out why this works:
>
> >>> comments = Comment.objects.all()
> >>>[c.content_object for c in comments]
>
> [returns a list of the objects the comments are attached to]
>
> But this doesn't:
>
> >>> c = Comment.objects.filter(id=111)
> >>> c
>
> []>>> c.content_object
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'QuerySet' object has no attribute 'content_object'

Of course. As the error message says, 'c' is here a queryset, not a
model object. If you want to retrieve a single model object, you have
to use manager.get, not manager.filter, ie:

>>> c = Comment.objects.get(id=111)
>>> c

>>> c.content_object
# your content object here

> The problem I'm trying to solve is that I've got a context processor
> that retrieves recent comments:
>
> def recent_comments(request):
>     return {'recent_comments': Comment.objects.filter().order_by('-id')
> [:6]}
>
> But if an item has been unpublished but still has comments attached to
> it, it crashes. So I want to alter the query in the content processor
> to only grab comments on items that have publish=True.

You won't be able to do this in a single SQL query. A Q&D solution
might be:

def recent_comments(request):
comments = Comment.objects.all().order_by('-id')
recent_comments = []
for comment in comments:
 if len(recent_comments) == 6: # XXX hardcoded, that's bad
 break
 content = comment.content_object()
 try:
  if content.publish:
  recent_comments.append(comment)
 except AttributeError
  # content has no 'publish' attribute
  pass
return dict(recent_comments=recent_comments)


If your comments are all on a same model class, you can possibly
optimize this by first retrieving a list of published objects AND the
content_type id for your model class, then filtering comments on these
values (implementation left as an exercice to the reader !-))

HTH

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



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Mark Mooij
Allright I tried a couple of things with your suggested appraoch:

- I printed all the strings used to define paths and files, this all
seems correct.

- The os.mkdir() command is passed without raising an error, but
without creating the directory either, this results in an "IOError: No
such file or directory" because of course a file can't be created in a
non-existing directory.

- I tried creating files in different already existing directories and
this works as expected.

- I tried to use os.makedirs() instead of os.mkdir(), this raises an
interesting error: "mkdir() takes exactly 1 argument (2 given)", I
tried calling the script outside of Django and this should work the
way I'm using it:

kmlpath = "%s/%s" % (basepath, game_id)
if not os.path.isdir(kmlpath):
os.makedirs(kmlpath)

- I tried creating a file without any directory structure in the path,
the file is created in the root of the website, if I try creating a
directory with os.mkdir() it should take the root as well I presume,
but no directory is created.

It seems that Django 1.2.1 has problems calling the os.mkdir() and
makedirs() commands ?

Mark

On 16 aug, 08:32, Mike Dewhirst  wrote:
> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>
>
>
>
>
> > On 16/08/2010 1:06am, Mark Mooij wrote:
> >> Hi Mike,
>
> >> Thanks for your reply. I haven't changed anything else, I am
> >> processing the MS updates, but I don't think this is the problem, as
> >> this all worked fine before the migration to 1.2.1, also if I call the
> >> script directly (outside Django) it works fine.
> >> My view looks like this:
> >> ..
> >> import createKML
> >> ..
> >> def my_view(request, arg):
> >> ...
> >> createKML.createKML(arg)
>
> > I don't really know what is happening here that might have changed in
> > 1.2.1 maybe someone else can suggest something.
>
> > In the meantime here is suggested approach to discovering the exact
> > problem ...
>
> > import os
> > ...
> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
> > ...
> > try:
> > if id:
> > kmlpath = "%s/%s" % (basepath, str(id))
>
> actually .. kmlpath = "%s/%s" % (basepath, id)
>
> > if not os.path.isdir(kmlpath):
> > os.makedirs(kmlpath)
> > writefile = "%s/%s" % (kmlpath, str(id))
>
> actually .. writefile = "%s/%s" % (kmlpath, id)
>
>
>
> > f = open(writefile, 'wb')
> > else:
> > raise
> > except Exception as e:
> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
> > ...
>
> > mike
>
> >> ...
>
> >> In the createKML.py the problem arises in:
> >> ...
> >> import os
> >> ...
> >> def createKML(id):
> >> ...
> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
> >> + ".kml"
> >> f = open(writefile, 'wb')
> >> ...
>
> >> I hope this helps?
>
> >> On 14 aug, 21:55, Mike Dewhirst wrote:
> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>
>  Hi all,
>
>  I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
>  application which imports an external python script in which a
>  directory and some files are created. Since the migrate this doesn't
>  work anymore, I get a number of IOErrors because the files (and
>  directory) that should be created can't be found. I've tried changing
>  my directories and slashes (I'm using Windows), but no success.
>
> >>> Have you changed anything else?
>
> >>> For example, are you processing the Microsoft Windows update patches
> >>> which (for WinXP) insert extra permission steps? Have you changed your
> >>> OS from XP to Win7?
>
> >>> Can you post the source of the script?
>
>  Can't I use the os python functions anymore in Django 1.2.1? In the
>  documentation I've read about Managing files in models but I prefer to
>  handle this through my external script.
>
>  I hope anybody can help me.
>
>  Thanks,
>  Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



multiple forms for same model

2010-08-16 Thread Mess
Hi,

I have a model where different users should have different
possibilities to edit, i.e. admin should be able to edit everything,
but users should only be able to edit certain fields.

My problem is that the user form doesn't validate when submitting
update as a user. But I get the error that the fields are missing even
though I can see them redisplayed.

I am looking at this tutorial:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
And I don't get what is different in my example since I pass "instance
= c" which contains the missing fields.

def update_contract(request,c):
if request.user.has_perm("contracts.is_admin") or
request.user.has_perm("contracts.is_internal"):
contract_form = ContractForm(request.POST, instance = c)
elif
request.user.has_perm("contracts.is_external"):
  contract_form = ContractFormExternal(request.POST,
instance = c)
if contract_form.is_valid():
contract_form.save()
return view_contract_details(request, c.pk, True)
else:
return render_to_response('contracts/
view_contract_details.html', {
'info_message' : 'Please correct the data in the
form',
'contract_form': contract_form,
'contract_id' : c.pk,
},context_instance=RequestContext(request))


Anyone can hint as to where it goes wrong or a hint to how to better
accomplish this?

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



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Doug Blank
On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
> Allright I tried a couple of things with your suggested appraoch:
>
> - I printed all the strings used to define paths and files, this all
> seems correct.
>
> - The os.mkdir() command is passed without raising an error, but
> without creating the directory either, this results in an "IOError: No
> such file or directory" because of course a file can't be created in a
> non-existing directory.
>
> - I tried creating files in different already existing directories and
> this works as expected.
>
> - I tried to use os.makedirs() instead of os.mkdir(), this raises an
> interesting error: "mkdir() takes exactly 1 argument (2 given)", I
> tried calling the script outside of Django and this should work the
> way I'm using it:
>
>        kmlpath = "%s/%s" % (basepath, game_id)
>        if not os.path.isdir(kmlpath):
>            os.makedirs(kmlpath)
>
> - I tried creating a file without any directory structure in the path,
> the file is created in the root of the website, if I try creating a
> directory with os.mkdir() it should take the root as well I presume,
> but no directory is created.
>
> It seems that Django 1.2.1 has problems calling the os.mkdir() and
> makedirs() commands ?

I doubt it. You shouldn't really do this:

kmlpath = "%s/%s" % (basepath, game_id)

but do this:

kmlpath = os.path.join(basepath, game_id)

as different OS's have different path formats. Or perhaps it is the
kml string that you are creating that has other issues (unicode?) I
would print out the mkdirs string to see what you are creating.

HTH,

-Doug

> Mark
>
> On 16 aug, 08:32, Mike Dewhirst  wrote:
>> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>>
>>
>>
>>
>>
>> > On 16/08/2010 1:06am, Mark Mooij wrote:
>> >> Hi Mike,
>>
>> >> Thanks for your reply. I haven't changed anything else, I am
>> >> processing the MS updates, but I don't think this is the problem, as
>> >> this all worked fine before the migration to 1.2.1, also if I call the
>> >> script directly (outside Django) it works fine.
>> >> My view looks like this:
>> >> ..
>> >> import createKML
>> >> ..
>> >> def my_view(request, arg):
>> >> ...
>> >> createKML.createKML(arg)
>>
>> > I don't really know what is happening here that might have changed in
>> > 1.2.1 maybe someone else can suggest something.
>>
>> > In the meantime here is suggested approach to discovering the exact
>> > problem ...
>>
>> > import os
>> > ...
>> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
>> > ...
>> > try:
>> > if id:
>> > kmlpath = "%s/%s" % (basepath, str(id))
>>
>> actually .. kmlpath = "%s/%s" % (basepath, id)
>>
>> > if not os.path.isdir(kmlpath):
>> > os.makedirs(kmlpath)
>> > writefile = "%s/%s" % (kmlpath, str(id))
>>
>> actually .. writefile = "%s/%s" % (kmlpath, id)
>>
>>
>>
>> > f = open(writefile, 'wb')
>> > else:
>> > raise
>> > except Exception as e:
>> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
>> > ...
>>
>> > mike
>>
>> >> ...
>>
>> >> In the createKML.py the problem arises in:
>> >> ...
>> >> import os
>> >> ...
>> >> def createKML(id):
>> >> ...
>> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
>> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
>> >> + ".kml"
>> >> f = open(writefile, 'wb')
>> >> ...
>>
>> >> I hope this helps?
>>
>> >> On 14 aug, 21:55, Mike Dewhirst wrote:
>> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>>
>>  Hi all,
>>
>>  I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
>>  application which imports an external python script in which a
>>  directory and some files are created. Since the migrate this doesn't
>>  work anymore, I get a number of IOErrors because the files (and
>>  directory) that should be created can't be found. I've tried changing
>>  my directories and slashes (I'm using Windows), but no success.
>>
>> >>> Have you changed anything else?
>>
>> >>> For example, are you processing the Microsoft Windows update patches
>> >>> which (for WinXP) insert extra permission steps? Have you changed your
>> >>> OS from XP to Win7?
>>
>> >>> Can you post the source of the script?
>>
>>  Can't I use the os python functions anymore in Django 1.2.1? In the
>>  documentation I've read about Managing files in models but I prefer to
>>  handle this through my external script.
>>
>>  I hope anybody can help me.
>>
>>  Thanks,
>>  Mark
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@googlegroups.com.
To

Re: multiple forms for same model

2010-08-16 Thread Scott Gould
You'll want to call is_valid() only if the request.method is "POST",
plus your code leaves the possibility of an error if none of those
permissions is found (your elif should probably simply be an else?).

On Aug 16, 6:49 am, Mess  wrote:
> Hi,
>
> I have a model where different users should have different
> possibilities to edit, i.e. admin should be able to edit everything,
> but users should only be able to edit certain fields.
>
> My problem is that the user form doesn't validate when submitting
> update as a user. But I get the error that the fields are missing even
> though I can see them redisplayed.
>
> I am looking at this 
> tutorial:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a...
> And I don't get what is different in my example since I pass "instance
> = c" which contains the missing fields.
>
> def update_contract(request,c):
>         if request.user.has_perm("contracts.is_admin") or
> request.user.has_perm("contracts.is_internal"):
>             contract_form = ContractForm(request.POST, instance = c)
>         elif
> request.user.has_perm("contracts.is_external"):
>               contract_form = ContractFormExternal(request.POST,
> instance = c)
>         if contract_form.is_valid():
>             contract_form.save()
>             return view_contract_details(request, c.pk, True)
>         else:
>             return render_to_response('contracts/
> view_contract_details.html', {
>                 'info_message' : 'Please correct the data in the
> form',
>                 'contract_form': contract_form,
>                 'contract_id' : c.pk,
>             },context_instance=RequestContext(request))
>
> Anyone can hint as to where it goes wrong or a hint to how to better
> accomplish this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: multiple forms for same model

2010-08-16 Thread Mess
Sorry, I had cut out some unimportant parts of the view causing that
error. The update_contract is called from another method only if it is
a POST.

My main issue is that it works as it should when logged in as admin
(probably because all the fields are in the admin version of the
form). But when logged in as external user and using different form
with only some of the fields, I get missing fields error. But the
contract_form still contains the data from all the fields.

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



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Mark Mooij
Hi Doug,

Thanks for your reply. I tried your suggestion:
..
import createKML
..
def createKML(id, basepath=os.getcwd()):
   ...
   try:
kmlpath = os.path.join(basepath, "templates")
kmlpath = os.path.join(kmlpath, "maps")
kmlpath = os.path.join(kmlpath, str(id))
if not os.path.isdir(kmlpath):
os.mkdir(kmlpath)
writefile = os.path.join(kmlpath, (str(id)+".kml"))

except Exception as e:
...

f = open(writefile, 'wb')

But no luck so far. using only os commands to define the directory
path should exclude any OS path formats issues I suppose? If I print
the paths they look just fine. I also tried hardcoding str(id) with a
predefined string but this doesn't work either, same problems arise.
Calling the script outside Django works fine (as did using the script
from Django 1.1.1), Also I find it strange that makedirs command rises
an error when calling from Django ("mkdir() takes exactly 1 argument
(2 given)"), but again outside Django this works just fine..

Hope anybody has any suggestions..
Mark

On 16 aug, 14:22, Doug Blank  wrote:
> On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
> > Allright I tried a couple of things with your suggested appraoch:
>
> > - I printed all the strings used to define paths and files, this all
> > seems correct.
>
> > - The os.mkdir() command is passed without raising an error, but
> > without creating the directory either, this results in an "IOError: No
> > such file or directory" because of course a file can't be created in a
> > non-existing directory.
>
> > - I tried creating files in different already existing directories and
> > this works as expected.
>
> > - I tried to use os.makedirs() instead of os.mkdir(), this raises an
> > interesting error: "mkdir() takes exactly 1 argument (2 given)", I
> > tried calling the script outside of Django and this should work the
> > way I'm using it:
>
> >        kmlpath = "%s/%s" % (basepath, game_id)
> >        if not os.path.isdir(kmlpath):
> >            os.makedirs(kmlpath)
>
> > - I tried creating a file without any directory structure in the path,
> > the file is created in the root of the website, if I try creating a
> > directory with os.mkdir() it should take the root as well I presume,
> > but no directory is created.
>
> > It seems that Django 1.2.1 has problems calling the os.mkdir() and
> > makedirs() commands ?
>
> I doubt it. You shouldn't really do this:
>
> kmlpath = "%s/%s" % (basepath, game_id)
>
> but do this:
>
> kmlpath = os.path.join(basepath, game_id)
>
> as different OS's have different path formats. Or perhaps it is the
> kml string that you are creating that has other issues (unicode?) I
> would print out the mkdirs string to see what you are creating.
>
> HTH,
>
> -Doug
>
>
>
> > Mark
>
> > On 16 aug, 08:32, Mike Dewhirst  wrote:
> >> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>
> >> > On 16/08/2010 1:06am, Mark Mooij wrote:
> >> >> Hi Mike,
>
> >> >> Thanks for your reply. I haven't changed anything else, I am
> >> >> processing the MS updates, but I don't think this is the problem, as
> >> >> this all worked fine before the migration to 1.2.1, also if I call the
> >> >> script directly (outside Django) it works fine.
> >> >> My view looks like this:
> >> >> ..
> >> >> import createKML
> >> >> ..
> >> >> def my_view(request, arg):
> >> >> ...
> >> >> createKML.createKML(arg)
>
> >> > I don't really know what is happening here that might have changed in
> >> > 1.2.1 maybe someone else can suggest something.
>
> >> > In the meantime here is suggested approach to discovering the exact
> >> > problem ...
>
> >> > import os
> >> > ...
> >> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
> >> > ...
> >> > try:
> >> > if id:
> >> > kmlpath = "%s/%s" % (basepath, str(id))
>
> >> actually .. kmlpath = "%s/%s" % (basepath, id)
>
> >> > if not os.path.isdir(kmlpath):
> >> > os.makedirs(kmlpath)
> >> > writefile = "%s/%s" % (kmlpath, str(id))
>
> >> actually .. writefile = "%s/%s" % (kmlpath, id)
>
> >> > f = open(writefile, 'wb')
> >> > else:
> >> > raise
> >> > except Exception as e:
> >> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
> >> > ...
>
> >> > mike
>
> >> >> ...
>
> >> >> In the createKML.py the problem arises in:
> >> >> ...
> >> >> import os
> >> >> ...
> >> >> def createKML(id):
> >> >> ...
> >> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
> >> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
> >> >> + ".kml"
> >> >> f = open(writefile, 'wb')
> >> >> ...
>
> >> >> I hope this helps?
>
> >> >> On 14 aug, 21:55, Mike Dewhirst wrote:
> >> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>
> >>  Hi all,
>
> >>  I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
> >>  application which imports an external python script in which a
> >>  directory and some files are created. Since the migrate this doesn't
> >>  work anymore, I get a number of IO

Re: convert textinput in label or text for a modelform and modelformset_factory

2010-08-16 Thread refreegrata
somebody have an idea ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: multiple forms for same model

2010-08-16 Thread Alex Robbins
I think the problem is that your form doesn't have all the required
data. When you assign the instance, you provide initial data, and
something for form.save to modify. However, when the data is posted
back, It looks like maybe the non-editable fields aren't in the POST
data. You could add the fields you don't want edited as readonly on
the front end, then do validation like this:
http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-be#answer-331550

I'm only guessing since I don't think you showed your forms.py or
template code.

Hope that helps,
Alex

On Aug 16, 8:14 am, Mess  wrote:
> Sorry, I had cut out some unimportant parts of the view causing that
> error. The update_contract is called from another method only if it is
> a POST.
>
> My main issue is that it works as it should when logged in as admin
> (probably because all the fields are in the admin version of the
> form). But when logged in as external user and using different form
> with only some of the fields, I get missing fields error. But the
> contract_form still contains the data from all the fields.

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



how to refresh a template' part

2010-08-16 Thread Imad Elharoussi
Hello

In my view.py I make connection with a distant server and i have to get an
object from it every minute
how can I do that without refreshing all the page

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-us...@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 refresh a template' part

2010-08-16 Thread Javier Guerra Giraldez
On Mon, Aug 16, 2010 at 9:29 AM, Imad Elharoussi
 wrote:
> Hello
>
> In my view.py I make connection with a distant server and i have to get an
> object from it every minute
> how can I do that without refreshing all the page

answer: AJAX
hint: jQuery  $('#refreshingelement').load(yoururl);

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: convert textinput in label or text for a modelform and modelformset_factory

2010-08-16 Thread refreegrata
{{ form.instance.field of the model }}

is a way to access.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Convert php project into django

2010-08-16 Thread Jagdeep Singh Malhi



> since python and php radically differ on the way things are done, it
> would be much quicker to rewrite the code afresh rather than attempt to
> translate it.

ok sir, 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-us...@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: DjangoDash 2010 is done! Check out the projects done in 48 hours.

2010-08-16 Thread Rolando Espinoza La Fuente
On Mon, Aug 16, 2010 at 4:53 AM, Stephen McDonald  wrote:
> I'm sure there are more entries than this, but here are the ones that
> were posted around finishing time in IRC:
>
> http://servertail.com/
> http://transphorm.me/
> http://www.buzz-fire.com/
> http://dash.manoria.com/
> http://ratemyflight.org/ <-- my team's
> http://www.ihatexml.com/
> http://repocracy.com/
> http://permachart.appspot.com/
> http://dashline.chronosbox.org/
> http://readthedocs.org/
> http://phonetapapp.appspot.com/
> http://www.ihatexml.com/
> http://hashfeedr.com/
> http://drinkfindr.com/

Here is mine: http://dash.darkrho.com

Lets you render one or multiple django templates and shows you the traceback
if there is an exception. Not complete and/or polish as the others,
but was fun to
hack around the template loader and the error reporter.

Regards,

Rolando Espinoza La fuente
www.insophia.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-us...@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: content_object and comments

2010-08-16 Thread shacker
On Aug 16, 3:17 am, bruno desthuilliers
 wrote:
>
> Of course. As the error message says, 'c' is here a queryset, not a
> model object. If you want to retrieve a single model object, you have
> to use manager.get, not manager.filter, ie:

Sorry about that brain fart - of course you're right - I just needed
get() instead of filter() there. Must have been late :)

> You won't be able to do this in a single SQL query. A Q&D solution
> might be:
>
> def recent_comments(request):
>     comments = Comment.objects.all().order_by('-id')
>     recent_comments = []
>     for comment in comments:
>          if len(recent_comments) == 6: # XXX hardcoded, that's bad
>              break
>          content = comment.content_object()
>          try:
>               if content.publish:
>                   recent_comments.append(comment)
>          except AttributeError
>               # content has no 'publish' attribute
>               pass
>     return dict(recent_comments=recent_comments)

I almost did get it down to a single query, but custom Model Managers
on the related content_object made things even more complicated, so I
settled on a custom list much like your example instead, which works
nicely. Thanks much!

./s

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



query evaluation problem

2010-08-16 Thread bagheera
Hi, i have "number" field in "newspaper" model.  I want assign to it  
dynamically a default value, witch would be a incremented by 1 highest  
value so far.
So i managed to make a little workaround, since i can't query for last  
value of "number" field of model from model itself.


I have created new model, witch has only 1 field any 1 record, witch  
stores current highest value.

I wrote two functions:


#-*- coding: utf-8 -*-
from nml.options.models import Wydanie_opt

def set_next(value):
try:
option = Wydanie_opt.objects.all()[0]
if value > option.nr_wydania_next:
option.nr_wydania_next = value
option.save()
except:
option = Wydanie_opt(nr_wydania_next = value)
option.save()

def get_next():
try:
option = Wydanie_opt.objects.all()[0]
value = option.nr_wydania_next
except:
return 0
else:
return value + 1

Here's code of "newspaper" model:


from nml.options.utils import get_next


class Wydanie(models.Model):
nr_wydania = models.PositiveIntegerField(verbose_name = "Numer  
wydania", unique = True, default = get_next(),

help_text = "Unikalny numer wydania.")

The problem is, set_next is working as intended, but get_next() does NOT,   
default value stays the same until i restart dev server. Why? Query isn't  
evaluated? get_next() function isn't called at all?

Mb there is a better way to implement auto-incrementation.
Keep in mind that, "nr_wydania" field must be visible and editable, since  
first entered value is unknown, some values may be skipped, and there is  
no order of adding it.

--
Linux user

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Encoding with {% url %} tag

2010-08-16 Thread shacker
On Aug 15, 9:34 am, aa56280  wrote:
> > Does the view code in app.views.blah know what to do with the
> > iriencode'd values?
>
> What does that have to do with anything?

More accurately, I should have asked "Does the URL definition and view
for app.views.blah know what to do with the
iriencode'd values?"

In other words, if you designed the URL regex to handle a certain sort
of string, and the view it points to handle a certain sort of string,
and now in your template you're running that string through iriencode
first, then the URL definition and the view it points to is receiving
something other than what it was meant to receive.

./s

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Best OS - VPS environment

2010-08-16 Thread daniels
+1 for Debian or FreeBSD and Nginx
Really fast/easy to setup and works withouth any problems.

On Aug 16, 12:48 pm, Alex  wrote:
> FreeBSD
>
> On Mon, Aug 16, 2010 at 12:39 PM, Kenneth Gonsalves wrote:
>
> > On Mon, 2010-08-16 at 01:54 -0700, Dan wrote:
> > > What do people recommend?
>
> > debian lenny
> > --
> > regards
> > Kenneth Gonsalves
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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-us...@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.



Changing a model of place from the admin site

2010-08-16 Thread Mathieu Leduc-Hamel
Hi all,

I'm currently developing a e-commerce website using satchmo and
django. I would like to simplify the admin pannel from the user
perspective. This is why i would like to change the different group of
models. Right now, these group are organized by application. But when
using some external dependencies it some become a big mess to deal
with so many different group of options.

Is it possible

There is a example of what i would like to do. There you have a part
of my admin site hierarchy. I would like to move "Categories" and
"Discounts" from the "Product" group to the "Store" group.

auth
  Groups
  Users
Contact
  Persons
  Organizations
Product
  Categories
  Discounts
Store
  Style
  Color
  Size

How can it be done ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Best OS - VPS environment

2010-08-16 Thread Mathieu Leduc-Hamel
Yeah but it's a little bit simpler with apache and mod_wsgi...

If i don't want to run a separate service like gunicorn or something like,
how can we do the same thing than apache+mod_wsgi but with nginx.

We've tried passenger but it's not very stable and not necessarily always
product's ready.

On Mon, Aug 16, 2010 at 6:43 PM, daniels  wrote:

> +1 for Debian or FreeBSD and Nginx
> Really fast/easy to setup and works withouth any problems.
>
> On Aug 16, 12:48 pm, Alex  wrote:
> > FreeBSD
> >
> > On Mon, Aug 16, 2010 at 12:39 PM, Kenneth Gonsalves  >wrote:
> >
> > > On Mon, 2010-08-16 at 01:54 -0700, Dan wrote:
> > > > What do people recommend?
> >
> > > debian lenny
> > > --
> > > regards
> > > Kenneth Gonsalves
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@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-us...@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-us...@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.



Copying the Django Admin Interface

2010-08-16 Thread Eric
Hello,

I am new to Django, and I am trying to develop an application for
researchers to submit data to a database.
I believe that the default admin interface from django.contrib.admin
should be just about perfect for the job. I
either want to subclass AdminSite and make my own administration page
that I direct users to, or I would like
to make a copy of the admin application.

I have been unsuccessful with both of these options. I can't find any
documentation on what exactly I need to
do in order to subclass AdminSite, and when I copy the contents of the
django/contrib/admin folder to
myproject/myapp/newadmin, and change my urls.py from
include(admin.site.urls) to
include(myproject.myapp.newadmin.site.urls), the new page doesn't take
because "site" doesn't refer to anything.
I find it odd though, because there is no "site" folder or file in the
django/contrib/admin directory, but admin.site.urls
still works.

If anyone has any idea what I am doing incorrectly, or any suggestions
about a better way to proceed with the task, I would greatly
appreciate your input.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: query evaluation problem

2010-08-16 Thread Alec Shaner
Regarding your issue with get_next, could be because you're invoking the
method when you define default=get_next(). Try it with just the bare method
name get_next.

You could also use the aggregate function instead of creating a new model:

http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#topics-db-aggregation

Just define get_next to call the Max aggregate on your Newspaper model's
number field.

On Mon, Aug 16, 2010 at 12:39 PM, bagheera  wrote:

> Hi, i have "number" field in "newspaper" model.  I want assign to it
> dynamically a default value, witch would be a incremented by 1 highest value
> so far.
> So i managed to make a little workaround, since i can't query for last
> value of "number" field of model from model itself.
>
> I have created new model, witch has only 1 field any 1 record, witch stores
> current highest value.
> I wrote two functions:
>
>
> #-*- coding: utf-8 -*-
> from nml.options.models import Wydanie_opt
>
> def set_next(value):
>try:
>option = Wydanie_opt.objects.all()[0]
>if value > option.nr_wydania_next:
>option.nr_wydania_next = value
>option.save()
>except:
>option = Wydanie_opt(nr_wydania_next = value)
>option.save()
>
> def get_next():
>try:
>option = Wydanie_opt.objects.all()[0]
>value = option.nr_wydania_next
>except:
>return 0
>else:
>return value + 1
>
> Here's code of "newspaper" model:
>
>
> from nml.options.utils import get_next
>
>
> class Wydanie(models.Model):
>nr_wydania = models.PositiveIntegerField(verbose_name = "Numer wydania",
> unique = True, default = get_next(),
>help_text = "Unikalny numer wydania.")
>
> The problem is, set_next is working as intended, but get_next() does NOT,
>  default value stays the same until i restart dev server. Why? Query isn't
> evaluated? get_next() function isn't called at all?
> Mb there is a better way to implement auto-incrementation.
> Keep in mind that, "nr_wydania" field must be visible and editable, since
> first entered value is unknown, some values may be skipped, and there is no
> order of adding it.
> --
> Linux user
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Encoding with {% url %} tag

2010-08-16 Thread aa56280
> In other words, if you designed the URL regex to handle a certain sort
> of string, and the view it points to handle a certain sort of string,
> and now in your template you're running that string through iriencode
> first, then the URL definition and the view it points to is receiving
> something other than what it was meant to receive.

Even if my regex is wrong, that doesn't mean the iriencode filter
wouldn't work - and that's really the crux of the matter here. I'm
applying the filter and string remains unchanged in the URL.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: query evaluation problem

2010-08-16 Thread Nick
How about using an autofield?

http://docs.djangoproject.com/en/dev/ref/models/fields/#autofield

On Aug 16, 12:25 pm, Alec Shaner  wrote:
> Regarding your issue with get_next, could be because you're invoking the
> method when you define default=get_next(). Try it with just the bare method
> name get_next.
>
> You could also use the aggregate function instead of creating a new model:
>
> http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#topics-db...
>
> Just define get_next to call the Max aggregate on your Newspaper model's
> number field.
>
> On Mon, Aug 16, 2010 at 12:39 PM, bagheera  wrote:
> > Hi, i have "number" field in "newspaper" model.  I want assign to it
> > dynamically a default value, witch would be a incremented by 1 highest value
> > so far.
> > So i managed to make a little workaround, since i can't query for last
> > value of "number" field of model from model itself.
>
> > I have created new model, witch has only 1 field any 1 record, witch stores
> > current highest value.
> > I wrote two functions:
>
> > #-*- coding: utf-8 -*-
> > from nml.options.models import Wydanie_opt
>
> > def set_next(value):
> >    try:
> >        option = Wydanie_opt.objects.all()[0]
> >        if value > option.nr_wydania_next:
> >            option.nr_wydania_next = value
> >            option.save()
> >    except:
> >        option = Wydanie_opt(nr_wydania_next = value)
> >        option.save()
>
> > def get_next():
> >    try:
> >        option = Wydanie_opt.objects.all()[0]
> >        value = option.nr_wydania_next
> >    except:
> >        return 0
> >    else:
> >        return value + 1
>
> > Here's code of "newspaper" model:
>
> > from nml.options.utils import get_next
>
> > class Wydanie(models.Model):
> >    nr_wydania = models.PositiveIntegerField(verbose_name = "Numer wydania",
> > unique = True, default = get_next(),
> >        help_text = "Unikalny numer wydania.")
>
> > The problem is, set_next is working as intended, but get_next() does NOT,
> >  default value stays the same until i restart dev server. Why? Query isn't
> > evaluated? get_next() function isn't called at all?
> > Mb there is a better way to implement auto-incrementation.
> > Keep in mind that, "nr_wydania" field must be visible and editable, since
> > first entered value is unknown, some values may be skipped, and there is no
> > order of adding it.
> > --
> > Linux user
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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-us...@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: query evaluation problem

2010-08-16 Thread bagheera

Dnia 16-08-2010 o 19:56:01 Nick  napisał(a):


How about using an autofield?

Nope. Autofield requires primary_key=True, filed need to be editable, so  
user can add values unordered, (10,11,12,13,17,25,9)


I'm checking out aggregation functions now.


--
Linux user

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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.



project management app

2010-08-16 Thread Bobby Roberts
hi all.

I've found http://code.google.com/p/django-project-management/ out
there as a project management app but have yet to install it and see
what all it can do.  Has anyone installed this and do you have an
opinion on it?  Is there anything else out there for project
management?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Best OS - VPS environment

2010-08-16 Thread Eric Elinow
> +1 for Debian or FreeBSD and Nginx
> Really fast/easy to setup and works withouth any problems.

I second the use of FreeBSD.  I personally go the route of FreeBSD 8.1 
w/Apache running mod_wsgi, forwarding static media requests to a lighttpd 
server.  This setup serves me well and is fairly simple to setup thanks to 
FreeBSD's sysinstall + ports collection.

-- Eric G. Elinow

> 
> 
> On Aug 16, 12:48 pm, Alex  wrote:
>> FreeBSD
>> 
>> On Mon, Aug 16, 2010 at 12:39 PM, Kenneth Gonsalves wrote:
>> 
>>> On Mon, 2010-08-16 at 01:54 -0700, Dan wrote:
 What do people recommend?
>> 
>>> debian lenny
>>> --
>>> regards
>>> Kenneth Gonsalves
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@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-us...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Long running process and time outs?

2010-08-16 Thread hcarvalhoalves
Or you can just run the long running task on a separate thread.

def my_long_running_function():
...

t = threading.Thread(target=my_long_running_function)
t.setDaemon(True)
t.start()

Then make a view that has access to the result calculated on this
thread, and shows the result when it's done running. The drawback with
this is that you will occupy one Django processes working on this, so
it's not particularly suited for lots of concurrent users.

Reserve queues for when you have more concurrency, or more tasks with
this behaviour. There's a whole new layer of complexity you have to
manage once you implement queues.

On Aug 15, 10:30 pm, Javier Guerra Giraldez 
wrote:
> On Sat, Aug 14, 2010 at 1:28 PM, ydjango  wrote:
> > I have a online user initiated synchronous process which runs anywhere
> > between 1-5 minutes and gives user status message at the end. It is a
> > very DB intensive process that reads and updates lots of mysql rows
> > and does many calculations. The process is run as part of a view
> > method.
>
> long-running tasks don't belong to the request-responce cycle, send
> them to a background process.
>
> one of the easiest solutions is to use "Ghetto Queues". it can look like this:
>
> - create a new 'task' table, with fields to specify how to process a
> task and a status field (preparing, ready, processing, done, failed),
> if needed a 'result' field and if possible a 'percent done' field too.
>
> - when the user initiates a task, don't process it in the view
> function.  just add  a new record to the task table, with all the info
> needed to process it and set in 'ready' state.  then return.  don't
> forget to note the task record ID somewhere you can relate to the
> user's action.
>
> - another process, separate from the Django server (can be a cron task
> in many cases) checks the task table and picks any record in 'ready'
> state to do all the needed processing, first changing it to
> 'processing' state.  it should update the 'percent done' field, and
> set to 'done' or 'failed' when finished.
>
> - make some way for the user to get the status of the task, either
> revisiting the same URL (which should show the status if there's a
> task in 'processing'), or via some AJAX query.
>
> there are many variations of this strategy: you can have several
> 'workers' if you pay attention to the way it picks a task and sets to
> 'processing' (transactions make it easy to atomically pick one), if
> you need low latency between queuing a task and picking it by the
> worker process, you can replace the task table with a queue manager
> (check carrot and/or celery)
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Validation and dynamically extending ChoiceField choices

2010-08-16 Thread ringemup
I have a domain search form with two fields: a Textarea for inputting
a list of domains to check, and a ChoiceField for selecting a domain
based on suggestions.

The ChoiceField is required, and on the first submission is auto-
populated with suggestions based on the domains listed in the
textarea.  Subsequently, the user may either enter a new list of
domains to check, or select a domain from the radio buttons.

However, when they select one of the radio buttons, the form never
validates because the selected domain "is not one of the available
choices" -- because, of course, the choices are populated only after
the form is submitted.

I'm having trouble working around this because of the messiness that
is Django's FormWizard.  Any suggestions?

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-us...@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: query evaluation problem [SOLVED]

2010-08-16 Thread bagheera

Dnia 16-08-2010 o 19:25:50 Alec Shaner  napisał(a):


Regarding your issue with get_next, could be because you're invoking the
method when you define default=get_next(). Try it with just the bare  
method

name get_next.

You could also use the aggregate function instead of creating a new  
model:





Thanks! I figured that out:
from django.db.models import Max

def get_val(dictionary):
try:
return dictionary['number__max'] + 1
except:
return 0

class Newspaper(models.Model):
number = models.PositiveIntegerField(unique = True,  default = lambda  
: get_val(Newspaper.objects.aggregate(Max('number'





http://docs.djangoproject.com/en/1.2/topics/db/aggregation/#topics-db-aggregation

Just define get_next to call the Max aggregate on your Newspaper model's
number field.

On Mon, Aug 16, 2010 at 12:39 PM, bagheera  wrote:


Hi, i have "number" field in "newspaper" model.  I want assign to it
dynamically a default value, witch would be a incremented by 1 highest  
value

so far.
So i managed to make a little workaround, since i can't query for last
value of "number" field of model from model itself.

I have created new model, witch has only 1 field any 1 record, witch  
stores

current highest value.
I wrote two functions:


#-*- coding: utf-8 -*-
from nml.options.models import Wydanie_opt

def set_next(value):
   try:
   option = Wydanie_opt.objects.all()[0]
   if value > option.nr_wydania_next:
   option.nr_wydania_next = value
   option.save()
   except:
   option = Wydanie_opt(nr_wydania_next = value)
   option.save()

def get_next():
   try:
   option = Wydanie_opt.objects.all()[0]
   value = option.nr_wydania_next
   except:
   return 0
   else:
   return value + 1

Here's code of "newspaper" model:


from nml.options.utils import get_next


class Wydanie(models.Model):
   nr_wydania = models.PositiveIntegerField(verbose_name = "Numer  
wydania",

unique = True, default = get_next(),
   help_text = "Unikalny numer wydania.")

The problem is, set_next is working as intended, but get_next() does  
NOT,
 default value stays the same until i restart dev server. Why? Query  
isn't

evaluated? get_next() function isn't called at all?
Mb there is a better way to implement auto-incrementation.
Keep in mind that, "nr_wydania" field must be visible and editable,  
since
first entered value is unknown, some values may be skipped, and there  
is no

order of adding it.
--
Linux user

--
You received this message because you are subscribed to the Google  
Groups

"Django users" group.
To post to this group, send email to django-us...@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.







--
Linux user

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



Re: Long running process and time outs?

2010-08-16 Thread ydjango
Thanks,
Is there a way to put the process in a different thread or background
job directly from django view  (without going through a queue and
cron)?
I heard Python is not very good with multi threading because of GIL. I
am on Python 2.5


On Aug 15, 6:30 pm, Javier Guerra Giraldez  wrote:
> On Sat, Aug 14, 2010 at 1:28 PM, ydjango  wrote:
> > I have a online user initiated synchronous process which runs anywhere
> > between 1-5 minutes and gives user status message at the end. It is a
> > very DB intensive process that reads and updates lots of mysql rows
> > and does many calculations. The process is run as part of a view
> > method.
>
> long-running tasks don't belong to the request-responce cycle, send
> them to a background process.
>
> one of the easiest solutions is to use "Ghetto Queues". it can look like this:
>
> - create a new 'task' table, with fields to specify how to process a
> task and a status field (preparing, ready, processing, done, failed),
> if needed a 'result' field and if possible a 'percent done' field too.
>
> - when the user initiates a task, don't process it in the view
> function.  just add  a new record to the task table, with all the info
> needed to process it and set in 'ready' state.  then return.  don't
> forget to note the task record ID somewhere you can relate to the
> user's action.
>
> - another process, separate from the Django server (can be a cron task
> in many cases) checks the task table and picks any record in 'ready'
> state to do all the needed processing, first changing it to
> 'processing' state.  it should update the 'percent done' field, and
> set to 'done' or 'failed' when finished.
>
> - make some way for the user to get the status of the task, either
> revisiting the same URL (which should show the status if there's a
> task in 'processing'), or via some AJAX query.
>
> there are many variations of this strategy: you can have several
> 'workers' if you pay attention to the way it picks a task and sets to
> 'processing' (transactions make it easy to atomically pick one), if
> you need low latency between queuing a task and picking it by the
> worker process, you can replace the task table with a queue manager
> (check carrot and/or celery)
>
> --
> Javier

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



Re: Long running process and time outs?

2010-08-16 Thread Javier Guerra Giraldez
On Mon, Aug 16, 2010 at 1:43 PM, ydjango  wrote:
> Is there a way to put the process in a different thread or background
> job directly from django view  (without going through a queue and
> cron)?

sure, you could simply execute an external process; but then you have
to be sure not to start too many of them (specially two of the same,
when the user gets click-happy), poll status and result, etc.  been
there, got bored, reinvented ghetto queues (and only recently found
they had a name)

> I heard Python is not very good with multi threading because of GIL. I
> am on Python 2.5

this is only a concern if your processing is CPU bound.  if so,
another reason to go off-process.

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



using acrobat fdf in templates

2010-08-16 Thread Sells, Fred
I'm trying to use the Django template system to render PDF's from .fdf's.  The 
PDF's are provided by client and I can generate a dummy .fdf from them and edit 
that.  I can use pdftk to merge the two, but it seems like the template system 
does something similar. 

My first problem is that the .fdf has "%" characters in it and I cannot find 
how to escape them in Django.  I guess I could define a variable named 
"percent" and use that to insert the % into the template.

Here's a snippet of my test .fdf file.  Is this idea feasible, or am I trying 
to push a chain?

%FDF-1.2
1 0 obj
<>
<>
<>

<>
]
endobj

trailer
<>
%%EOF

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



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Doug Blank
On Mon, Aug 16, 2010 at 9:49 AM, Mark Mooij  wrote:
> Hi Doug,
>
> Thanks for your reply. I tried your suggestion:
> ..
> import createKML
> ..
> def createKML(id, basepath=os.getcwd()):
>   ...
>   try:
>        kmlpath = os.path.join(basepath, "templates")
>        kmlpath = os.path.join(kmlpath, "maps")
>        kmlpath = os.path.join(kmlpath, str(id))
>        if not os.path.isdir(kmlpath):
>            os.mkdir(kmlpath)
>        writefile = os.path.join(kmlpath, (str(id)+".kml"))
>
>    except Exception as e:
>        ...
>
>    f = open(writefile, 'wb')

BTW, you can:

kmlpath = os.path.join(basepath, "templates", "maps", str(id))

[snip]

> Also I find it strange that makedirs command rises
> an error when calling from Django ("mkdir() takes exactly 1 argument
> (2 given)"), but again outside Django this works just fine..

Ok, that is very suspicious. It sounds like there is another os module
that you are somehow getting, rather than the Python system one.
Perhaps have a look at os.__file__ to see if that is the correct
version.

-Doug

> Hope anybody has any suggestions..
> Mark
>
> On 16 aug, 14:22, Doug Blank  wrote:
>> On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
>> > Allright I tried a couple of things with your suggested appraoch:
>>
>> > - I printed all the strings used to define paths and files, this all
>> > seems correct.
>>
>> > - The os.mkdir() command is passed without raising an error, but
>> > without creating the directory either, this results in an "IOError: No
>> > such file or directory" because of course a file can't be created in a
>> > non-existing directory.
>>
>> > - I tried creating files in different already existing directories and
>> > this works as expected.
>>
>> > - I tried to use os.makedirs() instead of os.mkdir(), this raises an
>> > interesting error: "mkdir() takes exactly 1 argument (2 given)", I
>> > tried calling the script outside of Django and this should work the
>> > way I'm using it:
>>
>> >        kmlpath = "%s/%s" % (basepath, game_id)
>> >        if not os.path.isdir(kmlpath):
>> >            os.makedirs(kmlpath)
>>
>> > - I tried creating a file without any directory structure in the path,
>> > the file is created in the root of the website, if I try creating a
>> > directory with os.mkdir() it should take the root as well I presume,
>> > but no directory is created.
>>
>> > It seems that Django 1.2.1 has problems calling the os.mkdir() and
>> > makedirs() commands ?
>>
>> I doubt it. You shouldn't really do this:
>>
>> kmlpath = "%s/%s" % (basepath, game_id)
>>
>> but do this:
>>
>> kmlpath = os.path.join(basepath, game_id)
>>
>> as different OS's have different path formats. Or perhaps it is the
>> kml string that you are creating that has other issues (unicode?) I
>> would print out the mkdirs string to see what you are creating.
>>
>> HTH,
>>
>> -Doug
>>
>>
>>
>> > Mark
>>
>> > On 16 aug, 08:32, Mike Dewhirst  wrote:
>> >> On 16/08/2010 12:57pm, Mike Dewhirst wrote:
>>
>> >> > On 16/08/2010 1:06am, Mark Mooij wrote:
>> >> >> Hi Mike,
>>
>> >> >> Thanks for your reply. I haven't changed anything else, I am
>> >> >> processing the MS updates, but I don't think this is the problem, as
>> >> >> this all worked fine before the migration to 1.2.1, also if I call the
>> >> >> script directly (outside Django) it works fine.
>> >> >> My view looks like this:
>> >> >> ..
>> >> >> import createKML
>> >> >> ..
>> >> >> def my_view(request, arg):
>> >> >> ...
>> >> >> createKML.createKML(arg)
>>
>> >> > I don't really know what is happening here that might have changed in
>> >> > 1.2.1 maybe someone else can suggest something.
>>
>> >> > In the meantime here is suggested approach to discovering the exact
>> >> > problem ...
>>
>> >> > import os
>> >> > ...
>> >> > def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
>> >> > ...
>> >> > try:
>> >> > if id:
>> >> > kmlpath = "%s/%s" % (basepath, str(id))
>>
>> >> actually .. kmlpath = "%s/%s" % (basepath, id)
>>
>> >> > if not os.path.isdir(kmlpath):
>> >> > os.makedirs(kmlpath)
>> >> > writefile = "%s/%s" % (kmlpath, str(id))
>>
>> >> actually .. writefile = "%s/%s" % (kmlpath, id)
>>
>> >> > f = open(writefile, 'wb')
>> >> > else:
>> >> > raise
>> >> > except Exception as e:
>> >> > print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
>> >> > ...
>>
>> >> > mike
>>
>> >> >> ...
>>
>> >> >> In the createKML.py the problem arises in:
>> >> >> ...
>> >> >> import os
>> >> >> ...
>> >> >> def createKML(id):
>> >> >> ...
>> >> >> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
>> >> >> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
>> >> >> + ".kml"
>> >> >> f = open(writefile, 'wb')
>> >> >> ...
>>
>> >> >> I hope this helps?
>>
>> >> >> On 14 aug, 21:55, Mike Dewhirst wrote:
>> >> >>> On 15/08/2010 12:10am, Mark Mooij wrote:
>>
>> >>  Hi all,
>>
>> >>  I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
>> >>  application which imports an ext

MySQL Newbie question

2010-08-16 Thread Bradley Hintze
Hi all,

I'm trying to install MySQL for Python on Snow Leopard and I get :

sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in 
metadata, options = get_config()
  File "/Users/bradleyhintze/Desktop/MySQL-python-1.2.3/setup_posix.py",
line 43, in get_config
libs = mysql_config("libs_r")
  File "/Users/bradleyhintze/Desktop/MySQL-python-1.2.3/setup_posix.py",
line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found


There is a lot of supposed help online for this but after a few hors
of googling I have yet to find mysql_config on my machine. Is there
another package that I must install first?

-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Wendy
Thanks Nick,
I tried the first solution first.
You're right, the many to manys aren't editable on that page, but the
problem is, I'm not seeing another admin page for the new join model:

class FilmmakerPosition(models.Model):
 filmmaker = models.ForeignKey(Filmmaker)
 film = models.ForeignKey(Film)
 position = models.IntegerField()

(it is in the db)
so there's no way I can assign filmmakers to a film in the admin.
In the Film class it specifies:

filmmakers = models.ManyToManyField(Filmmaker,
through='FilmmakerPosition')


Am I missing something?

I was slightly more intimidated by the inline example, as I'm not sure
I want to scrap the many to many relationship.  (there are lots of
films that have multiple filmmakers and vice versa, and I'd like to be
able to list them on both ends)  I'm still trying to wrap my head
around how I could do that with this example.

If anyone has anything else to add that would help me understand it
better, I'd really appreciate it.

Thanks,
Wendy


On Aug 13, 10:03 am, Nick Serra  wrote:
> You can go two directions with this. First, you could use a
> intermediate model for the many to many join, which would allow you to
> specify extra field on the join, in this case the order. Read up on
> this 
> here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> The problem with solution one is that the many to many won't be
> editable on that page anymore.
>
> Solution two would be to scrap the manytomany and use inline models
> instead. You would make an intermediate model, say FilmmakerItem,
> which would foreign key to the model you want to join to, and a
> foreign key to the filmmaker, and would have a field for order. This
> would be editable in the admin under the same page.
>
> Read about inline 
> here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> On Aug 13, 12:52 pm, Wendy  wrote:
>
> > I have a many to many field, with the horizontal available and chosen
> > boxes in the admin.  I wanted to see if there's any way that an admin
> > can select the order that the chosen objects show up, and have it be
> > saved and display that way.  Right now, they're not ordered, but seem
> > to show up based on when the object was created.  So I'm choosing
> > filmmakers for a film, and the only way I can change the order is to
> > destroy the filmmaker objects, then recreate and add them in a
> > different order, something that obviously wouldn't work in the real
> > world.  Is there any way to save the order in the chosen box in the
> > admin?
>
> > Thanks,
> > Wendy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Nick Serra
The inline solution is the pretty way to do it. If you just want the
join to show up in the admin, then simply register the join model in
the admin like any other model. In your admin,py include
FilmmakerPosition and then do admin.site.register(FilmmakerPosition)

On Aug 16, 3:24 pm, Wendy  wrote:
> Thanks Nick,
> I tried the first solution first.
> You're right, the many to manys aren't editable on that page, but the
> problem is, I'm not seeing another admin page for the new join model:
>
> class FilmmakerPosition(models.Model):
>          filmmaker = models.ForeignKey(Filmmaker)
>          film = models.ForeignKey(Film)
>          position = models.IntegerField()
> 
> (it is in the db)
> so there's no way I can assign filmmakers to a film in the admin.
> In the Film class it specifies:
> 
> filmmakers = models.ManyToManyField(Filmmaker,
> through='FilmmakerPosition')
> 
>
> Am I missing something?
>
> I was slightly more intimidated by the inline example, as I'm not sure
> I want to scrap the many to many relationship.  (there are lots of
> films that have multiple filmmakers and vice versa, and I'd like to be
> able to list them on both ends)  I'm still trying to wrap my head
> around how I could do that with this example.
>
> If anyone has anything else to add that would help me understand it
> better, I'd really appreciate it.
>
> Thanks,
> Wendy
>
> On Aug 13, 10:03 am, Nick Serra  wrote:
>
>
>
> > You can go two directions with this. First, you could use a
> > intermediate model for the many to many join, which would allow you to
> > specify extra field on the join, in this case the order. Read up on
> > this 
> > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > The problem with solution one is that the many to many won't be
> > editable on that page anymore.
>
> > Solution two would be to scrap the manytomany and use inline models
> > instead. You would make an intermediate model, say FilmmakerItem,
> > which would foreign key to the model you want to join to, and a
> > foreign key to the filmmaker, and would have a field for order. This
> > would be editable in the admin under the same page.
>
> > Read about inline 
> > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> > On Aug 13, 12:52 pm, Wendy  wrote:
>
> > > I have a many to many field, with the horizontal available and chosen
> > > boxes in the admin.  I wanted to see if there's any way that an admin
> > > can select the order that the chosen objects show up, and have it be
> > > saved and display that way.  Right now, they're not ordered, but seem
> > > to show up based on when the object was created.  So I'm choosing
> > > filmmakers for a film, and the only way I can change the order is to
> > > destroy the filmmaker objects, then recreate and add them in a
> > > different order, something that obviously wouldn't work in the real
> > > world.  Is there any way to save the order in the chosen box in the
> > > admin?
>
> > > Thanks,
> > > Wendy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Wendy
Thanks, Nick, I just figured that out, doh!  So I got the first
example going, I guess I'll try the inline solution as well, if it's
the pretty way to do it...  It'll be good for me to actually see what
they both do.
W



On Aug 16, 12:28 pm, Nick Serra  wrote:
> The inline solution is the pretty way to do it. If you just want the
> join to show up in the admin, then simply register the join model in
> the admin like any other model. In your admin,py include
> FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> On Aug 16, 3:24 pm, Wendy  wrote:
>
> > Thanks Nick,
> > I tried the first solution first.
> > You're right, the many to manys aren't editable on that page, but the
> > problem is, I'm not seeing another admin page for the new join model:
>
> > class FilmmakerPosition(models.Model):
> >          filmmaker = models.ForeignKey(Filmmaker)
> >          film = models.ForeignKey(Film)
> >          position = models.IntegerField()
> > 
> > (it is in the db)
> > so there's no way I can assign filmmakers to a film in the admin.
> > In the Film class it specifies:
> > 
> > filmmakers = models.ManyToManyField(Filmmaker,
> > through='FilmmakerPosition')
> > 
>
> > Am I missing something?
>
> > I was slightly more intimidated by the inline example, as I'm not sure
> > I want to scrap the many to many relationship.  (there are lots of
> > films that have multiple filmmakers and vice versa, and I'd like to be
> > able to list them on both ends)  I'm still trying to wrap my head
> > around how I could do that with this example.
>
> > If anyone has anything else to add that would help me understand it
> > better, I'd really appreciate it.
>
> > Thanks,
> > Wendy
>
> > On Aug 13, 10:03 am, Nick Serra  wrote:
>
> > > You can go two directions with this. First, you could use a
> > > intermediate model for the many to many join, which would allow you to
> > > specify extra field on the join, in this case the order. Read up on
> > > this 
> > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > The problem with solution one is that the many to many won't be
> > > editable on that page anymore.
>
> > > Solution two would be to scrap the manytomany and use inline models
> > > instead. You would make an intermediate model, say FilmmakerItem,
> > > which would foreign key to the model you want to join to, and a
> > > foreign key to the filmmaker, and would have a field for order. This
> > > would be editable in the admin under the same page.
>
> > > Read about inline 
> > > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> > > On Aug 13, 12:52 pm, Wendy  wrote:
>
> > > > I have a many to many field, with the horizontal available and chosen
> > > > boxes in the admin.  I wanted to see if there's any way that an admin
> > > > can select the order that the chosen objects show up, and have it be
> > > > saved and display that way.  Right now, they're not ordered, but seem
> > > > to show up based on when the object was created.  So I'm choosing
> > > > filmmakers for a film, and the only way I can change the order is to
> > > > destroy the filmmaker objects, then recreate and add them in a
> > > > different order, something that obviously wouldn't work in the real
> > > > world.  Is there any way to save the order in the chosen box in the
> > > > admin?
>
> > > > Thanks,
> > > > Wendy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Using localhost in MEDIA_URL causing very slow django

2010-08-16 Thread Steve Holden
On 8/16/2010 2:25 AM, Martin Lundberg wrote:
> Hi,
> 
> I started having a problem on my website when working on it locally
> using the runserver dev server. If I started the server I could visit
> a page once (and it loaded quickly) but if I reloaded the page it
> could take like 10 minutes for it to load. The code didn't even reach
> the view. I tracked the problem down to the use of MEDIA_URL in my
> base.html. I looked at my MEDIA_URL setting and it was set to
> http://localhost:8000/media/. Since I'm using http://127.0.0.1:8000/
> to access the page I tried changing the setting to 127.0.0.1 as well
> and for some reason the problem went away.
> 
> I'm curious to know if someone know why this was a problem?¨
> 
I would suspect a DNS issue - though this doesn't off-hand explain to me
why the page loaded so quickly the first time.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Loop over a form's choices (radio button) and render it

2010-08-16 Thread Bill Freeman
Ok.  I have permission from my boss, and have cleaned it up a bit.  See:

http://djangosnippets.org/snippets/2151/

Bill

On Sat, Aug 14, 2010 at 7:25 AM, Andreas Pfrengle  wrote:
> Hello Bill,
>
> thanks for your answer. However, I've never written a template filter
> yet. Would you present the code of your checkboxiterator? Is there
> sth. on djangosnippets?
>
> Andreas
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Ordering in the admin

2010-08-16 Thread Wendy
OK, I have the inline solution working in the admin, I can see why
it's prettier!
Now I'm trying to figure out how to refer to these filmmakers in my
film list template, as there is no longer a film.filmmakers object...
So when I look in mysql, films_filmmakerposition has an id, a
filmmaker id, a film id and a position.
My Filmmaker Object has a first name and last name.
I'm not sure where to start on this one, any help would be greatly
appreciated.
Thanks,
Wendy

On Aug 16, 12:45 pm, Wendy  wrote:
> Thanks, Nick, I just figured that out, doh!  So I got the first
> example going, I guess I'll try the inline solution as well, if it's
> the pretty way to do it...  It'll be good for me to actually see what
> they both do.
> W
>
> On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > The inline solution is the pretty way to do it. If you just want the
> > join to show up in the admin, then simply register the join model in
> > the admin like any other model. In your admin,py include
> > FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > Thanks Nick,
> > > I tried the first solution first.
> > > You're right, the many to manys aren't editable on that page, but the
> > > problem is, I'm not seeing another admin page for the new join model:
>
> > > class FilmmakerPosition(models.Model):
> > >          filmmaker = models.ForeignKey(Filmmaker)
> > >          film = models.ForeignKey(Film)
> > >          position = models.IntegerField()
> > > 
> > > (it is in the db)
> > > so there's no way I can assign filmmakers to a film in the admin.
> > > In the Film class it specifies:
> > > 
> > > filmmakers = models.ManyToManyField(Filmmaker,
> > > through='FilmmakerPosition')
> > > 
>
> > > Am I missing something?
>
> > > I was slightly more intimidated by the inline example, as I'm not sure
> > > I want to scrap the many to many relationship.  (there are lots of
> > > films that have multiple filmmakers and vice versa, and I'd like to be
> > > able to list them on both ends)  I'm still trying to wrap my head
> > > around how I could do that with this example.
>
> > > If anyone has anything else to add that would help me understand it
> > > better, I'd really appreciate it.
>
> > > Thanks,
> > > Wendy
>
> > > On Aug 13, 10:03 am, Nick Serra  wrote:
>
> > > > You can go two directions with this. First, you could use a
> > > > intermediate model for the many to many join, which would allow you to
> > > > specify extra field on the join, in this case the order. Read up on
> > > > this 
> > > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > > The problem with solution one is that the many to many won't be
> > > > editable on that page anymore.
>
> > > > Solution two would be to scrap the manytomany and use inline models
> > > > instead. You would make an intermediate model, say FilmmakerItem,
> > > > which would foreign key to the model you want to join to, and a
> > > > foreign key to the filmmaker, and would have a field for order. This
> > > > would be editable in the admin under the same page.
>
> > > > Read about inline 
> > > > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> > > > On Aug 13, 12:52 pm, Wendy  wrote:
>
> > > > > I have a many to many field, with the horizontal available and chosen
> > > > > boxes in the admin.  I wanted to see if there's any way that an admin
> > > > > can select the order that the chosen objects show up, and have it be
> > > > > saved and display that way.  Right now, they're not ordered, but seem
> > > > > to show up based on when the object was created.  So I'm choosing
> > > > > filmmakers for a film, and the only way I can change the order is to
> > > > > destroy the filmmaker objects, then recreate and add them in a
> > > > > different order, something that obviously wouldn't work in the real
> > > > > world.  Is there any way to save the order in the chosen box in the
> > > > > admin?
>
> > > > > Thanks,
> > > > > Wendy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Nick Serra
Can you list your models.py for me? What exactly do you want to show
in your template? I'm guessing some sort of WHERE clause, like all
filmmakers for a film or something.

On Aug 16, 5:08 pm, Wendy  wrote:
> OK, I have the inline solution working in the admin, I can see why
> it's prettier!
> Now I'm trying to figure out how to refer to these filmmakers in my
> film list template, as there is no longer a film.filmmakers object...
> So when I look in mysql, films_filmmakerposition has an id, a
> filmmaker id, a film id and a position.
> My Filmmaker Object has a first name and last name.
> I'm not sure where to start on this one, any help would be greatly
> appreciated.
> Thanks,
> Wendy
>
> On Aug 16, 12:45 pm, Wendy  wrote:
>
>
>
> > Thanks, Nick, I just figured that out, doh!  So I got the first
> > example going, I guess I'll try the inline solution as well, if it's
> > the pretty way to do it...  It'll be good for me to actually see what
> > they both do.
> > W
>
> > On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > > The inline solution is the pretty way to do it. If you just want the
> > > join to show up in the admin, then simply register the join model in
> > > the admin like any other model. In your admin,py include
> > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> > > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > > Thanks Nick,
> > > > I tried the first solution first.
> > > > You're right, the many to manys aren't editable on that page, but the
> > > > problem is, I'm not seeing another admin page for the new join model:
>
> > > > class FilmmakerPosition(models.Model):
> > > >          filmmaker = models.ForeignKey(Filmmaker)
> > > >          film = models.ForeignKey(Film)
> > > >          position = models.IntegerField()
> > > > 
> > > > (it is in the db)
> > > > so there's no way I can assign filmmakers to a film in the admin.
> > > > In the Film class it specifies:
> > > > 
> > > > filmmakers = models.ManyToManyField(Filmmaker,
> > > > through='FilmmakerPosition')
> > > > 
>
> > > > Am I missing something?
>
> > > > I was slightly more intimidated by the inline example, as I'm not sure
> > > > I want to scrap the many to many relationship.  (there are lots of
> > > > films that have multiple filmmakers and vice versa, and I'd like to be
> > > > able to list them on both ends)  I'm still trying to wrap my head
> > > > around how I could do that with this example.
>
> > > > If anyone has anything else to add that would help me understand it
> > > > better, I'd really appreciate it.
>
> > > > Thanks,
> > > > Wendy
>
> > > > On Aug 13, 10:03 am, Nick Serra  wrote:
>
> > > > > You can go two directions with this. First, you could use a
> > > > > intermediate model for the many to many join, which would allow you to
> > > > > specify extra field on the join, in this case the order. Read up on
> > > > > this 
> > > > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > > > The problem with solution one is that the many to many won't be
> > > > > editable on that page anymore.
>
> > > > > Solution two would be to scrap the manytomany and use inline models
> > > > > instead. You would make an intermediate model, say FilmmakerItem,
> > > > > which would foreign key to the model you want to join to, and a
> > > > > foreign key to the filmmaker, and would have a field for order. This
> > > > > would be editable in the admin under the same page.
>
> > > > > Read about inline 
> > > > > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>
> > > > > On Aug 13, 12:52 pm, Wendy  wrote:
>
> > > > > > I have a many to many field, with the horizontal available and 
> > > > > > chosen
> > > > > > boxes in the admin.  I wanted to see if there's any way that an 
> > > > > > admin
> > > > > > can select the order that the chosen objects show up, and have it be
> > > > > > saved and display that way.  Right now, they're not ordered, but 
> > > > > > seem
> > > > > > to show up based on when the object was created.  So I'm choosing
> > > > > > filmmakers for a film, and the only way I can change the order is to
> > > > > > destroy the filmmaker objects, then recreate and add them in a
> > > > > > different order, something that obviously wouldn't work in the real
> > > > > > world.  Is there any way to save the order in the chosen box in the
> > > > > > admin?
>
> > > > > > Thanks,
> > > > > > Wendy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Overriding ModelForm field's value in the admin changeview

2010-08-16 Thread vjimw
The form and object are combined when you call:

response = super([YOURMODELFORMHERE], self).change_view(request,
object_id, extra_context=my_context)

You can see what the admin code for def change_view does in Django1.*/
django/contrib/admin/options.py

I was looking at the same thing and found an alternate route to for my
needs since I didn't need the value to be updated before the form was
rendered.

On Jul 14, 1:03 pm, Chuck Harmston  wrote:
> Does anyone know where in the admin changeview the fields in a ModelForm is
> populated with the information from the database? I was hoping to override
> one of the fields in a subclassed ModelForm.__init__(), e.g.:
>
> self.base_fields[field_name].initial = 'foo'
>
> But the population appears to be happening farther down the chain, as 'foo'
> is overwritten with the value from the database.
>
> 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-us...@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: MySQL Newbie question

2010-08-16 Thread David
mysql_config is usually part of the MySQL client library (not to be
confused with the Python/MySQL library). You can get the full mysql
package from  http://dev.mysql.com/downloads/mysql

On Aug 16, 12:21 pm, Bradley Hintze 
wrote:
> Hi all,
>
> I'm trying to install MySQL for Python on Snow Leopard and I get :
>
> sh: mysql_config: command not found
> Traceback (most recent call last):
>   File "setup.py", line 15, in 
>     metadata, options = get_config()
>   File "/Users/bradleyhintze/Desktop/MySQL-python-1.2.3/setup_posix.py",
> line 43, in get_config
>     libs = mysql_config("libs_r")
>   File "/Users/bradleyhintze/Desktop/MySQL-python-1.2.3/setup_posix.py",
> line 24, in mysql_config
>     raise EnvironmentError("%s not found" % (mysql_config.path,))
> EnvironmentError: mysql_config not found
>
> There is a lot of supposed help online for this but after a few hors
> of googling I have yet to find mysql_config on my machine. Is there
> another package that I must install first?
>
> --
> Bradley J. Hintze
> Graduate Student
> Duke University
> School of Medicine
> 801-712-8799

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Foreignkeys and variables in a view

2010-08-16 Thread Nick
I have a view that handles elections/races. That view takes a request
object and then based on that object sends the information to a
specific template.

For each election/race there is a subset of candidates based on the
initial candidate_set from that race. I would like to know how to
filter that set in a view. Here is what I have so far:

Models.py:

Candidate
name = charfield
id = integer
race = ForeignKey(Race)

Race
name = charfield
type = integerfield

Views.py

def races_output(request, type): # the type is a number that equates
to general (3), runoff (2) or primary (1)
if type == 2:
 r = "runoff"
 t = loader.get_template("Government/race_output_2.html")
 state_races = Race.objects.select_related().filter(type=type)
 for race in state_races:
candidates = race.candidate_set.filter(status="runoff")

if type == 3:
 r = "general"
 t = loader.get_template("Government/race_output_3.html")
 state_races = Race.objects.select_related().filter(type=type)
 for race in state_races:
candidates = race.candidate_set.filter(status="general")

c = Context({'state_races': state_races, 'candidates': candidates,
'r':r})
html = t.render(c)

template

{% for race in state_races %}

{{race.name}} - {{race.type}}

{% for cand in candidates %}
{{ cand.name }} - {{cand.id }}
{% endfor %}

{% endif %}

The problem is the candidate for loop returns the exact same
candidates for every single race. How do I get it so that the
candidates query is specific to the race in the for loop?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



debug=True changes behavior of admin "fields"

2010-08-16 Thread Jerry Stratton
I have this in my admin.py:


class TutorialAdmin(admin.ModelAdmin):
fields = (
('title', 'category'),
'description',
'tags'
)
admin.site.register(Tutorial, TutorialAdmin)

It works fine when DEBUG = False in settings.py, but it fails when
DEBUG = True.

ImproperlyConfigured at /admin/tutorials/tutorial/
'TutorialAdmin.fields' refers to field '('title', 'category')' that is
missing from the form.

I've switched to using the more complicated fieldsets for now; but it
seems odd that this syntax for 'fields' fails only when DEBUG is on.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Wendy
Sure, it's pretty big, here are the relevant fields pulled out:
class Filmmaker (models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)


class Film(models.Model):
title = models.CharField(max_length=180)
slug = models.SlugField(unique=True)
#filmmakers = models.ManyToManyField(Filmmaker)
topics = models.ManyToManyField(Topic, blank=True)

def __unicode__(self):
return self.title

class FilmmakerPosition(models.Model):
 filmmaker = models.ForeignKey(Filmmaker)
 film = models.ForeignKey(Film)
 position = models.IntegerField()

--

In admin.py:

class FilmmakerPositionInline(admin.TabularInline):
model = FilmmakerPosition


class FilmAdmin(admin.ModelAdmin):
inlines = [
FilmmakerPositionInline,
]
... (there's more)

---

Anyway, this was what I was using in my template when filmmakers was a
many to many relationship with film (commented out in the model
stuff):
by {% with film.filmmakers.all as filmmakers %}
{% for filmmaker in filmmakers %}
   {% if filmmakers|length > 2 and not forloop.first 
%}, {% endif
%}
   {% if forloop.last and not forloop.first %}and {% 
endif %}
  {{filmmaker.first_name }} {{filmmaker.last_name}}
{% endfor %}
  {% endwith %}

Thanks,
Wendy




On Aug 16, 2:13 pm, Nick Serra  wrote:
> Can you list your models.py for me? What exactly do you want to show
> in your template? I'm guessing some sort of WHERE clause, like all
> filmmakers for a film or something.
>
> On Aug 16, 5:08 pm, Wendy  wrote:
>
> > OK, I have the inline solution working in the admin, I can see why
> > it's prettier!
> > Now I'm trying to figure out how to refer to these filmmakers in my
> > film list template, as there is no longer a film.filmmakers object...
> > So when I look in mysql, films_filmmakerposition has an id, a
> > filmmaker id, a film id and a position.
> > My Filmmaker Object has a first name and last name.
> > I'm not sure where to start on this one, any help would be greatly
> > appreciated.
> > Thanks,
> > Wendy
>
> > On Aug 16, 12:45 pm, Wendy  wrote:
>
> > > Thanks, Nick, I just figured that out, doh!  So I got the first
> > > example going, I guess I'll try the inline solution as well, if it's
> > > the pretty way to do it...  It'll be good for me to actually see what
> > > they both do.
> > > W
>
> > > On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > > > The inline solution is the pretty way to do it. If you just want the
> > > > join to show up in the admin, then simply register the join model in
> > > > the admin like any other model. In your admin,py include
> > > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> > > > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > > > Thanks Nick,
> > > > > I tried the first solution first.
> > > > > You're right, the many to manys aren't editable on that page, but the
> > > > > problem is, I'm not seeing another admin page for the new join model:
>
> > > > > class FilmmakerPosition(models.Model):
> > > > >          filmmaker = models.ForeignKey(Filmmaker)
> > > > >          film = models.ForeignKey(Film)
> > > > >          position = models.IntegerField()
> > > > > 
> > > > > (it is in the db)
> > > > > so there's no way I can assign filmmakers to a film in the admin.
> > > > > In the Film class it specifies:
> > > > > 
> > > > > filmmakers = models.ManyToManyField(Filmmaker,
> > > > > through='FilmmakerPosition')
> > > > > 
>
> > > > > Am I missing something?
>
> > > > > I was slightly more intimidated by the inline example, as I'm not sure
> > > > > I want to scrap the many to many relationship.  (there are lots of
> > > > > films that have multiple filmmakers and vice versa, and I'd like to be
> > > > > able to list them on both ends)  I'm still trying to wrap my head
> > > > > around how I could do that with this example.
>
> > > > > If anyone has anything else to add that would help me understand it
> > > > > better, I'd really appreciate it.
>
> > > > > Thanks,
> > > > > Wendy
>
> > > > > On Aug 13, 10:03 am, Nick Serra  wrote:
>
> > > > > > You can go two directions with this. First, you could use a
> > > > > > intermediate model for the many to many join, which would allow you 
> > > > > > to
> > > > > > specify extra field on the join, in this case the order. Read up on
> > > > > > this 
> > > > > > here:http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > > > > The problem with solution one is that the many to many won't be
> > > > > 

which python does django takes (two python exists)

2010-08-16 Thread John Yeukhon Wong
I am running Debian Lenny, and I have 2.5.25 and 2.7 co-exists
Which one would I get for django?

Notice the last response from this link
http://stackoverflow.com/questions/142764/how-do-i-upgrade-python-2-5-2-to-python-2-6rc2-on-ubuntu-linux-8-04

This is the method that I used...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: debug=True changes behavior of admin "fields"

2010-08-16 Thread Karen Tracey
On Mon, Aug 16, 2010 at 5:48 PM, Jerry Stratton  wrote:

> I have this in my admin.py:
>
>
> class TutorialAdmin(admin.ModelAdmin):
>fields = (
>('title', 'category'),
>'description',
>'tags'
>)
> admin.site.register(Tutorial, TutorialAdmin)
>
> It works fine when DEBUG = False in settings.py, but it fails when
> DEBUG = True.
>
> ImproperlyConfigured at /admin/tutorials/tutorial/
> 'TutorialAdmin.fields' refers to field '('title', 'category')' that is
> missing from the form.
>
> I've switched to using the more complicated fieldsets for now; but it
> seems odd that this syntax for 'fields' fails only when DEBUG is on.
>

Admin definitions are only explicitly validated when DEBUG is on. That is,
when DEBUG is on, there is some extensive checking of the admin definitions
to make sure that they all make sense and are valid. This is only done when
DEBUG is on because it is fairly expensive and thus not something you
necessarily want to do during production server start-up, when you likely
have not changed your admin definitions anyway so validating them is likely
wasted effort.

So yes, the ImproperlyConfigured error is something you will only get with
DEBUG on. But I would expect that the effect of the problem it identified
would be seen at some point when you try using the admin with DEBUG off.
That is, I'd expect you to hit some (possibly pretty cryptic) error at some
point, or find that not all the fields you are expecting are actually
listed, or something like that.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Nick Serra
In your view do:

filmmakeritems =
FilmmakerPosition.objects.filter(film=the_film).order_by('position')

Pass that into your template. Then in your template do:

{% for item in filmmakeritems %}
Name: {{ item.filmmaker.first_name }}
{% endfor %}


Etc...


On Aug 16, 6:12 pm, Wendy  wrote:
> Sure, it's pretty big, here are the relevant fields pulled out:
> class Filmmaker (models.Model):
>         first_name = models.CharField(max_length=30)
>         last_name = models.CharField(max_length=40)
>
>         def __unicode__(self):
>                 return u'%s %s' % (self.first_name, self.last_name)
>
> class Film(models.Model):
>         title = models.CharField(max_length=180)
>         slug = models.SlugField(unique=True)
>         #filmmakers = models.ManyToManyField(Filmmaker)
>         topics = models.ManyToManyField(Topic, blank=True)
>
>         def __unicode__(self):
>                 return self.title
>
> class FilmmakerPosition(models.Model):
>          filmmaker = models.ForeignKey(Filmmaker)
>          film = models.ForeignKey(Film)
>          position = models.IntegerField()
>
> --
>
> In admin.py:
>
> class FilmmakerPositionInline(admin.TabularInline):
>         model = FilmmakerPosition
>
> class FilmAdmin(admin.ModelAdmin):
>         inlines = [
>                 FilmmakerPositionInline,
>         ]
> ... (there's more)
>
> ---
>
> Anyway, this was what I was using in my template when filmmakers was a
> many to many relationship with film (commented out in the model
> stuff):
> by {% with film.filmmakers.all as filmmakers %}
>                         {% for filmmaker in filmmakers %}
>                            {% if filmmakers|length > 2 and not forloop.first 
> %}, {% endif
> %}
>                            {% if forloop.last and not forloop.first %}and {% 
> endif %}
>                               {{filmmaker.first_name }} 
> {{filmmaker.last_name}}
>                         {% endfor %}
>                   {% endwith %}
>
> Thanks,
> Wendy
>
> On Aug 16, 2:13 pm, Nick Serra  wrote:
>
> > Can you list your models.py for me? What exactly do you want to show
> > in your template? I'm guessing some sort of WHERE clause, like all
> > filmmakers for a film or something.
>
> > On Aug 16, 5:08 pm, Wendy  wrote:
>
> > > OK, I have the inline solution working in the admin, I can see why
> > > it's prettier!
> > > Now I'm trying to figure out how to refer to these filmmakers in my
> > > film list template, as there is no longer a film.filmmakers object...
> > > So when I look in mysql, films_filmmakerposition has an id, a
> > > filmmaker id, a film id and a position.
> > > My Filmmaker Object has a first name and last name.
> > > I'm not sure where to start on this one, any help would be greatly
> > > appreciated.
> > > Thanks,
> > > Wendy
>
> > > On Aug 16, 12:45 pm, Wendy  wrote:
>
> > > > Thanks, Nick, I just figured that out, doh!  So I got the first
> > > > example going, I guess I'll try the inline solution as well, if it's
> > > > the pretty way to do it...  It'll be good for me to actually see what
> > > > they both do.
> > > > W
>
> > > > On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > > > > The inline solution is the pretty way to do it. If you just want the
> > > > > join to show up in the admin, then simply register the join model in
> > > > > the admin like any other model. In your admin,py include
> > > > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> > > > > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > > > > Thanks Nick,
> > > > > > I tried the first solution first.
> > > > > > You're right, the many to manys aren't editable on that page, but 
> > > > > > the
> > > > > > problem is, I'm not seeing another admin page for the new join 
> > > > > > model:
>
> > > > > > class FilmmakerPosition(models.Model):
> > > > > >          filmmaker = models.ForeignKey(Filmmaker)
> > > > > >          film = models.ForeignKey(Film)
> > > > > >          position = models.IntegerField()
> > > > > > 
> > > > > > (it is in the db)
> > > > > > so there's no way I can assign filmmakers to a film in the admin.
> > > > > > In the Film class it specifies:
> > > > > > 
> > > > > > filmmakers = models.ManyToManyField(Filmmaker,
> > > > > > through='FilmmakerPosition')
> > > > > > 
>
> > > > > > Am I missing something?
>
> > > > > > I was slightly more intimidated by the inline example, as I'm not 
> > > > > > sure
> > > > > > I want to scrap the many to many relationship.  (there are lots of
> > > > > > films that have multiple filmmakers and vice versa, and I'd like to 
> > > > > > be
> > > > > > able to list them on both ends)  I'm still trying to wrap my head
> > > > > > around how I could do that with this example.
>
> > > > > > If anyone has anything else to add that would help me understand it
> > > > > > better, I'd really apprec

Re: Ordering in the admin

2010-08-16 Thread Wendy
It doesn't know what the_film is:
name 'the_film' is not defined

if I put quotes around 'the_film', it's expecting an integer:
invalid literal for int() with base 10: 'the_film'

 I think that what's happening, it's trying to match the id.

I'm going to read about filtering a little more, feels like it's
close...
(I also tried to put film_id in the parens after filter and got a "too
many values" error.)
So much to learn, thanks for all your help,
Wendy

On Aug 16, 4:00 pm, Nick Serra  wrote:
> In your view do:
>
> filmmakeritems =
> FilmmakerPosition.objects.filter(film=the_film).order_by('position')
>
> Pass that into your template. Then in your template do:
>
> {% for item in filmmakeritems %}
> Name: {{ item.filmmaker.first_name }}
> {% endfor %}
>
> Etc...
>
> On Aug 16, 6:12 pm, Wendy  wrote:
>
> > Sure, it's pretty big, here are the relevant fields pulled out:
> > class Filmmaker (models.Model):
> >         first_name = models.CharField(max_length=30)
> >         last_name = models.CharField(max_length=40)
>
> >         def __unicode__(self):
> >                 return u'%s %s' % (self.first_name, self.last_name)
>
> > class Film(models.Model):
> >         title = models.CharField(max_length=180)
> >         slug = models.SlugField(unique=True)
> >         #filmmakers = models.ManyToManyField(Filmmaker)
> >         topics = models.ManyToManyField(Topic, blank=True)
>
> >         def __unicode__(self):
> >                 return self.title
>
> > class FilmmakerPosition(models.Model):
> >          filmmaker = models.ForeignKey(Filmmaker)
> >          film = models.ForeignKey(Film)
> >          position = models.IntegerField()
>
> > --
>
> > In admin.py:
>
> > class FilmmakerPositionInline(admin.TabularInline):
> >         model = FilmmakerPosition
>
> > class FilmAdmin(admin.ModelAdmin):
> >         inlines = [
> >                 FilmmakerPositionInline,
> >         ]
> > ... (there's more)
>
> > ---
>
> > Anyway, this was what I was using in my template when filmmakers was a
> > many to many relationship with film (commented out in the model
> > stuff):
> > by {% with film.filmmakers.all as filmmakers %}
> >                         {% for filmmaker in filmmakers %}
> >                            {% if filmmakers|length > 2 and not 
> > forloop.first %}, {% endif
> > %}
> >                            {% if forloop.last and not forloop.first %}and 
> > {% endif %}
> >                               {{filmmaker.first_name }} 
> > {{filmmaker.last_name}}
> >                         {% endfor %}
> >                   {% endwith %}
>
> > Thanks,
> > Wendy
>
> > On Aug 16, 2:13 pm, Nick Serra  wrote:
>
> > > Can you list your models.py for me? What exactly do you want to show
> > > in your template? I'm guessing some sort of WHERE clause, like all
> > > filmmakers for a film or something.
>
> > > On Aug 16, 5:08 pm, Wendy  wrote:
>
> > > > OK, I have the inline solution working in the admin, I can see why
> > > > it's prettier!
> > > > Now I'm trying to figure out how to refer to these filmmakers in my
> > > > film list template, as there is no longer a film.filmmakers object...
> > > > So when I look in mysql, films_filmmakerposition has an id, a
> > > > filmmaker id, a film id and a position.
> > > > My Filmmaker Object has a first name and last name.
> > > > I'm not sure where to start on this one, any help would be greatly
> > > > appreciated.
> > > > Thanks,
> > > > Wendy
>
> > > > On Aug 16, 12:45 pm, Wendy  wrote:
>
> > > > > Thanks, Nick, I just figured that out, doh!  So I got the first
> > > > > example going, I guess I'll try the inline solution as well, if it's
> > > > > the pretty way to do it...  It'll be good for me to actually see what
> > > > > they both do.
> > > > > W
>
> > > > > On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > > > > > The inline solution is the pretty way to do it. If you just want the
> > > > > > join to show up in the admin, then simply register the join model in
> > > > > > the admin like any other model. In your admin,py include
> > > > > > FilmmakerPosition and then do admin.site.register(FilmmakerPosition)
>
> > > > > > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > > > > > Thanks Nick,
> > > > > > > I tried the first solution first.
> > > > > > > You're right, the many to manys aren't editable on that page, but 
> > > > > > > the
> > > > > > > problem is, I'm not seeing another admin page for the new join 
> > > > > > > model:
>
> > > > > > > class FilmmakerPosition(models.Model):
> > > > > > >          filmmaker = models.ForeignKey(Filmmaker)
> > > > > > >          film = models.ForeignKey(Film)
> > > > > > >          position = models.IntegerField()
> > > > > > > 
> > > > > > > (it is in the db)
> > > > > > > so there's no way I can assign filmmakers to a film in the admin.
> > > > > > > In the Film class it specifies:
> > > > > > > 
> > > 

formpreview with multivaluefield preview output

2010-08-16 Thread Architekt
Hey everyone, have a multivaluefield to gather a US phone number with
an optional extension.  It looks great on the form, however during the
form preview it looks pretty ugly.  In the database the number gets
stored as 555 555  x however in the form preview it looks like
this:   [u'555', u'555', u'', u''].  How can I pretty the
output in the preview form?  Any help would be appreciated.

In my model in models.py I define these two fields:
telephone_number = models.CharField(blank=True, max_length=34,
help_text="The person's telephone number.")
confirm_telephone_number = models.CharField(blank=True,
max_length=34)

I define the following widget and field:
class PhoneNumberWidget(forms.MultiWidget):
def __init__(self,attrs=None):
wigs = (forms.TextInput(attrs={'size':'3','maxlength':'3'}),\
forms.TextInput(attrs={'size':'3','maxlength':'3'}),\
forms.TextInput(attrs={'size':'4','maxlength':'4'}),\
forms.TextInput(attrs={'size':'4','maxlength':'4'}))
super(PhoneNumberWidget, self).__init__(wigs, attrs)

def decompress(self, value):
if value:
return value
return [None, None, None, None]

def format_output(self, rendered_widgets):
return
'('+rendered_widgets[0]+')'+rendered_widgets[1]+'-'+rendered_widgets[2]+'ext'+rendered_widgets[3]

class PhoneNumberField(forms.MultiValueField):
widget = PhoneNumberWidget
def __init__(self, *args, **kwargs):
fields=(forms.CharField(max_length=3),
forms.CharField(max_length=3), forms.CharField(max_length=4),
forms.CharField(max_length=4))
super(PhoneNumberField, self).__init__(fields, *args,
**kwargs)
def compress(self, data_list):
if data_list[0] in forms.fields.EMPTY_VALUES or data_list[1]
in forms.fields.EMPTY_VALUES or data_list[2] in
forms.fields.EMPTY_VALUES:
raise forms.fields.ValidationError(u'Enter valid phone
number')
if data_list[3] in forms.fields.EMPTY_VALUES:
return data_list[0]+' '+data_list[1]+' '+data_list[2]
else:
return data_list[0]+' '+data_list[1]+' '+data_list[2]+'
x'+data_list[3]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



select statements with specific fields across multiple tables...

2010-08-16 Thread Cindy
I'm having some trouble constructing a filter that's intended to work
across multiple tables with selected fields.  Here's a simplified
outline of my models:

class System(models.Model):
name = models.CharField(max_length=16)
domain = models.CharField(max_length=255, default='example.com')

class RaidStorage(models.Model):
in_system = models.ForeignKey(System)
name = models.CharField(max_length=25)

class RaidArray(models.Model):
in_storage = models.ForeignKey(RaidStorage)
name = models.CharField(max_length=25)

class RaidPhysicalDrive(models.Model):
in_array = models.ForeignKey(RaidArray)
name = models.CharField(max_length=25)
size = models.IntegerField(null=True, blank=True)
serial = models.CharField(max_length=25)
model = models.CharField(max_length=25)

Now, given a system id, I want to list all the physical drives from it
along with info from the related tables.  I would like something like

select System.name, RaidStorage.name, RaidArray.name,
RaidPhysicalDrive.name, RaidPhysicalDrive.serial,
RaidPhysicalDrive.model from System, RaidStorage, RaidArray,
RaidPhysicalDrive where RaidPhysicalDrive.in_array=RaidAarray.id and
RaidArray.in_storaage = RaidStorage.id and RaidStorage.in_system=id
(etc)

I'm having a good deal of trouble coming up with the filters for
this.  I'm thinking that .values() and possibly .select_related() are
key here, but so far I've failed at putting together anything that
gives me the results I want (a list of physical drives associated with
the selected system).   The filter examples through the tutorials and
such seem to all assume select *, and there's very little on dealing
with grouping selective fields from multiple tables that I've found.

Part of the issue might be in the template as well; If I cheat and
send it the correct list, I can't access part of the information I
want:

{% for pd in pd_list %}

{{ pd.in_array_id.storage.in_system.name }}
{{ pd.in_array_id.in_storage.name }}
{{ pd.in_array_id.name }}
{{ pd.name }}
{{ pd.serial }}
{{ pd.model }}

{% endfor %}

results in the first three columns of the table being empty...
templates don't seem to "follow" back the way they do in views.py,
etc.  So I'm sure I need to create a dictionary or list from the
original views.py def to pass to the template but as I say, I'm not
sure of how to use .values or .select_related (or whatever else item
I'm overlooking).

I did search through the group a bit, but didn't find anything
directly helpful.

Thanks!
--Cindy



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Foreignkeys and variables in a view

2010-08-16 Thread Steve Holden
On 8/16/2010 5:40 PM, Nick wrote:
> I have a view that handles elections/races. That view takes a request
> object and then based on that object sends the information to a
> specific template.
> 
> For each election/race there is a subset of candidates based on the
> initial candidate_set from that race. I would like to know how to
> filter that set in a view. Here is what I have so far:
> 
> Models.py:
> 
> Candidate
> name = charfield
> id = integer
> race = ForeignKey(Race)
> 
> Race
> name = charfield
> type = integerfield
> 
> Views.py
> 
> def races_output(request, type): # the type is a number that equates
> to general (3), runoff (2) or primary (1)
> if type == 2:
>  r = "runoff"
>  t = loader.get_template("Government/race_output_2.html")
>  state_races = Race.objects.select_related().filter(type=type)
>  for race in state_races:
> candidates = race.candidate_set.filter(status="runoff")
> 
> if type == 3:
>  r = "general"
>  t = loader.get_template("Government/race_output_3.html")
>  state_races = Race.objects.select_related().filter(type=type)
>  for race in state_races:
> candidates = race.candidate_set.filter(status="general")
> 
> c = Context({'state_races': state_races, 'candidates': candidates,
> 'r':r})
> html = t.render(c)
> 
> template
> 
> {% for race in state_races %}
> 
> {{race.name}} - {{race.type}}
> 
> {% for cand in candidates %}
> {{ cand.name }} - {{cand.id }}
> {% endfor %}
> 
> {% endif %}
> 
> The problem is the candidate for loop returns the exact same
> candidates for every single race. How do I get it so that the
> candidates query is specific to the race in the for loop?
> 
First of all, note that you are setting candidates in a for loop. So
what you see is only the result of the last iteration of that loop - the
results of all previous iterations are being overwritten by the last one.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Best OS - VPS environment

2010-08-16 Thread Eric Chamberlain
Dan,

We also run CentOS 5 on our production servers and have various django projects 
running Python 2.6.2 & 2.7.

I'd stick with an OS that you know and use virtualenv to isolate the python 
version to the django project.



On Aug 16, 2010, at 1:54 AM, Dan wrote:

> I have been using CentOS 5 to run Django sites with Apache + Mod WSGI
> mostly in VPS environments.
> 
> I want to upgrade to a new OS as CentOS runs an old version of python
> and it seems that it's not so easy to upgrade it.
> 
> What do people recommend?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Create files and directories from Django 1.2.1

2010-08-16 Thread Mike Dewhirst

On 16/08/2010 10:22pm, Doug Blank wrote:

On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:

Allright I tried a couple of things with your suggested appraoch:







I doubt it. You shouldn't really do this:

kmlpath = "%s/%s" % (basepath, game_id)


I suggested this to avoid having to cast game_id as a string. I'm not 
all that knowledgeable about the upcoming Python 3 tsunami but I figure 
there will be less hassle if I use the inbuilt string formatting in %s. 
At least I hope so!




but do this:

kmlpath = os.path.join(basepath, game_id)


Now I have a question - more Python than Django. os.path.join is very 
clever but in Windows we have multiple approaches. One is to simply use 
forward slashes and rely on the infrastructure to know what to do and 
the other is to be agnostically cross-platform with os.path.sep and 
os.path.join. We can also use r'raw\backslashes' and 
u'C:\\escaped\\backslashes'


I have come unstuck using all of them at one time or another. I can't 
quite put my finger on it at the moment but I have also seen things like 
'C:\path\to/some/file.txt' arising from combinations of the approaches 
and surprisingly being successful.


So my question is, has anyone written a dissertation on the best 
approaches for particular circumstances?


Mike



as different OS's have different path formats. Or perhaps it is the
kml string that you are creating that has other issues (unicode?) I
would print out the mkdirs string to see what you are creating.

HTH,

-Doug


Mark

On 16 aug, 08:32, Mike Dewhirst  wrote:

On 16/08/2010 12:57pm, Mike Dewhirst wrote:






On 16/08/2010 1:06am, Mark Mooij wrote:

Hi Mike,



Thanks for your reply. I haven't changed anything else, I am
processing the MS updates, but I don't think this is the problem, as
this all worked fine before the migration to 1.2.1, also if I call the
script directly (outside Django) it works fine.
My view looks like this:
..
import createKML
..
def my_view(request, arg):
...
createKML.createKML(arg)



I don't really know what is happening here that might have changed in
1.2.1 maybe someone else can suggest something.



In the meantime here is suggested approach to discovering the exact
problem ...



import os
...
def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
...
try:
if id:
kmlpath = "%s/%s" % (basepath, str(id))


actually .. kmlpath = "%s/%s" % (basepath, id)


if not os.path.isdir(kmlpath):
os.makedirs(kmlpath)
writefile = "%s/%s" % (kmlpath, str(id))


actually .. writefile = "%s/%s" % (kmlpath, id)




f = open(writefile, 'wb')
else:
raise
except Exception as e:
print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
...



mike



...



In the createKML.py the problem arises in:
...
import os
...
def createKML(id):
...
os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
+ ".kml"
f = open(writefile, 'wb')
...



I hope this helps?



On 14 aug, 21:55, Mike Dewhirst  wrote:

On 15/08/2010 12:10am, Mark Mooij wrote:



Hi all,



I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
application which imports an external python script in which a
directory and some files are created. Since the migrate this doesn't
work anymore, I get a number of IOErrors because the files (and
directory) that should be created can't be found. I've tried changing
my directories and slashes (I'm using Windows), but no success.



Have you changed anything else?



For example, are you processing the Microsoft Windows update patches
which (for WinXP) insert extra permission steps? Have you changed your
OS from XP to Win7?



Can you post the source of the script?



Can't I use the os python functions anymore in Django 1.2.1? In the
documentation I've read about Managing files in models but I prefer to
handle this through my external script.



I hope anybody can help me.



Thanks,
Mark


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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-us...@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.



mod_wsgi and first django app

2010-08-16 Thread John Yeukhon Wong
I have the book "The definitive Guide to DJango: Web Development Done
Right".
Both editions use mod_python, and not mod_wsgi.

I have the setup correctly.

The first program was display the current datetime

views.py

from django.http import HttpResponse
import datetime

def current_datetime(request):
now = datetime.datetime.now()
html = "It is now %s." % now
return HttpResponse(html)


The urls.py

from django.conf.urls.defaults import *
from mysite.views import current_datetime

urlpatterns = patterns('',

(r'^time/$', current_datetime),
)



I am getting nothing but again, the blue page with http://domain/time/

As a beginner, I can't find a book that use mod_wsgi

So how do I set up this, and for the future (as there are multiple
pages in the future...)

Thank 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-us...@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: select statements with specific fields across multiple tables...

2010-08-16 Thread Alec Shaner
1. What is your code for doing the filters?  If you want to start with
physical drives it would be something like:

RaidPhysicalDrive.objects.filter(in_array__in_storage__in_system__id=)

2. In your template you've referenced pd.in_array_id, but don't you just
want pd.in_array if you're wanting to follow the FK to get RaidArray fields,
e.g.,

{{ 
pd.in_array.in_storage.in_system.name}}


On Mon, Aug 16, 2010 at 8:04 PM, Cindy  wrote:

> I'm having some trouble constructing a filter that's intended to work
> across multiple tables with selected fields.  Here's a simplified
> outline of my models:
>
> class System(models.Model):
>name = models.CharField(max_length=16)
>domain = models.CharField(max_length=255, default='example.com')
>
> class RaidStorage(models.Model):
>in_system = models.ForeignKey(System)
>name = models.CharField(max_length=25)
>
> class RaidArray(models.Model):
>in_storage = models.ForeignKey(RaidStorage)
>name = models.CharField(max_length=25)
>
> class RaidPhysicalDrive(models.Model):
>in_array = models.ForeignKey(RaidArray)
>name = models.CharField(max_length=25)
>size = models.IntegerField(null=True, blank=True)
>serial = models.CharField(max_length=25)
>model = models.CharField(max_length=25)
>
> Now, given a system id, I want to list all the physical drives from it
> along with info from the related tables.  I would like something like
>
> select System.name, RaidStorage.name, RaidArray.name,
> RaidPhysicalDrive.name, RaidPhysicalDrive.serial,
> RaidPhysicalDrive.model from System, RaidStorage, RaidArray,
> RaidPhysicalDrive where RaidPhysicalDrive.in_array=RaidAarray.id and
> RaidArray.in_storaage = RaidStorage.id and RaidStorage.in_system=id
> (etc)
>
> I'm having a good deal of trouble coming up with the filters for
> this.  I'm thinking that .values() and possibly .select_related() are
> key here, but so far I've failed at putting together anything that
> gives me the results I want (a list of physical drives associated with
> the selected system).   The filter examples through the tutorials and
> such seem to all assume select *, and there's very little on dealing
> with grouping selective fields from multiple tables that I've found.
>
> Part of the issue might be in the template as well; If I cheat and
> send it the correct list, I can't access part of the information I
> want:
>
> {% for pd in pd_list %}
> 
>{{ pd.in_array_id.storage.in_system.name }}
>{{ pd.in_array_id.in_storage.name }}
>{{ pd.in_array_id.name }}
>{{ pd.name }}
>{{ pd.serial }}
>{{ pd.model }}
> 
> {% endfor %}
>
> results in the first three columns of the table being empty...
> templates don't seem to "follow" back the way they do in views.py,
> etc.  So I'm sure I need to create a dictionary or list from the
> original views.py def to pass to the template but as I say, I'm not
> sure of how to use .values or .select_related (or whatever else item
> I'm overlooking).
>
> I did search through the group a bit, but didn't find anything
> directly helpful.
>
> Thanks!
> --Cindy
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: mod_wsgi and first django app

2010-08-16 Thread John Yeukhon Wong
I added the wsgi scripts and incluced that in my views.py
It works...

I know that for every project there is only one views can exist... so
is that the really way???

I want to have some guides here, thank you, and I am sorry for being
stupid if I sound like one

On Aug 16, 9:39 pm, John Yeukhon Wong  wrote:
> I have the book "The definitive Guide to DJango: Web Development Done
> Right".
> Both editions use mod_python, and not mod_wsgi.
>
> I have the setup correctly.
>
> The first program was display the current datetime
>
> views.py
>
> from django.http import HttpResponse
> import datetime
>
> def current_datetime(request):
>         now = datetime.datetime.now()
>         html = "It is now %s." % now
>         return HttpResponse(html)
>
> The urls.py
>
> from django.conf.urls.defaults import *
> from mysite.views import current_datetime
>
> urlpatterns = patterns('',
>
>         (r'^time/$', current_datetime),
> )
>
> I am getting nothing but again, the blue page withhttp://domain/time/
>
> As a beginner, I can't find a book that use mod_wsgi
>
> So how do I set up this, and for the future (as there are multiple
> pages in the future...)
>
> Thank 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-us...@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: which python does django takes (two python exists)

2010-08-16 Thread Rolando Espinoza La Fuente
On Mon, Aug 16, 2010 at 6:38 PM, John Yeukhon Wong
 wrote:
> I am running Debian Lenny, and I have 2.5.25 and 2.7 co-exists
> Which one would I get for django?
>
> Notice the last response from this link
> http://stackoverflow.com/questions/142764/how-do-i-upgrade-python-2-5-2-to-python-2-6rc2-on-ubuntu-linux-8-04
>
> This is the method that I used...

Depends how do you run it.

In the command line, if you use ./manage.py
it uses whatever is specified in the first line. e.g. #!/usr/local/bin/python2.5

If it says /usr/bin/env python it uses the same as you type "python"
in the shell.
See `which` and `whereis` command in *nix.
$ which python
/home/rho/projects/py26env1/bin/python

$ whereis python
python: /usr/bin/python2.5-config /usr/bin/python /usr/bin/python2.5
/etc/python /etc/python2.5 /usr/lib/python2.4 /usr/lib/python2.5
/usr/local/bin/python2.6 /usr/local/bin/python2.6-config
/usr/local/lib/python2.5 /usr/local/lib/python2.6
/usr/include/python2.4_d /usr/include/python2.5_d
/usr/include/python2.4 /usr/include/python2.5 /usr/share/python
/usr/share/python2.3-wxglade /usr/share/man/man1/python.1.gz

Most python scripts uses just "python", so it will run with whatever
points to python.
Django's manage.py uses #!/usr/bin/env python

For mod_wsgi, see this link:
http://code.google.com/p/modwsgi/wiki/InstallationIssues#Multiple%5FPython%5FVersions

Als installed python modules are not shared between multiple python versions.
So you need to be careful in which version do you install something. You should
have easy_install-2.5 easy-install-2.6 easy-install-2.7 and the .deb
also specifies
which version belongs.

Read about virtualenv, it makes easy to work with multiple
python/django versions.

Regards,

Rolando Espinoza La fuente
www.insophia.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-us...@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.



list_search searching of stacked_inline forms using admin ?

2010-08-16 Thread gondor
I have several stacked_linline forms and was wondering if anyone knows
how to have the filter_search include the stacked_inline attributes?
Right now I can search the model and all foreign/many to many
fields.   I would like to include the stacked_inline fields as well.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: mod_wsgi and first django app

2010-08-16 Thread Steve Holden
Congratulations! Don't worry about sounding "stupid". Most people will
make allowances for the fact that you are writing in a foreign language.

regards
 Steve

On 8/16/2010 9:56 PM, John Yeukhon Wong wrote:
> I added the wsgi scripts and incluced that in my views.py
> It works...
> 
> I know that for every project there is only one views can exist... so
> is that the really way???
> 
> I want to have some guides here, thank you, and I am sorry for being
> stupid if I sound like one
> 
> On Aug 16, 9:39 pm, John Yeukhon Wong  wrote:
>> I have the book "The definitive Guide to DJango: Web Development Done
>> Right".
>> Both editions use mod_python, and not mod_wsgi.
>>
>> I have the setup correctly.
>>
>> The first program was display the current datetime
>>
>> views.py
>>
>> from django.http import HttpResponse
>> import datetime
>>
>> def current_datetime(request):
>> now = datetime.datetime.now()
>> html = "It is now %s." % now
>> return HttpResponse(html)
>>
>> The urls.py
>>
>> from django.conf.urls.defaults import *
>> from mysite.views import current_datetime
>>
>> urlpatterns = patterns('',
>>
>> (r'^time/$', current_datetime),
>> )
>>
>> I am getting nothing but again, the blue page withhttp://domain/time/
>>
>> As a beginner, I can't find a book that use mod_wsgi
>>
>> So how do I set up this, and for the future (as there are multiple
>> pages in the future...)
>>
>> Thank you.
> 


-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Foreignkeys and variables in a view

2010-08-16 Thread Steve Holden
On 8/16/2010 9:30 PM, Nick wrote:
> 
> Thanks for the reply.
> 
> I assume the problem is coming from the views since the template 'for'
> loop is technically doing what it's supposed to.
> 
I find that hard to believe - you appear to be saying that you only want
the candidates for the *last* state_race. In which case why bother to
compute the candidates for the others?

As far as I can see your code

  for race in state_races:
 candidates = race.candidate_set.filter(status="runoff")

should give exactly the same result at

  candidates = state_races[-1].candidate_set.filter(status="runoff")

but of course I could be mistaken.

Ignoring that for the moment you might want to simplify a little bit -
it looks as though you were heading along this road but didn't quite go
all the way.

racetypes = {"2": "runoff",
 "3": "general"} # What happened to "1"?

def races_output(request, rtyp) # type() is a Python built-in!
r = racetypes(rtyp)
t = loader.get_template("Government/race_output_%s.html" % rtyp)
state_races = Race.objects.select_related().filter(type=rtyp)
# then whatever you decide needs to be done with the races

Hope this helps.

regards
 Steve

> How do I limit the candidate_set(s) for each race to the statuses
> mentioned above? I have a very duct taped solution in my template but
> it's very unwieldly and confusing (many many if's). Can I move this
> filtering to the view to clean up the template?
> 
That's almost certainly the right approach. Whenever your templates get
clogged up with logic it indicates you need to migrate the logic to
views. This makes your templates much more readable too!

> On Aug 16, 7:41 pm, Steve Holden  wrote:
>> On 8/16/2010 5:40 PM, Nick wrote:
>>
>>
>>
>>> I have a view that handles elections/races. That view takes a request
>>> object and then based on that object sends the information to a
>>> specific template.
>>
>>> For each election/race there is a subset of candidates based on the
>>> initial candidate_set from that race. I would like to know how to
>>> filter that set in a view. Here is what I have so far:
>>
>>> Models.py:
>>
>>> Candidate
>>> name = charfield
>>> id = integer
>>> race = ForeignKey(Race)
>>
>>> Race
>>> name = charfield
>>> type = integerfield
>>
>>> Views.py
>>
>>> def races_output(request, type): # the type is a number that equates
>>> to general (3), runoff (2) or primary (1)
>>> if type == 2:
>>>  r = "runoff"
>>>  t = loader.get_template("Government/race_output_2.html")
>>>  state_races = Race.objects.select_related().filter(type=type)
>>>  for race in state_races:
>>> candidates = race.candidate_set.filter(status="runoff")
>>
>>> if type == 3:
>>>  r = "general"
>>>  t = loader.get_template("Government/race_output_3.html")
>>>  state_races = Race.objects.select_related().filter(type=type)
>>>  for race in state_races:
>>> candidates = race.candidate_set.filter(status="general")
>>
>>> c = Context({'state_races': state_races, 'candidates': candidates,
>>> 'r':r})
>>> html = t.render(c)
>>
>>> template
>>
>>> {% for race in state_races %}
>>
>>> {{race.name}} - {{race.type}}
>>
>>> {% for cand in candidates %}
>>> {{ cand.name }} - {{cand.id }}
>>> {% endfor %}
>>
>>> {% endif %}
>>
>>> The problem is the candidate for loop returns the exact same
>>> candidates for every single race. How do I get it so that the
>>> candidates query is specific to the race in the for loop?
>>
>> First of all, note that you are setting candidates in a for loop. So
>> what you see is only the result of the last iteration of that loop - the
>> results of all previous iterations are being overwritten by the last one.
>>
>> regards
>>  Steve
>> --
>> DjangoCon US 2010 September 7-9http://djangocon.us/


-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Foreignkeys and variables in a view

2010-08-16 Thread Steve Holden
On 8/16/2010 10:30 PM, Nick Tankersley wrote:
> Thank you again for your replies. They've been full of usefull
> information about how to clean up an otherwise pretty sloppy bit of code.
> 
No problem. I hope you don't mind me keeping this dialog on the list (I
see you didn't copy django-users, perhaps not realizing that a "Reply
All" would be required to do so).

> By the way, type 1 races passed about a month ago so it doesn't come
> into play.
> 
Thanks! That cleared up a mystery.

> I can see how you misunderstand my goal. After I get the initial query
> for the races I want to filter each races candidate_set to include only
> those candidates with a specific status. That is where I am getting stuck.
> 
> What I meant by saying that the template for loop is working properly is
> that based on my flawed query logic it is returning exactly what is
> should, a list of candidates in the last entry.
> 
Ah! Penny drops! I wasn't really looking at the templates. So what you
are really asking is how can you make the template work for every race,
and not just the last one?

A solution I have used in the past is to add attributes to the top-level
objects that I can then use in the template. This would in your case
involve doing something like

for race in state_races:
race.cands = race.candidate_set.filter(status="runoff")

in the view. Then the template would look like this:

{% for race in state_races %}

{{race.name}} - {{race.type}}

{% for cand in race.cands %}
{{ cand.name }} - {{cand.id }}
{% endfor %}

{% endif %}

I am pretty sure this isn't the recommended way to proceed, but with
luck someone on the list will advise us as to what is ...

regards
 Steve

> On Aug 16, 2010 9:21 PM, "Steve Holden"  > wrote:
>> On 8/16/2010 9:30 PM, Nick wrote:
>>>
>>> Thanks for the reply.
>>>
>>> I assume the problem is coming from the views since the template 'for'
>>> loop is technically doing what it's supposed to.
>>>
>> I find that hard to believe - you appear to be saying that you only want
>> the candidates for the *last* state_race. In which case why bother to
>> compute the candidates for the others?
>>
>> As far as I can see your code
>>
>> for race in state_races:
>> candidates = race.candidate_set.filter(status="runoff")
>>
>> should give exactly the same result at
>>
>> candidates = state_races[-1].candidate_set.filter(status="runoff")
>>
>> but of course I could be mistaken.
>>
>> Ignoring that for the moment you might want to simplify a little bit -
>> it looks as though you were heading along this road but didn't quite go
>> all the way.
>>
>> racetypes = {"2": "runoff",
>> "3": "general"} # What happened to "1"?
>>
>> def races_output(request, rtyp) # type() is a Python built-in!
>> r = racetypes(rtyp)
>> t = loader.get_template("Government/race_output_%s.html" % rtyp)
>> state_races = Race.objects.select_related().filter(type=rtyp)
>> # then whatever you decide needs to be done with the races
>>
>> Hope this helps.
>>
>> regards
>> Steve
>>
>>> How do I limit the candidate_set(s) for each race to the statuses
>>> mentioned above? I have a very duct taped solution in my template but
>>> it's very unwieldly and confusing (many many if's). Can I move this
>>> filtering to the view to clean up the template?
>>>
>> That's almost certainly the right approach. Whenever your templates get
>> clogged up with logic it indicates you need to migrate the logic to
>> views. This makes your templates much more readable too!
>>
>>> On Aug 16, 7:41 pm, Steve Holden  > wrote:
 On 8/16/2010 5:40 PM, Nick wrote:



> I have a view that handles elections/races. That view takes a request
> object and then based on that object sends the information to a
> specific template.

> For each election/race there is a subset of candidates based on the
> initial candidate_set from that race. I would like to know how to
> filter that set in a view. Here is what I have so far:

> Models.py:

> Candidate
> name = charfield
> id = integer
> race = ForeignKey(Race)

> Race
> name = charfield
> type = integerfield

> Views.py

> def races_output(request, type): # the type is a number that equates
> to general (3), runoff (2) or primary (1)
> if type == 2:
> r = "runoff"
> t = loader.get_template("Government/race_output_2.html")
> state_races = Race.objects.select_related().filter(type=type)
> for race in state_races:
> candidates = race.candidate_set.filter(status="runoff")

> if type == 3:
> r = "general"
> t = loader.get_template("Government/race_output_3.html")
> state_races = Race.objects.select_related().filter(type=type)
> for race in state_races:
> candidates = race.candidate_set.filter(status="general")

> c = Context({'state_races': state_races, 'candidates': candidates,
> 'r':r})
> html = t

Re: debug=True changes behavior of admin "fields"

2010-08-16 Thread Jerry Stratton
On Aug 16, 3:43 pm, Karen Tracey  wrote:
> So yes, the ImproperlyConfigured error is something you will only get with
> DEBUG on. But I would expect that the effect of the problem it identified
> would be seen at some point when you try using the admin with DEBUG off.
> That is, I'd expect you to hit some (possibly pretty cryptic) error at some
> point, or find that not all the fields you are expecting are actually
> listed, or something like that.

In this case all four were displayed, in the order listed, and with
the top two (title and category) grouped on the same line. I was able
to add and edit several entries, until I started adding functionality
that required me to turn DEBUG on and got that error. (I had hoped to
use the simpler format so that it would be easier for our less Python-
savvy team members to understand.)

I didn't know that about admin definitions; that makes sense.

Jerry

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ordering in the admin

2010-08-16 Thread Nick Serra
The_film was just sudo code. I was assuming you wanted to show
filmmakers based on a movie id. I would recommend going through the
django tutorials if you haven't, they go over all of the queries and
how the general layout goes when doing stuff like this.

On Aug 16, 7:46 pm, Wendy  wrote:
> It doesn't know what the_film is:
> name 'the_film' is not defined
>
> if I put quotes around 'the_film', it's expecting an integer:
> invalid literal for int() with base 10: 'the_film'
>
>  I think that what's happening, it's trying to match the id.
>
> I'm going to read about filtering a little more, feels like it's
> close...
> (I also tried to put film_id in the parens after filter and got a "too
> many values" error.)
> So much to learn, thanks for all your help,
> Wendy
>
> On Aug 16, 4:00 pm, Nick Serra  wrote:
>
> > In your view do:
>
> > filmmakeritems =
> > FilmmakerPosition.objects.filter(film=the_film).order_by('position')
>
> > Pass that into your template. Then in your template do:
>
> > {% for item in filmmakeritems %}
> > Name: {{ item.filmmaker.first_name }}
> > {% endfor %}
>
> > Etc...
>
> > On Aug 16, 6:12 pm, Wendy  wrote:
>
> > > Sure, it's pretty big, here are the relevant fields pulled out:
> > > class Filmmaker (models.Model):
> > >         first_name = models.CharField(max_length=30)
> > >         last_name = models.CharField(max_length=40)
>
> > >         def __unicode__(self):
> > >                 return u'%s %s' % (self.first_name, self.last_name)
>
> > > class Film(models.Model):
> > >         title = models.CharField(max_length=180)
> > >         slug = models.SlugField(unique=True)
> > >         #filmmakers = models.ManyToManyField(Filmmaker)
> > >         topics = models.ManyToManyField(Topic, blank=True)
>
> > >         def __unicode__(self):
> > >                 return self.title
>
> > > class FilmmakerPosition(models.Model):
> > >          filmmaker = models.ForeignKey(Filmmaker)
> > >          film = models.ForeignKey(Film)
> > >          position = models.IntegerField()
>
> > > --
>
> > > In admin.py:
>
> > > class FilmmakerPositionInline(admin.TabularInline):
> > >         model = FilmmakerPosition
>
> > > class FilmAdmin(admin.ModelAdmin):
> > >         inlines = [
> > >                 FilmmakerPositionInline,
> > >         ]
> > > ... (there's more)
>
> > > ---
>
> > > Anyway, this was what I was using in my template when filmmakers was a
> > > many to many relationship with film (commented out in the model
> > > stuff):
> > > by {% with film.filmmakers.all as filmmakers %}
> > >                         {% for filmmaker in filmmakers %}
> > >                            {% if filmmakers|length > 2 and not 
> > > forloop.first %}, {% endif
> > > %}
> > >                            {% if forloop.last and not forloop.first %}and 
> > > {% endif %}
> > >                               {{filmmaker.first_name }} 
> > > {{filmmaker.last_name}}
> > >                         {% endfor %}
> > >                   {% endwith %}
>
> > > Thanks,
> > > Wendy
>
> > > On Aug 16, 2:13 pm, Nick Serra  wrote:
>
> > > > Can you list your models.py for me? What exactly do you want to show
> > > > in your template? I'm guessing some sort of WHERE clause, like all
> > > > filmmakers for a film or something.
>
> > > > On Aug 16, 5:08 pm, Wendy  wrote:
>
> > > > > OK, I have the inline solution working in the admin, I can see why
> > > > > it's prettier!
> > > > > Now I'm trying to figure out how to refer to these filmmakers in my
> > > > > film list template, as there is no longer a film.filmmakers object...
> > > > > So when I look in mysql, films_filmmakerposition has an id, a
> > > > > filmmaker id, a film id and a position.
> > > > > My Filmmaker Object has a first name and last name.
> > > > > I'm not sure where to start on this one, any help would be greatly
> > > > > appreciated.
> > > > > Thanks,
> > > > > Wendy
>
> > > > > On Aug 16, 12:45 pm, Wendy  wrote:
>
> > > > > > Thanks, Nick, I just figured that out, doh!  So I got the first
> > > > > > example going, I guess I'll try the inline solution as well, if it's
> > > > > > the pretty way to do it...  It'll be good for me to actually see 
> > > > > > what
> > > > > > they both do.
> > > > > > W
>
> > > > > > On Aug 16, 12:28 pm, Nick Serra  wrote:
>
> > > > > > > The inline solution is the pretty way to do it. If you just want 
> > > > > > > the
> > > > > > > join to show up in the admin, then simply register the join model 
> > > > > > > in
> > > > > > > the admin like any other model. In your admin,py include
> > > > > > > FilmmakerPosition and then do 
> > > > > > > admin.site.register(FilmmakerPosition)
>
> > > > > > > On Aug 16, 3:24 pm, Wendy  wrote:
>
> > > > > > > > Thanks Nick,
> > > > > > > > I tried the first solution first.
> > > > > > > > You're right, the many to manys aren't editable on that page, 
> > > > > > > > but the
> > > > > > > > problem is, I'm not seeing anot

load auth data with natural keys

2010-08-16 Thread knight
Hi,

I am using django 1.2.1. I dumped the auth data with natural keys (--
natural), but when I try to load them I get the following error:

Installing xml fixture 'auth' from absolute path.
Problem installing fixture 'auth.xml': Traceback (most recent call
last):
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/
core/management/commands/loaddata.py", line 165, in handle
for obj in objects:
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/
core/serializers/xml_serializer.py", line 158, in next
return self._handle_object(node)
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/
core/serializers/xml_serializer.py", line 198, in _handle_object
data[field.attname] = self._handle_fk_field_node(field_node,
field)
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/
core/serializers/xml_serializer.py", line 222, in
_handle_fk_field_node
obj =
field.rel.to._default_manager.db_manager(self.db).get_by_natural_key(*field_value)
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/
contrib/contenttypes/models.py", line 15, in get_by_natural_key
ct = self.get(app_label=app_label, model=model)
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/db/
models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/var/peertv/peergw/.env/lib/python2.5/site-packages/django/db/
models/query.py", line 341, in get
% self.model._meta.object_name)
DoesNotExist: ContentType matching query does not exist.

What am I doing wrong?

Thanks, Alex A.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.