change in admin template django/contrib/admin/templates/widget

2008-11-21 Thread [EMAIL PROTECTED]

hi all, i am using debian etch stable version 0.95

please i would like to know if there is a way to change admin, when 
displaying link "Currently" in models.BooleanField.
When i have images locally this can be done just by changing urls.py . 
But when i copy this file to another server during saving the model, and 
updated the value in db, it would be nice to have chance to check if the 
image is loaded on the new server via admin for this model. So i was 
thinking about changing django/contrib/admin/templates/widget/file.html 
just to change some values. But i did not succeed.

thank you very much for any idea
pavel

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



Re: Custom Select widget choices - how to reuse choices?

2008-11-21 Thread Donn

On Friday, 21 November 2008 08:06:32 urukay wrote:
> easy way how to solve it is to put definition of your choices out of model
> definition:

Yeah, that's what I call a 'global', but is there no way to get the choices 
from the field in the model class?

\d

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



Re: Problems with file upload and model forms

2008-11-21 Thread Marc Barranco

Oh yeah!! It was that! Thank you veru much Alex :)

I forgot to put the template code, Here it is (mayb useful for some
other):

--upload.html--








{% for field in form %}

{{ field.label_tag }}
{{ field }}
{% if field.help_text %}{{ field.help_text }}{% 
endif %}
{% if field.errors %}{{ 
field.errors }}
{% endif %}


{% endfor %}






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



Re: Custom Select widget choices - how to reuse choices?

2008-11-21 Thread urukay


u can use ModelForm and you don't have to write choices.
Don't know any other way. But I don't suppose there is other way, these two
"ways" can solve everything, I think.
Or maybe someone else would help

R.


Donn Ingle wrote:
> 
> 
> On Friday, 21 November 2008 08:06:32 urukay wrote:
>> easy way how to solve it is to put definition of your choices out of
>> model
>> definition:
> 
> Yeah, that's what I call a 'global', but is there no way to get the
> choices 
> from the field in the model class?
> 
> \d
> 
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Custom-Select-widget-choices---how-to-reuse-choices--tp20606743p20617654.html
Sent from the django-users mailing list archive at Nabble.com.


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



Validating two forms in one

2008-11-21 Thread Florencio Cano

Hello all,
I have two models called User and Responsible. When I add a
Responsible automatically a User is added. I have only one form to add
a User and a Responsible.

class NewUserResponsibleForm(forms.Form):
username = forms.CharField(max_length=30)
password = forms.CharField(max_length=20, widget=forms.PasswordInput())
confirm_password = forms.CharField(max_length=20,
widget=forms.PasswordInput())
email = forms.EmailField(max_length=30)
name = forms.CharField(max_length=64)
responsible_boss = forms.BooleanField(required=False)

With the username and the password a User will be created. With the
others fields a Responsible will be created.
The problem is that I want to check that the username is unique and if
it is not, show the error in this form. If I check this form with
is_valid() the username is not checked against User and I can't use
the attribute unique=True in forms.Form.
I have tried gathering the info with this form and then passing the data to:

class UserForm(forms.ModelForm):
class Meta:
model = User

and the checking this form with is_valid(). But now the error is in
that form and not in NewUserResponsibleForm that is the form I show. I
would like to pass the errors from UserForm to NewUserResponsibleForm
or some way of doing what I'm trying.

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



Re: Validating two forms in one

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 10:28 +0100, Florencio Cano wrote:
> Hello all,
> I have two models called User and Responsible. When I add a
> Responsible automatically a User is added. I have only one form to add
> a User and a Responsible.
> 
> class NewUserResponsibleForm(forms.Form):
> username = forms.CharField(max_length=30)
> password = forms.CharField(max_length=20, widget=forms.PasswordInput())
> confirm_password = forms.CharField(max_length=20,
> widget=forms.PasswordInput())
> email = forms.EmailField(max_length=30)
> name = forms.CharField(max_length=64)
> responsible_boss = forms.BooleanField(required=False)
> 
> With the username and the password a User will be created. With the
> others fields a Responsible will be created.
> The problem is that I want to check that the username is unique and if
> it is not, show the error in this form. If I check this form with
> is_valid() the username is not checked against User and I can't use
> the attribute unique=True in forms.Form.

All you need to do is write a clean_username() method that does the
validation you need. You can do any sort of custom checking on a form
field that you like by writing such a method. The documentation for this
is at 

http://docs.djangoproject.com/en/dev/ref/forms/validation/

Regards,
Malcolm



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



Dynamic columns in admin changelists

2008-11-21 Thread AndyB

I basically would like some way for staff users to choose which
columns are displaying in an object's changelist.

So far I've got an ugly solution which I can actually have some idea
how to implement and the 'correct' solution which requires quite a lot
of digging in the django internals.

The ugly solution is 'show everything and use jquery to control what
is displayed'

The correct solution I imagine would involve altering the list_display
properties that are created when the app's admin.py is imported.

Has anyone tried to do anything like this already?

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



Re: Using just one custom manager

2008-11-21 Thread Spoksss

Hello,

I have the same problem with entry_set in my related_manager.

On 8 Lis, 05:32, John M <[EMAIL PROTECTED]> wrote:
> DR,
>
> Now I have a new problem.  When I use this as a related_manager
> (Report.objects.all()[0].task_set.accomplishments()) it returns all
> the accomplishments.  I've even added the use_for_related_fields=True
> in the manager.  The all() (default) call seems to work fine, but the
> others done.
>
> Any ideas?
>
> Thanks
>
> John
>
> On Nov 7, 11:47 am, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Nov 7, 7:13 pm, John M <[EMAIL PROTECTED]> wrote:
>
> > > I wanted to get some feedback on how I'm using custom model managers.
>
> > > I've put all my queries into one manager, each in a different method.
> > > Is this the right way to go?
>
> > > So for example:
>
> > > CHOICES_TASK = (
> > >                         ("NO", "None"),
> > >                         ("GR", "Green"),
> > >                         ("YL", "Yellow"),
> > >                         ("RD", "Red"),
> > >                 )
>
> > > class TaskManager(models.Manager):
> > >         use_for_related_fields = True
>
> > >         # Task.objects.all()
> > >         def get_query_set(self):
> > >                 return super(TaskManager, self).get_query_set()
>
> > >         # Task.milestones()
> > >         def Milestones(self):
> > >                 return super(TaskManager,
> > > self).get_query_set().filter(milestone=True)
>
> > >         def Accomplishments(self):
> > >                 return super(TaskManager,
> > > self).get_query_set().filter(milestone=False).filter(completed=True)
>
> > >         def Nextsteps(self):
> > >                 return super(TaskManager,
> > > self).get_query_set().filter(milestone=False).filter(completed=False)
>
> > > class Task(models.Model):
> > >         report = models.ForeignKey(Report)
> > >         name = models.CharField(max_length=50)
> > >         started = models.BooleanField(default=False)
> > >         status = models.CharField(max_length=20, choices=CHOICES_TASK,
> > > default="NO")
> > >         completed = models.BooleanField(default=False)
> > >         duedate = models.DateField(blank=True, null=True)
> > >         milestone = models.BooleanField(default=False)
>
> > >         # Managers
> > >         objects = TaskManager()
> > >         milestones = TaskManager().Milestones
> > >         accomplishments = TaskManager().Accomplishments
> > >         nextsteps = TaskManager().Nextsteps
>
> > >         def __unicode__(self):
> > >                 return self.name
>
> > There's nothing wrong with the general idea - that's how I do it
> > myself, although the official docs say to use multiple managers and
> > override get_query_set on each one. A couple of comments on your
> > implementation though:
>
> > 1. There's no point in defining a get_query_set model simply to pass
> > to super. If you don't define it at all, it will just inherit from the
> > parent class anyway, which is exactly the same as what happens in your
> > version, so you may as well save two lines of code.
>
> > 2. The convention in Python/Django is to have all lower case names for
> > functions and methods - so it should be milestones, accomplishments,
> > etc.
>
> > 3. I don't think there's any point in defining all the extra manager
> > attributes that you have. Leave objects as TaskManager, then you can
> > do things like:
> > Task.objects.milestones()
> > Task.objects.accomplishments().filter(started=False)
> > or whatever.
>
> > --
> > DR.
>
>

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



Flatpage App vs. Static Template

2008-11-21 Thread Caisys

Hi,
I would like to publish some statics files on my website and I have a
some questions:
1- The flatpage app examples like http://www.lawrence.com/about/staph/
contain elaborate html, is this edited as a text field in the admin
interface, wouldn't it be tedious to maintain?
2- Can i do something like point all pages/(?P\w+) to
mysite.views.page_serve and create a view page_serve that accepts the
page name as a parameter and reners_to_response a template with the
same name?
This way I can edit my static pages easily with my web development
app?
Is there anything wrong with doing the above.
Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Select widget choices - how to reuse choices?

2008-11-21 Thread Daniel Roseman

On Nov 21, 9:09 am, Donn <[EMAIL PROTECTED]> wrote:
> On Friday, 21 November 2008 08:06:32 urukay wrote:
>
> > easy way how to solve it is to put definition of your choices out of model
> > definition:
>
> Yeah, that's what I call a 'global', but is there no way to get the choices
> from the field in the model class?
>
> \d

No, there isn't - this is one of the frustrating parts of customising
a ModelForm. You can't get the default widget attributes either.

There is an alternative, though: instead of overriding the fields
declaratively, you can define a formfield_callback function. This gets
passed each model field and must return a form field, but you can do
anything you want to it in the meantime. So, for example:

def customise_formfields(field):
field_obj = field.formfield()
if field.name == 'disk_type':
existing_choices = field_obj.choices
field_obj.widget = choicewidget(choices=existing_choices)
return field_obj

class CustomModelForm(forms.ModelForm):
formfield_callback = customise_formfields

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



Re: Flatpage App vs. Static Template

2008-11-21 Thread Daniel Roseman

On Nov 21, 11:29 am, Caisys <[EMAIL PROTECTED]> wrote:
> Hi,
> I would like to publish some statics files on my website and I have a
> some questions:
> 1- The flatpage app examples likehttp://www.lawrence.com/about/staph/
> contain elaborate html, is this edited as a text field in the admin
> interface, wouldn't it be tedious to maintain?
> 2- Can i do something like point all pages/(?P\w+) to
> mysite.views.page_serve and create a view page_serve that accepts the
> page name as a parameter and reners_to_response a template with the
> same name?
> This way I can edit my static pages easily with my web development
> app?
> Is there anything wrong with doing the above.
> Thanks

Well, the advantage of the flatpage app is that it's all there
already. It's quite easy to put TinyMCE or another WYSIWYG editor on
top of the admin to edit the HTML easily.
But there's nothing wrong with your proposal, if you fancy writing it.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpage App vs. Static Template

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 03:29 -0800, Caisys wrote:
> Hi,
> I would like to publish some statics files on my website and I have a
> some questions:
> 1- The flatpage app examples like http://www.lawrence.com/about/staph/
> contain elaborate html, is this edited as a text field in the admin
> interface, wouldn't it be tedious to maintain?

Depends upon how complicated the page is and how often you're going to
edit it.

> 2- Can i do something like point all pages/(?P\w+) to
> mysite.views.page_serve and create a view page_serve that accepts the
> page name as a parameter and reners_to_response a template with the
> same name?
> This way I can edit my static pages easily with my web development
> app?
> Is there anything wrong with doing the above.

Absolutely nothing at all wrong with doing that. You might want to have
a look at the direct_to_template view as well (see [1]) which provides a
fairly nice shortcut for that sort of thing. But even your own very
small view, if the generic one doesn't do everything you want is fine
(and, I suspect, not at all uncommon. I use that pattern a fair bit).

[1]
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-simple-direct-to-template

Regards,
Malcolm



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



Re: Dynamic columns in admin changelists

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 02:08 -0800, AndyB wrote:
> I basically would like some way for staff users to choose which
> columns are displaying in an object's changelist.
> 
> So far I've got an ugly solution which I can actually have some idea
> how to implement and the 'correct' solution which requires quite a lot
> of digging in the django internals.
> 
> The ugly solution is 'show everything and use jquery to control what
> is displayed'
> 
> The correct solution I imagine would involve altering the list_display
> properties that are created when the app's admin.py is imported.
> 
> Has anyone tried to do anything like this already?

I haven't tried it, but a couple of minutes looking at the code suggests
it shouldn't be too hard. The admin display, by design, is a class-based
setup, with particular methods you can override. If you look at the
ModelAdmin.changelist_view() method -- which is the one responsible for
the page you're interested in -- you'll see that it creates the page
using information from attributes on "self". So you could override that
method, set up self.list_display and self.list_display_links
appropriately and then pass off control to the base class method.

That's pretty much the intention of the admin system design: you
override the methods you want to change, often just setting up the
instance slightly differently before returning to the normal execution
paths.

Regards,
Malcolm


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



Request object from models

2008-11-21 Thread FT

class Document(models.Model):

created = models.DateTimeField(
help_text='Timestamp when the document is created',
blank=True,
default=datetime.datetime.now)

author = models.EmailField(blank=True, default=request.user)

Hi there,

I'm trying to set up a default value the author field in the model
above as the current user as the default value.
Is there any way to access the request object from here?

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



Re: Request object from models

2008-11-21 Thread Alex Koshelev
No. Request object does not exist when model classes are created.


On Fri, Nov 21, 2008 at 13:47, FT <[EMAIL PROTECTED]> wrote:

>
> class Document(models.Model):
>
>created = models.DateTimeField(
>help_text='Timestamp when the document is created',
> blank=True,
>default=datetime.datetime.now)
>
>author = models.EmailField(blank=True, default=request.user)
>
> Hi there,
>
> I'm trying to set up a default value the author field in the model
> above as the current user as the default value.
> Is there any way to access the request object from here?
>
> >
>

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



Re: django site within 7 hours (a day)

2008-11-21 Thread tom


> Although the submit button at the top doesn't seem to work...

the submit button should work now and it is also possible to add
releases to an application. looking forward having your app listed!

have a nice day!
tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Request object from models

2008-11-21 Thread Steve Holden

FT wrote:
> class Document(models.Model):
> 
> created = models.DateTimeField(
> help_text='Timestamp when the document is created',
> blank=True,
> default=datetime.datetime.now)
> 
> author = models.EmailField(blank=True, default=request.user)
> 
> Hi there,
> 
> I'm trying to set up a default value the author field in the model
> above as the current user as the default value.
> Is there any way to access the request object from here?
> 
The fact that you say "current user" implies that instances of the model
are created in response to a web request (i.e. when a view is running).
At that time, obviously, yo have access to the web request and so can
get hold of the user's identity.

But there is no way to know that information in advance, so you can't
specify it as a default value.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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



Re: Request object from models

2008-11-21 Thread barbara shaurette

Yeah, you want to assign that user_id value in the view, when you're
saving the instance:

mydocument.author_id = request.user.id
mydocument.save()

Are you trying to solve for a case where you want the current *admin*
user to be the author_id for the record?  You can also add a save
method to your admin class, something like this:

class DocumentAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.user = request.user
if not obj.author_id:
obj.author_id = obj.user_id
obj.save()

One other thing ... if you're going to populate 'author' with user_id,
you might want to change the model thusly:

author = models.ForeignKey(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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: configuring production server for static media

2008-11-21 Thread Serdar T.

For posterity, I should point out that Graham's suggestion did indeed
work and the final set of problems stemmed from my django app code. I
had copied over some old code from my development environment to the
production server, but the dev server was running an older version of
django so the code required some updates.

A thousand thanks to Graham for helping iron out the configuration
kinks and to Karen for reminding me to go back to basics and use
Debug. (and apologies for the earlier top posts)

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



How to test request.session after HttpResponseRedirect?

2008-11-21 Thread Florencio Cano

Hi!
Is there any way to access request.session from a unit test if I have
a response that is a HttpResponseRedirect. I know HttpResponse have
the attribute session but HttpResponseRedirect does not. I've read
that HttpResponseRedirect is a subclass of HttpResponse, can I access
to the HttpResponse with the session variable through
HttpResponseRedirect?
Any way of testing this?
The situation is that when I create a user succesfull after posting a
form I add a variable called 'notification' to the request.session
array and I want to test if it is filled properly.
Thanks!

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



NoReverseMatch question

2008-11-21 Thread goblue0311

Hi all:

I'm receiving this error:

#*
NoReverseMatch at /blog/
Reverse for 'blog_detail' with arguments '()' and keyword arguments
'{'year': 2008, 'slug': u'second_post', 'day': 21, 'month': 'nov'}'
not found."
#*

when I try to call this function from views.py:

#*
def post_list(request, page=0):
  queryset = Post.objects.published()

  for item in queryset:
print item.get_absolute_url()

  return list_detail.object_list(
  request,
  queryset,
  paginate_by = 20,
  page = page,
  )
#*

with this urls.py:

#*
url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?
P[-\w]+)/$',
view=blog_views.post_detail,
name='blog_detail'),
#*

This may be an odd thing to do, but I'm trying to debug an issue where
my blog_index view doesn't let me see the detailed view for any of the
blog entries. In any case, I think my URLconf and model definition of
get_absolute_url( ) are aligned, but maybe that's not the case.

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



Re: NoReverseMatch question

2008-11-21 Thread goblue0311

Another note if interest is that the error message is citing the
keyword arguments in the order year, slug, day, and month. However,
get_absoloute_url and the urls.py function use year, month, day, and
slug. Maybe I have some outdated code here, but where would it reside?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: NoReverseMatch question

2008-11-21 Thread Alex Koshelev
You have an underscore in slug - "second_post" but your regex doesn't allow
it - "[-\w]+". I think it is the problem.
And why you did you choose "\w" for day?


On Fri, Nov 21, 2008 at 17:16, goblue0311 <[EMAIL PROTECTED]> wrote:

>
> Hi all:
>
> I'm receiving this error:
>
> #*
> NoReverseMatch at /blog/
> Reverse for 'blog_detail' with arguments '()' and keyword arguments
> '{'year': 2008, 'slug': u'second_post', 'day': 21, 'month': 'nov'}'
> not found."
> #*
>
> when I try to call this function from views.py:
>
> #*
> def post_list(request, page=0):
>  queryset = Post.objects.published()
>
>  for item in queryset:
>print item.get_absolute_url()
>
>  return list_detail.object_list(
>  request,
>  queryset,
>  paginate_by = 20,
>  page = page,
>  )
> #*
>
> with this urls.py:
>
> #*
>url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?
> P[-\w]+)/$',
>view=blog_views.post_detail,
>name='blog_detail'),
> #*
>
> This may be an odd thing to do, but I'm trying to debug an issue where
> my blog_index view doesn't let me see the detailed view for any of the
> blog entries. In any case, I think my URLconf and model definition of
> get_absolute_url( ) are aligned, but maybe that's not the case.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: NoReverseMatch question

2008-11-21 Thread Jarek Zgoda

Wiadomość napisana w dniu 2008-11-21, o godz. 15:22, przez goblue0311:

> Another note if interest is that the error message is citing the
> keyword arguments in the order year, slug, day, and month. However,
> get_absoloute_url and the urls.py function use year, month, day, and
> slug. Maybe I have some outdated code here, but where would it reside?

Python doctionaries do not have any notion of "ordering".

-- 
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
[EMAIL PROTECTED]


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



Re: NoReverseMatch question

2008-11-21 Thread goblue0311

Thanks for the suggestion!

This code came from the basicApps collection, so I'm not sure why
they're using a Word regex to match the day, I'm going to try changing
that to Digit.

However, I did remove the underscore from my slug, so now it's just
'secondPost', and I get the same error. I also tried deleting all the
*.pyc files, because I'm a little concerned about the re-ordering of
the error message, although maybe that's nothing.


On Nov 21, 9:24 am, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> You have an underscore in slug - "second_post" but your regex doesn't allow
> it - "[-\w]+". I think it is the problem.
> And why you did you choose "\w" for day?
>
> On Fri, Nov 21, 2008 at 17:16, goblue0311 <[EMAIL PROTECTED]> wrote:
>
> > Hi all:
>
> > I'm receiving this error:
>
> > #*
> > NoReverseMatch at /blog/
> > Reverse for 'blog_detail' with arguments '()' and keyword arguments
> > '{'year': 2008, 'slug': u'second_post', 'day': 21, 'month': 'nov'}'
> > not found."
> > #*
>
> > when I try to call this function from views.py:
>
> > #*
> > def post_list(request, page=0):
> >  queryset = Post.objects.published()
>
> >  for item in queryset:
> >    print item.get_absolute_url()
>
> >  return list_detail.object_list(
> >      request,
> >      queryset,
> >      paginate_by = 20,
> >      page = page,
> >  )
> > #*
>
> > with this urls.py:
>
> > #*
> >    url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?
> > P[-\w]+)/$',
> >        view=blog_views.post_detail,
> >        name='blog_detail'),
> > #*
>
> > This may be an odd thing to do, but I'm trying to debug an issue where
> > my blog_index view doesn't let me see the detailed view for any of the
> > blog entries. In any case, I think my URLconf and model definition of
> > get_absolute_url( ) are aligned, but maybe that's not the case.
>
> > 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: NoReverseMatch question

2008-11-21 Thread goblue0311

good call - I repeated my concern below before I saw your response, so
please disregard.

On Nov 21, 9:35 am, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> Wiadomość napisana w dniu 2008-11-21, o godz. 15:22, przez goblue0311:
>
> > Another note if interest is that the error message is citing the
> > keyword arguments in the order year, slug, day, and month. However,
> > get_absoloute_url and the urls.py function use year, month, day, and
> > slug. Maybe I have some outdated code here, but where would it reside?
>
> Python doctionaries do not have any notion of "ordering".
>
> --
> We read Knuth so you don't have to. - Tim Peters
>
> Jarek Zgoda, R&D, Redefine
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Select widget choices - how to reuse choices?

2008-11-21 Thread Donn

On Friday, 21 November 2008 13:46:35 Daniel Roseman wrote:
> There is an alternative, though: instead of overriding the fields
> declaratively, you can define a formfield_callback function. 
This seems interesting. I have searched the docs online 
for 'formfield_callback' and get no useful results. Does anyone have a link 
to where I can learn more?

\d

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



order_by function

2008-11-21 Thread Luke Seelenbinder

Can I order_by a function within the model? I know you can list them
in the admin inteface, etc. But can you order_by a model function? Or
would you have to write a custom piece of code to do that?

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



Re: NoReverseMatch question

2008-11-21 Thread Jarek Zgoda

Wiadomość napisana w dniu 2008-11-21, o godz. 15:40, przez goblue0311:

> Thanks for the suggestion!
>
> This code came from the basicApps collection, so I'm not sure why
> they're using a Word regex to match the day, I'm going to try changing
> that to Digit.
>
> However, I did remove the underscore from my slug, so now it's just
> 'secondPost', and I get the same error. I also tried deleting all the
> *.pyc files, because I'm a little concerned about the re-ordering of
> the error message, although maybe that's nothing.


The NoReverseMatch will also pop up if the view function you declared  
to handle the url is not importable.

-- 
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
[EMAIL PROTECTED]


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



Re: Flatpage App vs. Static Template

2008-11-21 Thread DavidA

I do something like you are suggesting: I actually write my "flat"
pages in Markdown since I prefer it to HTML, and I keep the contents
in a file instead of the database, so I can edit them with Emacs. Then
I just route these special pages to a trivial template that uses the
markdown filter to render them.

On Nov 21, 6:29 am, Caisys <[EMAIL PROTECTED]> wrote:
> Hi,
> I would like to publish some statics files on my website and I have a
> some questions:
> 1- The flatpage app examples likehttp://www.lawrence.com/about/staph/
> contain elaborate html, is this edited as a text field in the admin
> interface, wouldn't it be tedious to maintain?
> 2- Can i do something like point all pages/(?P\w+) to
> mysite.views.page_serve and create a view page_serve that accepts the
> page name as a parameter and reners_to_response a template with the
> same name?
> This way I can edit my static pages easily with my web development
> app?
> Is there anything wrong with doing the above.
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: order_by function

2008-11-21 Thread Емил Иванов / Emil Ivanov

Check out
http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields

2008/11/21 Luke Seelenbinder <[EMAIL PROTECTED]>:
>
> Can I order_by a function within the model? I know you can list them
> in the admin inteface, etc. But can you order_by a model function? Or
> would you have to write a custom piece of code to do that?
>
> Thanks,
> Luke
> >
>



-- 
My place to share my ideas:
http://vladev.blogspot.com
http://carutoo.com

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



Re: Using just one custom manager

2008-11-21 Thread John M

Spoksss,

I brought this up as a BUG? subject and got some traction from
Malcom.  Malcom opened a tracking ticket to get it fixed.

I was able to work around it by sending some querysets to my view
before, instead of using the related sets in the view.  If you'd like
to see my work around, please let me know.

In the mean time, checkout my new topic, which Malcom answered
http://groups.google.com/group/django-users/browse_thread/thread/738460b50b0c96cd/65aa99bd3fcc9812?lnk=gst&q=bug%3F#65aa99bd3fcc9812

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



Re: order_by function

2008-11-21 Thread John M

I wanted the same thing long ago, you have a couple of choices: 1. Use
custom SQL functions (but kinda locks u in), 2. Use the python sort
function.  This basically takes ur queryset, turns it into a list and
then sorts it.

Since all querysets are just lists in python you can do this:

orderedlist = list(querysetX).

orderedlist.sort...  or something like that, you'll have to play with
the syntax.

But you can't use the Order_by on the queryset, because that
translates directly into SQL and that's not available.

John

On Nov 21, 6:56 am, Luke Seelenbinder <[EMAIL PROTECTED]> wrote:
> Can I order_by a function within the model? I know you can list them
> in the admin inteface, etc. But can you order_by a model function? Or
> would you have to write a custom piece of code to do that?
>
> Thanks,
> Luke
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: order_by function

2008-11-21 Thread Rajesh Dhawan

> Can I order_by a function within the model? I know you can list them
> in the admin inteface, etc. But can you order_by a model function? Or
> would you have to write a custom piece of code to do that?

In addition to the two solutions that John mentioned, you can do the
following in many cases:

Precompute the value of the model function and save it into a column
of your model. Then use the normal Django DB API to order by that
column etc.

You could compute and save this function's value from within an
overridden model.save() method. The advantage of this approach is that
you only compute the function when a model instance is saved or
updated. So it should work better than the Python list sort approach
in cases where you have a large number of records to go through *and*
where that function involves resource intensive calculations that you
don't really want to perform every time the instance is accessed.
Obviously, this doesn't work if the function's value changes based on
factors external to the model's own fields.

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



Re: Auto-notify outside/API services when instance Updated - Best Practices?

2008-11-21 Thread Rajesh Dhawan



On Nov 20, 3:40 pm, "John.R" <[EMAIL PROTECTED]> wrote:
> I'm working with an Event Model that, when saved (and possibly when
> updated) needs to run some custom Python code to notify some outside
> APIs - Twitter, Pownce, Google Calendar for instance.
>
> I know enough to implement Signals so that I don't have to code
> anything into the Event model itself if we change or add APIs later -
> but what's the best approach to this, when handling things like:
>
> What if one of several APIs is unavailable for update?
> Best way to keep track of that, and update only the correct ones
> later?
>
> -
> My initial thinking is to create a related Model that will store
> information in properties, like "was_twittered",
> "x_service_was_notified" that has a OneToOne relationship with the
> Event Model. Then in Signals I would create a new instance of that,
> related to the Event being saved/updated, and call a method on it that
> would attempt to contact any services that don't have their related
> "x_was_notified" property set to True.
>
> But then, what about later? What if one doesn't respond? How do I go
> back and tell it to retry later? Use cron? Implement a Django-based
> cron app? I'd like to self-contain as much as possible with this, so
> as to Not Repeat Myself, and to not go one a "wild goose chase" if
> something acts buggy later.
>
> Any ideas?

You could write messages to a queue model and set up a cron job that
picks up and dispatches "unprocessed" messages every X minutes. If the
cron job manages to process a message successfully, it marks that
message as "processed" or removes it from the queue. The messages
could be in a simple-to-parse format like JSON. This way, you can use
this mechanism for different kinds of events and activities without
tying it to one model.

Take a look at the Django Queue Service for a start:
http://code.google.com/p/django-queue-service/
For Django 1.0 compatibility, you will need to pick up the latest
branch from here: 
http://django-queue-service.googlecode.com/svn/branches/unstable/

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



Re: NoReverseMatch question

2008-11-21 Thread goblue0311

ok, the view function I'm using appears to be importable - because if
I remove the line "print item.get_absolute_url()", the view function
is called appropriately, with the odd exception that all instances
where the template is calling "get_absolute_url( )" are resolving to
the same page.

A clue may be that in the application urls.py file, when I replace
"view=blog_views.post_list" with "view=basicBlog.blog.views.post_list"
it claims to not be able to find "basicBlog"

Here's the complete code, I'm quite stuck on this and appreciate your
help:

urls.py from project root
#*
from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
(r'^$',  include('basicBlog.blog.urls')),
(r'^blog/',  include('basicBlog.blog.urls')),
(r'^comments/',  include('django.contrib.comments.urls')),
(r'^admin/(.*)', admin.site.root),
)
#*

urls.py from blog application
#*
from django.conf.urls.defaults import *
from basicBlog.blog import views as blog_views

urlpatterns = patterns('',
url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?
P[-\w]+)/$',
view=blog_views.post_detail,
name='blog_detail'),

url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$',
view=blog_views.post_archive_day,
name='blog_archive_day'),

url(r'^(?P\d{4})/(?P[a-z]{3})/$',
view=blog_views.post_archive_month,
name='blog_archive_month'),

url(r'^(?P\d{4})/$',
view=blog_views.post_archive_year,
name='blog_archive_year'),

url(r'^categories/(?P[-\w]+)/$',
view=blog_views.category_detail,
name='blog_category_detail'),

url (r'^categories/$',
view=blog_views.category_list,
name='blog_category_list'),

url (r'^search/$',
view=blog_views.search,
name='blog_search'),

url(r'^page/(?P\w)/$',
view=blog_views.post_list,
name='blog_index_paginated'),

url(r'^$',
view=blog_views.post_list,
name='blog_index'),
)
#*

and views.py for the post_list view:
#*
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
from django.views.generic import date_based, list_detail
from basicBlog.blog.models import *

import datetime
import re

def post_list(request, page=0):
  queryset = Post.objects.published()

  for item in queryset:
print item.get_absolute_url()

  return list_detail.object_list(
  request,
  queryset,
  paginate_by = 20,
  page = page,
  )
post_list.__doc__ = list_detail.object_list.__doc__

# this file goes 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Keeping fields out of the Admin

2008-11-21 Thread maeck

Please note that the result of this is that if you use
'editable=False' this field is not visible in the admin at all.
As far as I know there is no good way (see below) of putting read only
data in an admin page.

You could however, create a read only widget (there are some examples
to be fund on the internet), however, if you still need to save the
form, you nee dto keep that data in a hidden form field which opens up
the possibility of people fiddling with POST data.

Last resort, create your own custom view.

maeck.



On Nov 20, 11:46 pm, Lars Stavholm <[EMAIL PROTECTED]> wrote:
> Epinephrine wrote:
> > I have a field that should never be edited by hand.  It is basically
> > date_letter_sent, and it should be filled in by a view function when
> > it sends a letter.
>
> > How can I keep the field from being editable in the Admin edit page
> > for that class?
>
> editable = False in the model definition.
> /L
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using a HTML to fire off a data processing script on the server (REST or SOAP)

2008-11-21 Thread Jeff Anderson
Shao wrote:
> Dear ALL,
>
> I am very much interested in using a HTML to fire off a data
> processing script to run over the internet.
>
> I will be very grateful if you can advise me on passing parameters
> from an HTML form to a script and fire the script off to carry out
> full execution, monitor its progress and return an innerHTML with link
> (a name string of) the file generated back to allow user to download
> the result.
>
> The script run over a period of 2 to 3 minutes.
>   
I designed a system to do something similar, but never implemented it fully.

Basically, a Django view would fire off a Python thread that would run
the script, and report its progress. I chose to use a Django model that
the Python thread would store its progress in. The progress was
monitored by the end user via AJAX. It queried the progress of the job
once a second or so until it was completed. I only implemented a proof
of concept, where the script would only count to 100. Unfortunately, I
didn't save the code. The project I was doing it for was scrapped. The
proof of concept code was fairly easy to implement. I think it'd fit
your bill.

If you aren't familiar with AJAX, I suggest reading a tutorial about how
AJAX works, and then consider using an AJAX library.

Hopefully this gives you a good starting point.


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


model.Model has no attribute 'objects'

2008-11-21 Thread craic


I have a class called Raw which extends model. Much like every other
class. Except, i'm using the method on this page to connect to a
different DB.  In the admin tool, all is lovely. I can view and add
new "Raw" objects.

http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/

however, in my own view, when i try to use the model:   r =
Raw.objects.all() i get the error

type object 'Raw' has no attribute 'objects'

dumping the Raw object, indeed, it doesn't have 'objects'.

['DoesNotExist', 'MultipleObjectsReturned', '__class__',
'__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__',
'__hash__', '__init__', '__metaclass__', '__module__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__str__', '__unicode__', '__weakref__', '_collect_sub_objects',
'_default_manager', '_get_FIELD_display',
'_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order',
'_get_pk_val', '_meta', '_set_pk_val', 'delete', 'pk', 'save',
'save_base']


class Raw(models.Model):


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



Re: model.Model has no attribute 'objects'

2008-11-21 Thread craic


as soon as i posted i found the fix. my model needs to define the
objects and point to the custom manager, ie

class Raw(models.Model):
 objects = DBManager()



On Nov 21, 11:54 am, craic <[EMAIL PROTECTED]> wrote:
> I have a class called Raw which extends model. Much like every other
> class. Except, i'm using the method on this page to connect to a
> different DB.  In the admin tool, all is lovely. I can view and add
> new "Raw" objects.
>
> http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/
>
> however, in my own view, when i try to use the model:   r =
> Raw.objects.all() i get the error
>
> type object 'Raw' has no attribute 'objects'
>
> dumping the Raw object, indeed, it doesn't have 'objects'.
>
> ['DoesNotExist', 'MultipleObjectsReturned', '__class__',
> '__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__',
> '__hash__', '__init__', '__metaclass__', '__module__', '__ne__',
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
> '__str__', '__unicode__', '__weakref__', '_collect_sub_objects',
> '_default_manager', '_get_FIELD_display',
> '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order',
> '_get_pk_val', '_meta', '_set_pk_val', 'delete', 'pk', 'save',
> 'save_base']
>
> class Raw(models.Model):
>
> thoughts?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Where are you developing your python?

2008-11-21 Thread prem1er

Just wondering where everyone is developing there pythong code?
Anyone using development environments, if so which one?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

I am just simply trying to display all existing objects in a form

MODEL:
class Product(models.Model):
name = models.CharField(max_length=30)

def __unicode__(self):
return self.name

VIEW
def product(request):
product = Product.objects.all()
form = ProductForm(instance=product)
return render_to_response('index.html', {'form' : form})


Throws this error:
=

Environment:

Request Method: GET
Request URL: http://localhost:8000/product/
Django Version: 1.0.1 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'demo.home']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Django\demo\..\demo\home\views.py" in product
  10. form = ProductForm(instance=product)
File "C:\Python25\Lib\site-packages\django\forms\models.py" in
__init__
  216. object_data = model_to_dict(instance, opts.fields,
opts.exclude)
File "C:\Python25\Lib\site-packages\django\forms\models.py" in
model_to_dict
  119. opts = instance._meta

Exception Type: AttributeError at /product/
Exception Value: 'QuerySet' object has no attribute '_meta'




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



Re: Help with GeoDjango and Google Maps, please...

2008-11-21 Thread ChrisK

Well, this is interesting.

The problem seems to be that GPolygon calls

self.latlng_from_coords(poly.shell.coords)

to unpack the coordinates. I handed in 2D points for the shell
coordinates, but somewhere along the line, a third coordinate of
"almost zero" in floating point was added to every point. This causes
the code which expects two coordinates

return '[%s]' % ','.join(['new GLatLng(%s,%s)' % (y, x) for x, y in
coords])

to blow up.

I've hacked my copy to pull out and ignore the useless z coordinate.

Where can I file a bug?


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



Template tag attribute lookup with abstracted variable

2008-11-21 Thread Andy Young

I'm looking for an elegant way of stepping through my models from
within my template tags.

I have 3 model classes chained by many-to-many relationships, viz
Category --> Item --> Detail.  This model pertains to resume data,
e.g., Category='Education', Item='Univ1', Detail='Biology
coursework'.  Each model class has various subfields which I would
like to display on the final resume page.

I have tried various approaches involving {% for %} loops, and each
has resulted in failure.  Each of my attempts requires using a
variable name as a model's attribute lookup.  Unfortunately, it seem
the Django templating language attempts to access the variable's name,
not its value.

Approach 1):

I have pulled the field names from metadata in the view:

fields = []
for f in Item._meta.fields:
fields.append(f.column)

{% for c in categories %}
  {% for i in c.items.all %}
{% for f in fields %}
  {{ i.f }}
{% endfor %}
  {% endfor %}
{% endfor %}

There's no resulting output, indicating Django was looking for an "f"
attribute to the Item instance contained in "i".

I was thinking about using a {% with %} block to concatenate the value
of "f" to the end of the "i" Item instance.  It just seems incredibly
inelegant to have to explicitly list every field name I want
displayed.

Regards.

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



New Django user: How do I return the server's IP address?

2008-11-21 Thread [EMAIL PROTECTED]

Where can I get the Host server's IP address?

request.META['SERVER_NAME'] simply returns localhost instead of
whatever my ip address is

Thanks.

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



Re: Where are you developing your python?

2008-11-21 Thread Tim Chase

> Just wondering where everyone is developing there pythong code?
> Anyone using development environments, if so which one?

I'm from the old-school of folks that just use a text-editor (Vim 
in my case).  I tend to run it within "screen", with the 
following windows/screens:

  - editor (vim)
  - running the dev-server
  - just a shell/console (for things like file manipulation, 
pushing out to the server, or VCS commands -- mercurial in my 
case...I haven't bothered using any of the Vim VCS plugins)
  - sometimes, depending on where I'm developing, 
lynx/links/elinks as well so I can browse my results (though it's 
usually epiphany/dillo/firefox/safari).

I occasionally skip screen and just run them each in their own 
xterm as well, however, I like "screen"'s ability to detach and 
reattach from a remote machine via ssh.

Depending on the project, the development takes place on my the 
dev-server, on my work PC, or on one of my home laptops (an 
iBook, a Dell Mini-9, or an 8-year-old laptop running Debian -- 
all more than capable).  It's nice to use mercurial to sync 
development across multiple machines.

-tim





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



Re: Help with GeoDjango and Google Maps, please...

2008-11-21 Thread Ariel Mauricio Nunez Gomez
ChrisK,

I use:
*
from django.contrib.gis.geos import fromstr

gpoly=GPolygon(fromstr(poly.wkt, srid=4326))*

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



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread Karen Tracey
On Fri, Nov 21, 2008 at 4:22 PM, ayayalar <[EMAIL PROTECTED]> wrote:

>
> I am just simply trying to display all existing objects in a form
>
> MODEL:
> class Product(models.Model):
>name = models.CharField(max_length=30)
>
>def __unicode__(self):
>return self.name
>
> VIEW
> def product(request):
>product = Product.objects.all()
>form = ProductForm(instance=product)
>return render_to_response('index.html', {'form' : form})
>
>
> Throws this error:
> =
>
> Environment:
>
> Request Method: GET
> Request URL: http://localhost:8000/product/
> Django Version: 1.0.1 final
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'demo.home']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> get_response
>  86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "C:\Django\demo\..\demo\home\views.py" in product
>  10. form = ProductForm(instance=product)
> File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> __init__
>  216. object_data = model_to_dict(instance, opts.fields,
> opts.exclude)
> File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> model_to_dict
>  119. opts = instance._meta
>
> Exception Type: AttributeError at /product/
> Exception Value: 'QuerySet' object has no attribute '_meta'
>
>
> Any suggestions?
>

You don't show us ProductForm but I can guess it is a ModelForm for
Product.  A ModelForm is designed to display and let you edit one individual
object from the DB, not multiple.  Thus the 'instance' parameter to a model
form is supposed to be one single instance of a model, not a QuerySet.  A
model formset might be closer to what you are looking for:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1

Karen

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



Re: Where are you developing your python?

2008-11-21 Thread Ovnicraft
2008/11/21 Tim Chase <[EMAIL PROTECTED]>

>
> > Just wondering where everyone is developing there pythong code?
> > Anyone using development environments, if so which one?
>
> I'm from the old-school of folks that just use a text-editor (Vim
> in my case).  I tend to run it within "screen", with the
> following windows/screens:
>
>  - editor (vim)
>  - running the dev-server
>  - just a shell/console (for things like file manipulation,
> pushing out to the server, or VCS commands -- mercurial in my
> case...I haven't bothered using any of the Vim VCS plugins)
>  - sometimes, depending on where I'm developing,
> lynx/links/elinks as well so I can browse my results (though it's
> usually epiphany/dillo/firefox/safari).
>
> I occasionally skip screen and just run them each in their own
> xterm as well, however, I like "screen"'s ability to detach and
> reattach from a remote machine via ssh.
>
> Depending on the project, the development takes place on my the
> dev-server, on my work PC, or on one of my home laptops (an
> iBook, a Dell Mini-9, or an 8-year-old laptop running Debian --
> all more than capable).  It's nice to use mercurial to sync
> development across multiple machines.
>
> -tim
>
>
>
>
>
> >
>

Emacs + python-mode + Pymacs + django template mode on Slackware always ;-)


-- 
[b]question = (to) ? be : !be; .[/b]

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



Re: New Django user: How do I return the server's IP address?

2008-11-21 Thread Karen Tracey
On Fri, Nov 21, 2008 at 5:14 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>wrote:

>
> Where can I get the Host server's IP address?
>
> request.META['SERVER_NAME'] simply returns localhost instead of
> whatever my ip address is
>

Your machine likely has more than one IP address: one for each network
interface, including the local loopback interface, so usually at least two
when actually connected to a network.  Which one do you want?

More importantly -- what is the real problem you are trying to solve?  I
have a feeling you are not asking the right question to solve it.

Karen

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



Re: New Django user: How do I return the server's IP address?

2008-11-21 Thread Steve Holden

[EMAIL PROTECTED] wrote:
> Where can I get the Host server's IP address?
>
> request.META['SERVER_NAME'] simply returns localhost instead of
> whatever my ip address is
>
>   
Try

import socket
socket.gethostbyname(request.META['SERVER_NAME'])

regards
 Steve


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



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

Thanks Karen. That's exactly the case. Link you provided very helpful.

On Nov 21, 3:00 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Nov 21, 2008 at 4:22 PM, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > I am just simply trying to display all existing objects in a form
>
> > MODEL:
> > class Product(models.Model):
> >    name = models.CharField(max_length=30)
>
> >    def __unicode__(self):
> >        return self.name
>
> > VIEW
> > def product(request):
> >    product = Product.objects.all()
> >    form = ProductForm(instance=product)
> >    return render_to_response('index.html', {'form' : form})
>
> > Throws this error:
> > =
>
> > Environment:
>
> > Request Method: GET
> > Request URL:http://localhost:8000/product/
> > Django Version: 1.0.1 final
> > Python Version: 2.5.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'demo.home']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >  86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "C:\Django\demo\..\demo\home\views.py" in product
> >  10.     form = ProductForm(instance=product)
> > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > __init__
> >  216.             object_data = model_to_dict(instance, opts.fields,
> > opts.exclude)
> > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > model_to_dict
> >  119.     opts = instance._meta
>
> > Exception Type: AttributeError at /product/
> > Exception Value: 'QuerySet' object has no attribute '_meta'
>
> > Any suggestions?
>
> You don't show us ProductForm but I can guess it is a ModelForm for
> Product.  A ModelForm is designed to display and let you edit one individual
> object from the DB, not multiple.  Thus the 'instance' parameter to a model
> form is supposed to be one single instance of a model, not a QuerySet.  A
> model formset might be closer to what you are looking for:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpage App vs. Static Template

2008-11-21 Thread Caisys

Thank you all, it's my first django project and its nice to be
reassured ;)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

Karen,

On this note, is it possible to customize the widget's for formsets as
well?


Thank you.

On Nov 21, 3:23 pm, ayayalar <[EMAIL PROTECTED]> wrote:
> Thanks Karen. That's exactly the case. Link you provided very helpful.
>
> On Nov 21, 3:00 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > On Fri, Nov 21, 2008 at 4:22 PM, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > > I am just simply trying to display all existing objects in a form
>
> > > MODEL:
> > > class Product(models.Model):
> > >    name = models.CharField(max_length=30)
>
> > >    def __unicode__(self):
> > >        return self.name
>
> > > VIEW
> > > def product(request):
> > >    product = Product.objects.all()
> > >    form = ProductForm(instance=product)
> > >    return render_to_response('index.html', {'form' : form})
>
> > > Throws this error:
> > > =
>
> > > Environment:
>
> > > Request Method: GET
> > > Request URL:http://localhost:8000/product/
> > > Django Version: 1.0.1 final
> > > Python Version: 2.5.2
> > > Installed Applications:
> > > ['django.contrib.auth',
> > >  'django.contrib.contenttypes',
> > >  'django.contrib.sessions',
> > >  'django.contrib.sites',
> > >  'demo.home']
> > > Installed Middleware:
> > > ('django.middleware.common.CommonMiddleware',
> > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > > Traceback:
> > > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > > get_response
> > >  86.                 response = callback(request, *callback_args,
> > > **callback_kwargs)
> > > File "C:\Django\demo\..\demo\home\views.py" in product
> > >  10.     form = ProductForm(instance=product)
> > > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > > __init__
> > >  216.             object_data = model_to_dict(instance, opts.fields,
> > > opts.exclude)
> > > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > > model_to_dict
> > >  119.     opts = instance._meta
>
> > > Exception Type: AttributeError at /product/
> > > Exception Value: 'QuerySet' object has no attribute '_meta'
>
> > > Any suggestions?
>
> > You don't show us ProductForm but I can guess it is a ModelForm for
> > Product.  A ModelForm is designed to display and let you edit one individual
> > object from the DB, not multiple.  Thus the 'instance' parameter to a model
> > form is supposed to be one single instance of a model, not a QuerySet.  A
> > model formset might be closer to what you are looking for:
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1
>
> > Karen
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread [EMAIL PROTECTED]

You can pass modelformset_factory a kwarg form which should just me
the form class you want to use(aka make a ModelForm with the changes
to the widgets).

Alex

On Nov 21, 7:25 pm, ayayalar <[EMAIL PROTECTED]> wrote:
> Karen,
>
> On this note, is it possible to customize the widget's for formsets as
> well?
>
> Thank you.
>
> On Nov 21, 3:23 pm, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > Thanks Karen. That's exactly the case. Link you provided very helpful.
>
> > On Nov 21, 3:00 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > > On Fri, Nov 21, 2008 at 4:22 PM, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > > > I am just simply trying to display all existing objects in a form
>
> > > > MODEL:
> > > > class Product(models.Model):
> > > >    name = models.CharField(max_length=30)
>
> > > >    def __unicode__(self):
> > > >        return self.name
>
> > > > VIEW
> > > > def product(request):
> > > >    product = Product.objects.all()
> > > >    form = ProductForm(instance=product)
> > > >    return render_to_response('index.html', {'form' : form})
>
> > > > Throws this error:
> > > > =
>
> > > > Environment:
>
> > > > Request Method: GET
> > > > Request URL:http://localhost:8000/product/
> > > > Django Version: 1.0.1 final
> > > > Python Version: 2.5.2
> > > > Installed Applications:
> > > > ['django.contrib.auth',
> > > >  'django.contrib.contenttypes',
> > > >  'django.contrib.sessions',
> > > >  'django.contrib.sites',
> > > >  'demo.home']
> > > > Installed Middleware:
> > > > ('django.middleware.common.CommonMiddleware',
> > > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > > > Traceback:
> > > > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > > > get_response
> > > >  86.                 response = callback(request, *callback_args,
> > > > **callback_kwargs)
> > > > File "C:\Django\demo\..\demo\home\views.py" in product
> > > >  10.     form = ProductForm(instance=product)
> > > > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > > > __init__
> > > >  216.             object_data = model_to_dict(instance, opts.fields,
> > > > opts.exclude)
> > > > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > > > model_to_dict
> > > >  119.     opts = instance._meta
>
> > > > Exception Type: AttributeError at /product/
> > > > Exception Value: 'QuerySet' object has no attribute '_meta'
>
> > > > Any suggestions?
>
> > > You don't show us ProductForm but I can guess it is a ModelForm for
> > > Product.  A ModelForm is designed to display and let you edit one 
> > > individual
> > > object from the DB, not multiple.  Thus the 'instance' parameter to a 
> > > model
> > > form is supposed to be one single instance of a model, not a QuerySet.  A
> > > model formset might be closer to what you are looking for:
>
> > >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1
>
> > > Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



dynamic method calling

2008-11-21 Thread Chris

Hello everyone,
I have a quick python question. Is they a better way of calling a
method dynamically then what I have below? Is there a more elegant
approach? Thanks in advance.

try:
push = getattr(self, 'get_%s_content' % self.name)
except AttributeError:
raise "Method does not exist"
if callable(push):
push(**argv)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Currency field type in model

2008-11-21 Thread dash86no

I'm have a number of "price" fields in my application. I searched
around the net and it seems to be the case that there are no explicit
currency types in Django. What is the best data type to use for
currency? Would it be decimal?

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



Re: Custom Select widget choices - how to reuse choices?

2008-11-21 Thread Jeff FW

You could define the CHOICES as a member of your model class, like so:

class Movie( Relic ):
CHOICES=((u'1','one'), (u'2',u'two'))
disk_type = models.CharField( 'Type', max_length=8,
choices=CHOICES)

Then, in your form:

class MovieForm( BasicRelicForm ):
disk_type = forms.CharField( widget = choicewidget
( choices=Movie.CHOICES ))
class Meta:
model = Movie

That seems, to me, to be the cleanest way to do it.

You can also access the choices like this, but I wouldn't recommend
it:
choices = Movie._meta.get_field('disk_type').choices

-Jeff

On Nov 21, 4:09 am, Donn <[EMAIL PROTECTED]> wrote:
> On Friday, 21 November 2008 08:06:32 urukay wrote:
>
> > easy way how to solve it is to put definition of your choices out of model
> > definition:
>
> Yeah, that's what I call a 'global', but is there no way to get the choices
> from the field in the model class?
>
> \d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Currency field type in model

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 17:49 -0800, dash86no wrote:
> I'm have a number of "price" fields in my application. I searched
> around the net and it seems to be the case that there are no explicit
> currency types in Django. What is the best data type to use for
> currency? Would it be decimal?

It depends. A decimal field is certainly the right choice for the
numerical value. You also want to consider whether you need to store the
currency type, if it varies or might change for different rows in the
table. An extra character field or integer field to store the type could
then be used. Or you could use a character field and store a normalised
representation of the type + value, if you only wanted one column and
didn't need to directly do numerical work with the values (that is, you
could store "JPY 14000", "AUD 27.34", etc).

So consider if you want to work with the values numerically and if the
current type is a variable as well.

Regards,
Malcolm



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



Re: Template tag attribute lookup with abstracted variable

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 12:06 -0800, Andy Young wrote:
> I'm looking for an elegant way of stepping through my models from
> within my template tags.
> 
> I have 3 model classes chained by many-to-many relationships, viz
> Category --> Item --> Detail.  This model pertains to resume data,
> e.g., Category='Education', Item='Univ1', Detail='Biology
> coursework'.  Each model class has various subfields which I would
> like to display on the final resume page.
> 
> I have tried various approaches involving {% for %} loops, and each
> has resulted in failure.  Each of my attempts requires using a
> variable name as a model's attribute lookup.  Unfortunately, it seem
> the Django templating language attempts to access the variable's name,
> not its value.

It is deliberate that Django's template language doesn't support
indirect attribute lookup. Helps to keep things simple (part of the
"keep programming out of templates" design goal). However, that's just
the goal of Django's core. You can easily write a template tag or a
filter to do this (I believe somebody already has something similar on
djangosnippets, but I don't have any link to it, since I never have a
need to do this).

An alternate approach is to write a template tag that takes the list of
field names as an argument (perhaps takes a variable containing the list
of field names) and then returns the list of values you want. So you
could write something like

{% get_fields c fields as my_values %}
{% for value in my_values %}
   ...
{% endfor %}

Here, I'm making up an API where the tag puts the result in the
my_values variable, so that you can subsequently loop over it. You could
store the values there, or a list of (name, value) pairs, or make it a
dictionary; whatever, you like.

Regards,
Malcolm



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



Re: Currency field type in model

2008-11-21 Thread dash86no

Malclom,

Thanks for the helpful answer. I need to do numerical work on the
values so I think I'll store the currency type in a separate field.

Cheers,


On Nov 22, 10:54 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2008-11-21 at 17:49 -0800, dash86no wrote:
> > I'm have a number of "price" fields in my application. I searched
> > around the net and it seems to be the case that there are no explicit
> > currency types in Django. What is the best data type to use for
> > currency? Would it be decimal?
>
> It depends. A decimal field is certainly the right choice for the
> numerical value. You also want to consider whether you need to store the
> currency type, if it varies or might change for different rows in the
> table. An extra character field or integer field to store the type could
> then be used. Or you could use a character field and store a normalised
> representation of the type + value, if you only wanted one column and
> didn't need to directly do numerical work with the values (that is, you
> could store "JPY 14000", "AUD 27.34", etc).
>
> So consider if you want to work with the values numerically and if the
> current type is a variable as well.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Michael Keselman

Hello,

http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code)

Django's QuerySets allow you to do ORs (unions) pretty nicely with  
Model.manager.filter(Q(...) | Q(...)). However, ANDs don't work quite  
as nicely in my situation because I want AND to do what  
Model.manager.filter(Q(...)).filter(Q(...)) would do, but  
Model.manager.filter(Q(...) & Q(...)) does something very different.  
It does not compare fields with other rows in the table but rather  
with the same row against itself. For example, I have a Tag model with  
a CharField I call 'name'. If I were to do  
Tag.objects.filter(Q(name='text') & Q(name='password')), it would  
compare each tag to check if the tag's name equals "text" AND that the  
same tag's name equals "password".

Can you think of a way to fix eval_cmds() so that my app can parse a  
query like "(text & password) | (python & django)" which a user would  
enter? It seems like nothing I try will work.

Thank you,
Michael

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



Re: Dynamic columns in admin changelists

2008-11-21 Thread AndyB

Thanks Malcolm,

That was so much easier than I was expecting:

class ItemOptions(admin.ModelAdmin):
def changelist_view(self, request, extra_context=None):
self.list_display = request.session['item_columns']
return super(ItemOptions, self).changelist_view(request,
extra_context)

Incidentally - while reading around it I found this page which is a
treasure trove:

http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIaddanextracolumntothechangelistview

If anyone ever want to expands the 'customising the admin' sections of
the docs then that's the page to look at.

Andy

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



Re: Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Malcolm Tredinnick


On Fri, 2008-11-21 at 22:37 -0500, Michael Keselman wrote:
> Hello,
> 
> http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code)
> 
> Django's QuerySets allow you to do ORs (unions) pretty nicely with  
> Model.manager.filter(Q(...) | Q(...)). However, ANDs don't work quite  
> as nicely in my situation because I want AND to do what  
> Model.manager.filter(Q(...)).filter(Q(...)) would do, but  
> Model.manager.filter(Q(...) & Q(...)) does something very different.  
> It does not compare fields with other rows in the table but rather  
> with the same row against itself. For example, I have a Tag model with  
> a CharField I call 'name'. If I were to do  
> Tag.objects.filter(Q(name='text') & Q(name='password')), it would  
> compare each tag to check if the tag's name equals "text" AND that the  
> same tag's name equals "password".

Yeah, this is the edge-case that isn't handled out of the box. On the
(likely) probability that it's much less common than the alternative
behaviour, we decided to go with the current approach. You use-case
isn't invalid, but it's never the goal to support every possible
use-case.

Speaking as an implementor, I'll also note that it's the really, really
hard case to make it work efficiently in all cases (particularly with
highly nested trees of ANDs and ORs), so it falls close to, or possibly
over the line marked "out of scope for the ORM; custom SQL is your
friend".

I can think of four(!) possible approaches for your problem. In rough
order from least intrusive to the one requiring the most changes (and
roughly least efficient to most efficient), we have the following. I
haven't written code for any of these, so I'm using English rather than
Python. But my intuition is that they should all work.

(1) After you have parsed the query, rewrite it in conjunctive normal
form (CNF). That's a fairly routine transformation. Then each clause in
the CNF can be written as Q(...)|Q(...)|... and can be put in a separate
call to filter() (so you end up with one filter() call per clause in the
CNF). Guaranteed to give the right answer and requires no understanding
of Django's internals. The downside is that more comparisons than are
possibly necessary will be made. Still, in practice, the difference
possibly won't be noticed on a well-index table.

(2) Write your own variation on Q() -- let's call it Q1 here, for
brevity. This requires understanding what's going on when you call
filter() a bit, but since you are looking at a case that isn't normally
handled, you need to roll up your sleeves and dive in. It's not that
bad, really.

Basically, filter() wraps up its parameters in a Q() object and then
calls Query.add_q(). So calling Queryset.filter() is equivalent to an
outer call to Query.add_q(). The way a single call to add_q() knows that
it can (and should) reuse certain aliases is the used_aliases parameter
passed into add_q(). So you could force a particular alias not to be
reused if you adjusted used_aliases. Notice that used_aliases is also
passed to the add_to_query() method of any Q-like object you might pass
in. 

In practice, that means you write a class Q1 that subclasses Q and which
has an add_to_query() method. In your code that constructs the filter
call, you use Q1 when you are creating a conjunction of terms, rather
than Q -- for example, Q1(Q(name="a") & Q(name="b")). Your
Q1.add_to_query() method will then generally call Q.add_q(), except that
after each return it will remove any newly added aliases from
used_aliases so that they aren't reused inside that Q1. You can do this
by deep copying used_aliases before and restoring it afterwards. Just
before finally returning from your add_to_query() method, you might want
to add back all the used aliases so that any outer calls can reuse them.
It's this nested removing and readding of aliases that makes this a hard
problem (I would strongly suggest experimenting with something like (A &
(B|(C&D)) to make sure things work as expected).

(3) You could write your own equivalent to add_q() and call that for
your case. Since filter() calls add_q(), subclass QuerySet and add your
own disjoint_filter() method, say, that calls your own add_q() method --
which need not even be a separate method if you don't want to subclass
Query as well and don't mind calling setup_filter() directly. In your
own add_q() version, you might choose to not update used_aliases for
some or all situations. I think not updating used_aliases at all will
lead to very inefficient queries -- lots of unnecessary tables involved
-- so this could well reduce to option (2), above, in which case I'd go
with option (2). But have a think about it and see.

(4) Since it looks like you're doing the equivalent of text searching
with boolean operators, my fourth solution would be to use a text
searching tool. Solr or Sphinx or something like that which indexes the
tag field in question. The reason for suggesting this option is that
most of those search engines have 

Re: Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Michael Keselman


On Nov 21, 2008, at 11:46 PM, Malcolm Tredinnick wrote:

>
>
> On Fri, 2008-11-21 at 22:37 -0500, Michael Keselman wrote:
>> Hello,
>>
>> http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code)
>>
>> Django's QuerySets allow you to do ORs (unions) pretty nicely with
>> Model.manager.filter(Q(...) | Q(...)). However, ANDs don't work quite
>> as nicely in my situation because I want AND to do what
>> Model.manager.filter(Q(...)).filter(Q(...)) would do, but
>> Model.manager.filter(Q(...) & Q(...)) does something very different.
>> It does not compare fields with other rows in the table but rather
>> with the same row against itself. For example, I have a Tag model  
>> with
>> a CharField I call 'name'. If I were to do
>> Tag.objects.filter(Q(name='text') & Q(name='password')), it would
>> compare each tag to check if the tag's name equals "text" AND that  
>> the
>> same tag's name equals "password".
>
> Yeah, this is the edge-case that isn't handled out of the box. On the
> (likely) probability that it's much less common than the alternative
> behaviour, we decided to go with the current approach. You use-case
> isn't invalid, but it's never the goal to support every possible
> use-case.
>
> Speaking as an implementor, I'll also note that it's the really,  
> really
> hard case to make it work efficiently in all cases (particularly with
> highly nested trees of ANDs and ORs), so it falls close to, or  
> possibly
> over the line marked "out of scope for the ORM; custom SQL is your
> friend".
>
> I can think of four(!) possible approaches for your problem. In rough
> order from least intrusive to the one requiring the most changes (and
> roughly least efficient to most efficient), we have the following. I
> haven't written code for any of these, so I'm using English rather  
> than
> Python. But my intuition is that they should all work.
>
> (1) After you have parsed the query, rewrite it in conjunctive normal
> form (CNF). That's a fairly routine transformation. Then each clause  
> in
> the CNF can be written as Q(...)|Q(...)|... and can be put in a  
> separate
> call to filter() (so you end up with one filter() call per clause in  
> the
> CNF). Guaranteed to give the right answer and requires no  
> understanding
> of Django's internals. The downside is that more comparisons than are
> possibly necessary will be made. Still, in practice, the difference
> possibly won't be noticed on a well-index table.
>
> (2) Write your own variation on Q() -- let's call it Q1 here, for
> brevity. This requires understanding what's going on when you call
> filter() a bit, but since you are looking at a case that isn't  
> normally
> handled, you need to roll up your sleeves and dive in. It's not that
> bad, really.
>
> Basically, filter() wraps up its parameters in a Q() object and then
> calls Query.add_q(). So calling Queryset.filter() is equivalent to an
> outer call to Query.add_q(). The way a single call to add_q() knows  
> that
> it can (and should) reuse certain aliases is the used_aliases  
> parameter
> passed into add_q(). So you could force a particular alias not to be
> reused if you adjusted used_aliases. Notice that used_aliases is also
> passed to the add_to_query() method of any Q-like object you might  
> pass
> in.
>
> In practice, that means you write a class Q1 that subclasses Q and  
> which
> has an add_to_query() method. In your code that constructs the filter
> call, you use Q1 when you are creating a conjunction of terms, rather
> than Q -- for example, Q1(Q(name="a") & Q(name="b")). Your
> Q1.add_to_query() method will then generally call Q.add_q(), except  
> that
> after each return it will remove any newly added aliases from
> used_aliases so that they aren't reused inside that Q1. You can do  
> this
> by deep copying used_aliases before and restoring it afterwards. Just
> before finally returning from your add_to_query() method, you might  
> want
> to add back all the used aliases so that any outer calls can reuse  
> them.
> It's this nested removing and readding of aliases that makes this a  
> hard
> problem (I would strongly suggest experimenting with something like  
> (A &
> (B|(C&D)) to make sure things work as expected).
>
> (3) You could write your own equivalent to add_q() and call that for
> your case. Since filter() calls add_q(), subclass QuerySet and add  
> your
> own disjoint_filter() method, say, that calls your own add_q()  
> method --
> which need not even be a separate method if you don't want to subclass
> Query as well and don't mind calling setup_filter() directly. In your
> own add_q() version, you might choose to not update used_aliases for
> some or all situations. I think not updating used_aliases at all will
> lead to very inefficient queries -- lots of unnecessary tables  
> involved
> -- so this could well reduce to option (2), above, in which case I'd  
> go
> with option (2). But have a think about it and see.
>
> (4) Since it looks like you'r