using relationship fields in ModelAdmin

2010-01-11 Thread Mike Thon
I have an object in my model that has a OneToOne relationship with an
object in another app.  I would like to customize the way my object is
displayed in the admin interface by subclassing ModelAdmin as shown in
the tutorial.  I'm not sure how to reference fields across the
OneToOne relationship - i.e. I want to show fields from the object
referenced by the OneToOne relationship in the admin interface.  Is
there any way to do this?
Thanks
Mike
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Order model objects by foreign key "set" count

2010-01-11 Thread Margie Roginski
Ah - yes, that is so awesome!  For anyone interested, here's the magic
incantation:

Book.objects.annotate(Count('reader')).order_by('reader__count')

Or more verbosely:

Book.objects.annotate(num_readers=Count('reader')).order_by
('num_readers')

That documentation link describes it very well.   Thanks Scott!

Margie

On Jan 11, 7:51 pm, Scott Maher  wrote:
> Margie Roginski wrote:
> > Say I have a Reader model that has a foreign key to a Book
>
> > class Reader(models.Model):
> >   book = models.ForeignKey(Book)
>
> > Now say I want to find all books and order them by the number of
> > readers.  Is that possible, ie something like this?
>
> > Book.objects.all().order_by(reader_set__count)
>
> > This syntax doesn't work, however.  Is this possible?
>
> > Margie
>
> I can't give you specific code but I think that you want is under the
> Aggregation section of the documentation. Specifically I think you want
> to apply the Count object on the Book reader set. You were almost there. :)
>
> http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db...
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread kkerbel
That was it!  Thank you very much for your time and effort!

On Jan 11, 5:36 pm, Karen Tracey  wrote:
> On Mon, Jan 11, 2010 at 4:54 PM, kkerbel  wrote:
> > [snip]
> >  File "/usr/local/lib64/python2.5/site-packages/django/db/models/
> > fields/related.py", line 257, in __get__
> >   rel_obj = QuerySet(self.field.rel.to).get(**params)
>
> >  File "/usr/local/lib64/python2.5/site-packages/django/db/models/
> > query.py", line 305, in get
> >   % self.model._meta.object_name)
>
> > DoesNotExist: Employee matching query does not exist.
>
> > [snip]
>
> > ...also, this only happens with the approval and final_approval
> > models...the request model works fine and shows the details with no
> > problem.
>
> You need to check that the Employee in requested_by for ALL Requests is
> valid.  You already know that the specific Employee associated with the
> Request associated with the Approval you are attempting to view is valid
> because it is part of what you display on the changelist page.  However when
> you click on the link to produce the detail page you get an error noting
> that an Employee cannot be found.  A difference with the detail page,
> compared to the changelist page,  is that the detail page will have a select
> box listing all the Requests the Approval could be associated with.  My
> guess is somewhere you have a Request linked to an Employee that is no
> longer valid.  It is that Request which is causing the error.
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




How crypt python code

2010-01-11 Thread nameless
I have to upload my django project on shared hosting.
How can I crypt my code ?
I want to hide my code on server.

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




Re: Order model objects by foreign key "set" count

2010-01-11 Thread Scott Maher

Margie Roginski wrote:

Say I have a Reader model that has a foreign key to a Book

class Reader(models.Model):
  book = models.ForeignKey(Book)


Now say I want to find all books and order them by the number of
readers.  Is that possible, ie something like this?

Book.objects.all().order_by(reader_set__count)

This syntax doesn't work, however.  Is this possible?

Margie
  
I can't give you specific code but I think that you want is under the 
Aggregation section of the documentation. Specifically I think you want 
to apply the Count object on the Book reader set. You were almost there. :)


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




Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread Ovnicraft
2010/1/11 spike 

> Wow. Just WOW.
>
> I'm sorry to say this but, your audacity is embarrassing.
>
> I will continue to post here.
>

Would be better if you talk about you problems, experience, etc with django
**here** and tutorials or whatever in your blog :).

Cristian,

>
> Thank you.
>
> On Jan 11, 3:38 pm, Daniel Roseman  wrote:
> > On Jan 11, 10:27 pm, spike  wrote:
> >
> >
> > If you're planning on making a series of posts, can I beg you to
> > please not post them here, but to get a blog and put them there? It's
> > great that you have written this stuff, but Google Groups is not a
> > great place for keeping things for posterity. You can always post a
> > link here back to the new blog.
> >
> > --
> > 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>


-- 
Cristian Salamea
CEO GnuThink Software Labs
Software Libre / Open Source
(+593-8) 4-36-44-48
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Updated to revision 12207, now CSRF verification failed. Request aborted.

2010-01-11 Thread neridaj
I guess I had to add the middleware even though I'm using
django.contrib.comments and generic views?

On Jan 11, 7:12 pm, neridaj  wrote:
> what's up with this now. I'm suing contrib apps and generic views
> i.e., no middleware needed, and I've added {% csrf_token %} to my POST
> forms but can't get rid of this.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread spike
Wow. Just WOW.

I'm sorry to say this but, your audacity is embarrassing.

I will continue to post here.

Thank you.

On Jan 11, 3:38 pm, Daniel Roseman  wrote:
> On Jan 11, 10:27 pm, spike  wrote:
>
>
> If you're planning on making a series of posts, can I beg you to
> please not post them here, but to get a blog and put them there? It's
> great that you have written this stuff, but Google Groups is not a
> great place for keeping things for posterity. You can always post a
> link here back to the new blog.
>
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Order model objects by foreign key "set" count

2010-01-11 Thread Margie Roginski
Say I have a Reader model that has a foreign key to a Book

class Reader(models.Model):
  book = models.ForeignKey(Book)


Now say I want to find all books and order them by the number of
readers.  Is that possible, ie something like this?

Book.objects.all().order_by(reader_set__count)

This syntax doesn't work, however.  Is this possible?

Margie

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




Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread spike
Wow.

On Jan 11, 3:38 pm, Daniel Roseman  wrote:
> On Jan 11, 10:27 pm, spike  wrote:
>
>
> If you're planning on making a series of posts, can I beg you to
> please not post them here, but to get a blog and put them there? It's
> great that you have written this stuff, but Google Groups is not a
> great place for keeping things for posterity. You can always post a
> link here back to the new blog.
>
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Updated to revision 12207, now CSRF verification failed. Request aborted.

2010-01-11 Thread neridaj
what's up with this now. I'm suing contrib apps and generic views
i.e., no middleware needed, and I've added {% csrf_token %} to my POST
forms but can't get rid of this.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




contrib.comments get_absolute_url raising 404 only on remote server

2010-01-11 Thread neridaj
I've been testing my site locally and figured I should commit some of
my changes. I'm using django.contrib.comments and for some reason the
comment.get_absolute_url is resulting in a broken link on the live
server. When I mouse over the link the status bar reads the link
correctly i.e., http://mysite.com/comments/cr/12/1/#c5 but when I
click the link the result is 
http://example.com/blog/2010/jan/11/test-title-1/#c5
resulting in: The requested URL /blog/2010/jan/11/test-title-1/ was
not found on this server. If I manually type in my domain instead of
example.com it works as it should, I just don't understand why it's
not resolving with mysite.com.

Thanks,

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




Re: form.has_changed always true?

2010-01-11 Thread Alastair Campbell
On Fri, Jan 8, 2010 at 1:09 AM, Karen Tracey  wrote:
> Using the instance parameter is the POST leg also allows you to simply
> save() the form to get the changes to the instance saved.  There is then no
> need to individually copy each of the fields from the form's cleaned_data
> dict to the model instance.  See:

Thanks Karen, that worked great.

I had done quite a few non-model forms, which is a more manual
process, I hadn't twigged that you save the form rather than the
model. After that, the changed form aspect works great and I can
selectively output the changed data.

Thanks for the help,

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




Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread Daniel Roseman
On Jan 11, 10:27 pm, spike  wrote:
> Good points. Anyone looking for information of this nature after
> reading this thread is sure to find information that helps. I write
> this as a Django novice, hoping that the process of writing tutorials
> for myself as I learn and submitting them to the community for some
> amount of review will push me further, faster.
>
> Thank you for the comments, hopefully you'll read my next post
> tomorrow and have more good info.

If you're planning on making a series of posts, can I beg you to
please not post them here, but to get a blog and put them there? It's
great that you have written this stuff, but Google Groups is not a
great place for keeping things for posterity. You can always post a
link here back to the new blog.

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




Re: Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 4:54 PM, kkerbel  wrote:

> [snip]
>  File "/usr/local/lib64/python2.5/site-packages/django/db/models/
> fields/related.py", line 257, in __get__
>   rel_obj = QuerySet(self.field.rel.to).get(**params)
>
>  File "/usr/local/lib64/python2.5/site-packages/django/db/models/
> query.py", line 305, in get
>   % self.model._meta.object_name)
>
> DoesNotExist: Employee matching query does not exist.
>
> [snip]
>
> ...also, this only happens with the approval and final_approval
> models...the request model works fine and shows the details with no
> problem.
>
>
You need to check that the Employee in requested_by for ALL Requests is
valid.  You already know that the specific Employee associated with the
Request associated with the Approval you are attempting to view is valid
because it is part of what you display on the changelist page.  However when
you click on the link to produce the detail page you get an error noting
that an Employee cannot be found.  A difference with the detail page,
compared to the changelist page,  is that the detail page will have a select
box listing all the Requests the Approval could be associated with.  My
guess is somewhere you have a Request linked to an Employee that is no
longer valid.  It is that Request which is causing the error.

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-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread spike
Good points. Anyone looking for information of this nature after
reading this thread is sure to find information that helps. I write
this as a Django novice, hoping that the process of writing tutorials
for myself as I learn and submitting them to the community for some
amount of review will push me further, faster.

Thank you for the comments, hopefully you'll read my next post
tomorrow and have more good info.

On Jan 11, 2:11 pm, Shawn Milochik  wrote:
> A lot of this tutorial duplicates information in the official Django 
> tutorial. However, the official tutorial doesn't do any special hand-holding 
> for Windows users. Perhaps it would be helpful if you referred people to the 
> Django site for the tutorial, and gave all the Windows-specific stuff you've 
> had to figure out on your own to help out other Windows 
> users.http://docs.djangoproject.com/en/dev/intro/tutorial01/
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Brief tutorial to get a django dev server up.

2010-01-11 Thread Shawn Milochik
Since you asked for comments:

The Django core developers are looking to discontinue Python 2.3 support soon, 
so it's a good idea to recommend 2.4 as the minimum, or state which version of 
Django requires Python 2.3 or higher.

Just a personal preference, but I wouldn't recommend downloading and 
decompressing software to the root of the OS partition. It just clutters things 
up.

Instead of copying django-admin.py, add its folder to the PATH, or just specify 
the full path when running it, since you'll only do that very rarely.

You mention that Django comes with its own Web server in addition to supporting 
Apache and others. Technically, this is true, but it's very important to note 
that the built-in server is for development purposes only, because (among other 
reasons) it has not been tested or designed for security. It was never meant 
for production use, just development.

A lot of this tutorial duplicates information in the official Django tutorial. 
However, the official tutorial doesn't do any special hand-holding for Windows 
users. Perhaps it would be helpful if you referred people to the Django site 
for the tutorial, and gave all the Windows-specific stuff you've had to figure 
out on your own to help out other Windows users.
http://docs.djangoproject.com/en/dev/intro/tutorial01/

Shawn


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




Re: Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread kkerbel
admin.py
===
from django.contrib import admin
from . import models

class PerDiemInline(admin.StackedInline):
model = models.PerDiem

class AccountInline(admin.StackedInline):
model = models.Account

class RequestAdmin(admin.ModelAdmin):
list_display = ('requested_by', 'department', 'date_submitted',
'travel_start', 'travel_end',)
list_filter = ('department',)
inlines = (PerDiemInline, AccountInline)

class ApprovalAdmin(admin.ModelAdmin):
list_display = ('request', 'approved_by', 'approved_at', 'approved')
list_filter = ('approved', 'approved_by')

class FinalApprovalAdmin(admin.ModelAdmin):
list_display = ('request', 'approved_by', 'approved_at', 'approved')
list_filter = ('approved', 'approved_by')

admin.site.register(models.Request, RequestAdmin)
admin.site.register(models.Approval, ApprovalAdmin)
admin.site.register(models.FinalApproval, FinalApprovalAdmin)
===


models.py
===
from django.db import models
from django.db.models import Q
import datetime
from maysnet.directory.models import Employee, Department

class Request(models.Model):
requested_by = models.ForeignKey(Employee,
related_name="foreigntravel_requester")
department = models.ForeignKey(Department,
related_name="foreigntravel_targetdepartment")
no_travel_warning = models.BooleanField()
cibs_name = models.CharField("Name", max_length=100, blank=True,
null=True)
cibs_title = models.CharField("Title", max_length=100, blank=True,
null=True)
cibs_organization = models.CharField("Funding Organization",
max_length=100, blank=True, null=True)
teacher = models.BooleanField()
substitute_teacher = models.CharField("Teaching Duties Covered By",
max_length=100, blank=True)
destination = models.CharField(max_length=100)
travel_start = models.DateField(default=datetime.date.today() +
datetime.timedelta(days=10))
travel_end = models.DateField(default=datetime.date.today() +
datetime.timedelta(days=10))
purpose = models.TextField("Purpose of Travel")
benefit = models.TextField("Benefit to")
airfare = models.DecimalField(max_digits=7, decimal_places=2,
blank=True, null=True, default=0)
ground_transportation = models.DecimalField(max_digits=7,
decimal_places=2, blank=True, null=True, default=0)
registration_fee = models.DecimalField(max_digits=7,
decimal_places=2, blank=True, null=True, default=0)
meals = models.DecimalField(max_digits=7, decimal_places=2,
blank=True, null=True, default=0)
lodging = models.DecimalField(max_digits=7, decimal_places=2,
blank=True, null=True, default=0)
comments = models.TextField(null=True, blank=True)
date_submitted = models.DateField(auto_now_add=True)
send_to = models.ForeignKey(Employee, verbose_name="Department Head",
related_name="foreigntravel_requestrecipient")

def __unicode__(self):
return self.requested_by.__unicode__() + " - " +
self.date_submitted.strftime("%m/%d/%Y")

def status(self):
try:
self.approval
except:
return "Pending Approval"
try:
self.finalapproval
except:
if self.approval.approved:
return "Pending Final Approval"
else:
return "Denied"
if self.finalapproval.approved:
return "Approved"
else:
return "Denied"

class Meta:
ordering = ["-date_submitted"]
permissions = (
("approve_foreigntravel", "Can approve foreign travel"),
("finalapprove_foreigntravel", "Can give final approval 
for foreign
travel"),
("view_request", "Can view department foreign travel"),
)

class PerDiem(models.Model):
request = models.ForeignKey(Request)
city = models.CharField(max_length=50)
lodging = models.DecimalField(max_digits=7, decimal_places=2)
meals = models.DecimalField(max_digits=7, decimal_places=2)
order = models.IntegerField(default=1)

def __unicode__(self):
return self.city

class Meta:
ordering = ["-request", "order"]

class Account(models.Model):
request = models.ForeignKey(Request)
number = models.IntegerField()
name = models.CharField(max_length=50)
amount = models.DecimalField(max_digits=7, decimal_places=2)

def __unicode__(self):
return self.number.__unicode__()

class Meta:
ordering = ["-request", "number"]

class Approval(models.Model):
request = models.OneToOneField(Request)
approved_by = 

Brief tutorial to get a django dev server up.

2010-01-11 Thread spike
This is just a brief tutorial I wrote for myself without the intention
of releasing, but I figure if I can help just 1 person get started,
then why keep it to myself.

Again, not to be passed off as anything more then notes I wrote one
afternoon for my own understanding on a Windows machine.

Hope this helps someone. Comments ARE welcome.

---
When creating a project you’ll want to link it to a database. So
we'll, install Python, then Django, then the database. Create the
project, setup the database, then launch the development server. For
ease we’ll go with SQLite.

Django requires Python 2.3 or higher.

Install Python. When the installation is complete, add Python to the
system path so that it can be accessed from the command prompt. To do
this access “Control Panel > System > Advanced > Environment
Variables”. Select the “path” from the “System Variables” section and
append the Python installation directory.

Download and extract Django to the “C:\”. Then in the command prompt,
“cd” to the extracted directory.

To install Django run “(Django Directory) python setup.py install” or
to manually install, copy the Django folder to the Lib > site-packages
directory inside the Python directory.

The last step to install, copy django-admin.py from “(Django
Directory) > django > bin” to either c:\ or the Python directory.
After completed you will want to test the installation by running “c:
\>python django-admin.py --version”.

Django supports many database systems like MySQL, PostgreSQL, and
SQLite. Django has a database layer, which will interact with any
supported & selected database.

Python 2.5 or later comes with the SQLite module named, “sqlite3”.
SQLite stores the database in a single file.
To use MySQL you must install the MySQL driver, which is titled
“MySQLdb”.

Django comes with its own preconfigured webserver but does support
Apache and Lighttpd.

Now, to create a new project, run “django-admin.py startproject
(project title)”.
This command will create a folder named after the project title you
entered. Inside this folder will be 4 files: __init__.py, manage.py,
settings.py and urls.py. The file functions are as follows:
i.  __init__.py: This file tells python to treat this folder as a
package.
ii. manage.py: This is the project admin file, similar to django-
admin.py. So similar in fact they share the same code.
iii.settings.py: The main configuration file. Includes your database
settings, site language and Django features as well as more advanced
functions.
iv. urls.py: Configuration file. Maps the URLs with the Python
functions that handle them.

Open settings.py and set the database with “DATABASE_ENGINE”. For
SQLite enter “sqlite3”.

Next, name the database with “DATABASE_NAME”. Name it after your
project with “db” at the end. Example: “bookmarksdb”. Now save your
file.

Almost done. Cd into the project directory then tell Django to create
tables for the database with the command “python manage.py syncdb”.

Create your Superuser account. This process will create the file
titled after the database name. This file holds the application data.

Now run the development server with “python manage.py runserver”. You
can also change the default port from 8000 by appending your desired
port to the command.

Open your browser to http://127.0.0.1:8000/

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




Re: mod_wsgi and stderr

2010-01-11 Thread Graham Dumpleton


On Jan 12, 3:13 am, Patrick May  wrote:
> On Jan 5, 1:55 pm, Patrick May  wrote:
>
> >                 I'm running Django using mod_wsgi under Apache.  I'm trying 
> > to write messages to the Apache error log with:
>
> >                 sys.stderr.write('Message...')
>
> > but for some reason they don't appear.  This is under OS X (Snow Leopard).  
> > Do I have to configure something in httpd.conf to enable this?
>
> I'm still having this problem.  The relevant section of my httpd.conf
> looks like this:
>
> . . .
> LoadModule wsgi_module libexec/apache2/mod_wsgi.so
> . . .
> 
>     WSGIScriptAlias /codestreet /Users/Patrick/codestreet/src/rest/
> django.wsgi
>
>     
>     Order deny,allow
>     Allow from all
>     
> 
>
> My django.wsgi contains:
>
> import os
> import sys
>
> sys.path.append('/Users/Patrick/codestreet/src/rest')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'server.settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> The only errors I see in /var/log/apache2/error_log are:
>
> [Mon Jan 11 11:12:05 2010] [error] [client ::1] mod_wsgi (pid=93049):
> Exception occurred processing WSGI script '/Users/Patrick/codestreet/
> src/rest/django.wsgi'.
> [Mon Jan 11 11:12:05 2010] [error] [client ::1] IOError: failed to
> write data
>
> I have had some successful invocations, so I know the request is
> getting to the appropriate handler.  Any thoughts?

But where are you putting the call to write messages to error log?

Add at start of your WSGI script file:

  import sys
  print >> sys.stderr, 'IMPORTING WSGI SCRIPT FILE'

Do what is needed for your configuration to ensure script file
reloaded. Then look in Apache error logs for message. Ensure you check
all virtual host specific error logs as well as the main Apache error
log in case the issue is that you are misunderstanding which log it
should appear in, or your Apache configuration is wrong and matching
virtual hosts wrong and so going to wrong log file.

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




Re: mod_wsgi and stderr

2010-01-11 Thread Graham Dumpleton


On Jan 6, 6:29 am, Karen Tracey  wrote:
> On Tue, Jan 5, 2010 at 2:22 PM, Patrick May wrote:
>
>
>
>
>
> > On Jan 5, 2:18 pm, Karen Tracey  wrote:
> > > On Tue, Jan 5, 2010 at 1:55 PM, Patrick May  > >wrote:
>
> > > >                  I’m running Django using mod_wsgi under Apache.  I’m
> > > > trying to write messages to the Apache error log with:
>
> > > >                 sys.stderr.write(‘Message…’)
>
> > > > but for some reason they don’t appear.  This is under OS X (Snow
> > Leopard).
> > > > Do I have to configure something in httpd.conf to enable this?
>
> > > Do you also include sys.stderr.flush() ?
>
> > No, I thought that mod_wsgi did the flush automatically (from some
> > reading on the web).
>
> That's not been my experience.  Without an explicit call to .flush() I don't
> see the data written to sys.stderr appearing in the log file immediately.

It should auto flush on a newline being output if using
sys.stderr.write().

When using 'print >> sys.stderr', the 'print' adds a newline
automatically and so many wouldn't realise that it is the newline that
causes a flush to occur.

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




Re: How to get ModelAdmin given a Model

2010-01-11 Thread Matt Schinckel
On Jan 12, 4:11 am, Tomasz Zieliński
 wrote:
> On 11 Sty, 16:23, Marco Rogers  wrote:
>
> > I'm reposting this from earlier to see if I have better luck. I need
> > to be able to get the ModelAdmin associated with a model at runtime.
> > Similar to how django.db.models.get_model allows you to retrieve a
> > model.
>
> >     admin_class = get_admin(Model)
>
> > Is this possible?
>
> > The original post has more info.
>
> >http://groups.google.com/group/django-users/browse_thread/thread/0cd0...
>
> Maybe something like this:
>
> 1. Write something like django.contrib.admin.autodiscover, to get all
> ModelAdmins
> 2. Iterate those ModelAdmins, retrieve models they are attached to and
> store this mapping in a dict.
> 3. def get_admin(model):
>         return admin_to_model[model]

You should be able to iterate through admin.site._registry, and pull
out the one you need.

from django.contrib import admin
def get_admin(model):
for k,v in admin.site._registry.iteritems():
if v is model:
return v

Written in a browser.

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




Best way to fix django admin preview of flatpage attached to multiple sites

2010-01-11 Thread Tomasz Zieliński
I have flatpage attached to multiple sites. Its admin preview chooses
arbitrary site,
which is quite obvious after debugging up to lines 35-36 of
django.contrib.contenttypes.views.shortcut().

What would be the best way of fixing this problem?

I see that mentioned shortcut() function receives request object, so I
could just
extract host from there, but I prefer not to patch live server.

I haven't looked at catching admin url yet , so maybe someone can
suggest some nice solution?

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




Re: Django with embedded python - module error

2010-01-11 Thread Wim De Hul
On Mon, Jan 11, 2010 at 05:58:07PM -0300, Gonzalo Delgado wrote:
> El 10/01/10 18:06, Wim De Hul escribió:
> > I'm trying to use Django in an embedded python app (main program is in C).
> > When I try to import the models from my Django app, I get the following 
> > error:
> >
> > Traceback (most recent call last):
> >   File "/data/mytest/test.py", line 4, in 
> > from accounts import models
> >   File "/data/dj/accounts/models.py", line 1, in 
> > from django.db import models
> >   File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 41, in 
> > 
> > backend = load_backend(settings.DATABASE_ENGINE)
> >   File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 22, in 
> > load_backend
> > return import_module('.base', backend_name)
> >   File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, 
> > in import_module
> > __import__(name)
> > ImportError: No module named mysql.base
> >
> > This is my sys.path:
> >
> > ['/data/mytest', '/data/dj', '/data/dj', '/usr/lib/python2.6', 
> > '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', 
> > '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', 
> > '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', 
> > '/usr/lib/pymodules/python2.6/gtk-2.0', 
> > '/usr/local/lib/python2.6/dist-packages']
> >
> >
> > And this is the mysql module:
> > r...@lab:/data# ls -l /usr/lib/pymodules/python2.6/django/db/backends/mysql/
> > total 40
> > lrwxrwxrwx 1 root root52 2009-12-27 15:12 base.py -> 
> > /usr/share/pyshared/django/db/backends/mysql/base.py
> > -rw-r--r-- 1 root root 12169 2009-12-27 15:13 base.pyc
> > lrwxrwxrwx 1 root root54 2009-12-27 15:12 client.py -> 
> > /usr/share/pyshared/django/db/backends/mysql/client.py
> > -rw-r--r-- 1 root root  1581 2009-12-27 15:13 client.pyc
> > lrwxrwxrwx 1 root root56 2009-12-27 15:12 creation.py -> 
> > /usr/share/pyshared/django/db/backends/mysql/creation.py
> > -rw-r--r-- 1 root root  2939 2009-12-27 15:13 creation.pyc
> > -rw-r--r-- 1 root root 0 2009-12-27 15:13 __init__.py
> > -rw-r--r-- 1 root root   152 2009-12-27 15:13 __init__.pyc
> > lrwxrwxrwx 1 root root61 2009-12-27 15:12 introspection.py -> 
> > /usr/share/pyshared/django/db/backends/mysql/introspection.py
> > -rw-r--r-- 1 root root  4699 2009-12-27 15:13 introspection.pyc
> > lrwxrwxrwx 1 root root58 2009-12-27 15:12 validation.py -> 
> > /usr/share/pyshared/django/db/backends/mysql/validation.py
> > -rw-r--r-- 1 root root  1901 2009-12-27 15:13 validation.pyc
> > r...@lab:/data#
> >
> >
> > Everything seems OK for me... Django runs from Apache.
> > Someone has an idea?
> >   
> 
> MySQLdb[0] missing? The backend provided by Django depends on that.
> 
> [0] http://sourceforge.net/projects/mysql-python/
>
Well, that would be the case if it didn't run with mod-apache, but it does. 
Infact I found out that it is a Python problem.
It's also happening to the modules CVS and OpenSSL...

Strange...

 
> --
> Gonzalo Delgado 
> 

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


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




Re: Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread kkerbel
Ok...I'm sorry.  The change list page is what I'm referring to...I'll
try to gather some info and post it.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Django with embedded python - module error

2010-01-11 Thread Gonzalo Delgado
El 10/01/10 18:06, Wim De Hul escribió:
> I'm trying to use Django in an embedded python app (main program is in C).
> When I try to import the models from my Django app, I get the following error:
>
> Traceback (most recent call last):
>   File "/data/mytest/test.py", line 4, in 
> from accounts import models
>   File "/data/dj/accounts/models.py", line 1, in 
> from django.db import models
>   File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 41, in 
> 
> backend = load_backend(settings.DATABASE_ENGINE)
>   File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 22, in 
> load_backend
> return import_module('.base', backend_name)
>   File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in 
> import_module
> __import__(name)
> ImportError: No module named mysql.base
>
> This is my sys.path:
>
> ['/data/mytest', '/data/dj', '/data/dj', '/usr/lib/python2.6', 
> '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', 
> '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', 
> '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', 
> '/usr/lib/pymodules/python2.6/gtk-2.0', 
> '/usr/local/lib/python2.6/dist-packages']
>
>
> And this is the mysql module:
> r...@lab:/data# ls -l /usr/lib/pymodules/python2.6/django/db/backends/mysql/
> total 40
> lrwxrwxrwx 1 root root52 2009-12-27 15:12 base.py -> 
> /usr/share/pyshared/django/db/backends/mysql/base.py
> -rw-r--r-- 1 root root 12169 2009-12-27 15:13 base.pyc
> lrwxrwxrwx 1 root root54 2009-12-27 15:12 client.py -> 
> /usr/share/pyshared/django/db/backends/mysql/client.py
> -rw-r--r-- 1 root root  1581 2009-12-27 15:13 client.pyc
> lrwxrwxrwx 1 root root56 2009-12-27 15:12 creation.py -> 
> /usr/share/pyshared/django/db/backends/mysql/creation.py
> -rw-r--r-- 1 root root  2939 2009-12-27 15:13 creation.pyc
> -rw-r--r-- 1 root root 0 2009-12-27 15:13 __init__.py
> -rw-r--r-- 1 root root   152 2009-12-27 15:13 __init__.pyc
> lrwxrwxrwx 1 root root61 2009-12-27 15:12 introspection.py -> 
> /usr/share/pyshared/django/db/backends/mysql/introspection.py
> -rw-r--r-- 1 root root  4699 2009-12-27 15:13 introspection.pyc
> lrwxrwxrwx 1 root root58 2009-12-27 15:12 validation.py -> 
> /usr/share/pyshared/django/db/backends/mysql/validation.py
> -rw-r--r-- 1 root root  1901 2009-12-27 15:13 validation.pyc
> r...@lab:/data#
>
>
> Everything seems OK for me... Django runs from Apache.
> Someone has an idea?
>   

MySQLdb[0] missing? The backend provided by Django depends on that.

[0] http://sourceforge.net/projects/mysql-python/

--
Gonzalo Delgado 

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




Re: Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 2:59 PM, kkerbel  wrote:

> When viewing the admin pages for a travel request app we wrote, the
> admin page shows the record links, however, when you click to view the
> details of any record, I get an error stating "DoesNotExist: Employee
> matching query does not exist."  I've looked at the database and the
> employee does indeed exist and all of the related tables' keys link
> properly to each other.  I recently upgraded from Django 1.0 to 1.1.1,
> might there be a change between those versions that could cause this
> issue?  Any direction would be appreciated...i'm just failing to see
> what could be causing this.
>
>
It would help people help you if you were a bit more specific about what
admin pages are displaying these links, what their values are, what admin
definitions exist for the models(s) in question, etc.  Given that the
recommended way of specifying admin urls changed from 1.0 to 1.1 it might
also be helpful to include exactly what admin url pattern you are using
(though the old way should still work).

The basic admin function of listing all the objects on the change list page
with links to an edit page for each certainly still works in 1.1.1, so it's
a little hard to know what is going on in your case without more
information.

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-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: If Statements inside For Loops

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 1:02 PM, Dave Merwin  wrote:

> First of all, thanks to everyone for the help!!!
>
> I'm not getting any output after the else. Nothing displays in the
> template.
>
> That is what is confusing.
>
>
"Nothing displays in the template" sounds like either there is no user
variable in the context, or the user is in no groups.  Note that is not the
same as no "output after the else".  If you are saying you get group.name at
the top of the for loop displayed:

{% for group in user.groups.all %}
   {{ group.name }}

but nothing else, then that is mysterious (and something I cannot
recreate).

No output at all means the problem is elsewhere.  In that case you are
likely not passing the user in the context or passing a user that is in no
groups.

>From what you've reported I'm still not sure what is is you are seeing,
exactly.

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-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: text in translation strings?

2010-01-11 Thread Andreas Pfrengle
> {% url login as login_url %}
> {% blocktrans %}You need to login before
> you can do anything {% endblocktrans %}
>
> I'm curious if this is good guess, so please let me know.

It works! Didn't know that the url tag can name its result with "as".
Thanks again :-)
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Viewing details on a record in admin pages gives DoesNotExist error

2010-01-11 Thread kkerbel
When viewing the admin pages for a travel request app we wrote, the
admin page shows the record links, however, when you click to view the
details of any record, I get an error stating "DoesNotExist: Employee
matching query does not exist."  I've looked at the database and the
employee does indeed exist and all of the related tables' keys link
properly to each other.  I recently upgraded from Django 1.0 to 1.1.1,
might there be a change between those versions that could cause this
issue?  Any direction would be appreciated...i'm just failing to see
what could be causing this.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Mysterious transactions wrapping views without middleware.

2010-01-11 Thread apramanik
Sure, but the transaction is still open and PostgresSQL prevents any
other statements form being executed until it is closed. So, the db is
pretty much locked until the next transaction is started (which in my
case is when i render the view). I filed a bug for it:

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

On Jan 11, 10:20 am, Tomasz Zieliński
 wrote:
> On 10 Sty, 02:38, apramanik  wrote:
>
>
>
> > Thanks! That partially fixes my problem. I wrapped a function with
> > commit_on_success and it doesn't rollback the changes if it throws an
> > IntegrityError coming from PostgresSQL:
>
> > @transaction.commit_on_success
> >     def add_destination( self, placemark, trip, user,
> > \
> >                         description = None, status =
> > Item.SUGGESTED ) :
>
> >         ...
>
> >         # create the
> > destination
> >         destination = self.create(creator = user, description =
> > description,
> >                 status = status, location = location, trip =
> > trip)
>
> >         ...
>
> > So, if that create throws an IntegrityError, the transaction is *not*
> > rolled back. If I place "transaction.set_dirty()" before the create,
> > the transaction is rolled back. Seems like a bug.
>
> I'm not that sure - if there is fresh transaction and first statement
> in it is INSERT,
> and that insert fails, then the transaction is still empty - so there
> is nothing
> to be rolled back.
>
> --
> Tomasz Zielinskihttp://pyconsultant.eu
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Mysterious transactions wrapping views without middleware.

2010-01-11 Thread Tomasz Zieliński


On 10 Sty, 02:38, apramanik  wrote:
> Thanks! That partially fixes my problem. I wrapped a function with
> commit_on_success and it doesn't rollback the changes if it throws an
> IntegrityError coming from PostgresSQL:
>
> @transaction.commit_on_success
>     def add_destination( self, placemark, trip, user,
> \
>                         description = None, status =
> Item.SUGGESTED ) :
>
>         ...
>
>         # create the
> destination
>         destination = self.create(creator = user, description =
> description,
>                 status = status, location = location, trip =
> trip)
>
>         ...
>
> So, if that create throws an IntegrityError, the transaction is *not*
> rolled back. If I place "transaction.set_dirty()" before the create,
> the transaction is rolled back. Seems like a bug.
>

I'm not that sure - if there is fresh transaction and first statement
in it is INSERT,
and that insert fails, then the transaction is still empty - so there
is nothing
to be rolled back.

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




Re: Permissions (was: Namespace Security)

2010-01-11 Thread Shawn Milochik
Tim,

I think that if you replace the term "namespace" with "group," we can do what 
we both want with the same solution. Or, in other words, we're kind of saying 
the same thing but using different words.

In my scenario, each user would be in one or more groups. Each user could read 
or write anything they created. They could read or write things other people in 
the same group created (permissions allowing). If course, people can be in 
multiple groups. Exactly the same as the user permissions in *nix, rwx 
(read/write/execute) for ugo (user/group/other), except that I don't think 
'execute' really applies.

I think each model would have "hidden" fields for group and owner (creator), as 
the "logical delete" author created for deletion date. Each user would have a 
many-to-many with the same groups, and read and/or write permissions for those 
groups. This would be added by taking advantage of the AUTH_PROFILE_MODULE 
Django makes available.
http://docs.djangoproject.com/en/dev/topics/auth/#auth-profiles

Everything above would be ridiculously easy to implement. The rest (subclassing 
models.Model to enforce the behavior) might be pretty simple as well, but I 
haven't really rooted around in the Django internals enough to know how 
involved it is. Also, I could be missing a couple of steps if additional work 
is required to make it play nicely in the admin.

Does this line up with your vision, or is there a contradiction in goals?

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




Re: How to get ModelAdmin given a Model

2010-01-11 Thread Tomasz Zieliński
On 11 Sty, 16:23, Marco Rogers  wrote:
> I'm reposting this from earlier to see if I have better luck. I need
> to be able to get the ModelAdmin associated with a model at runtime.
> Similar to how django.db.models.get_model allows you to retrieve a
> model.
>
>     admin_class = get_admin(Model)
>
> Is this possible?
>
> The original post has more info.
>
> http://groups.google.com/group/django-users/browse_thread/thread/0cd0...

Maybe something like this:

1. Write something like django.contrib.admin.autodiscover, to get all
ModelAdmins
2. Iterate those ModelAdmins, retrieve models they are attached to and
store this mapping in a dict.
3. def get_admin(model):
return admin_to_model[model]

?

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




Re: Permissions (was: Namespace Security)

2010-01-11 Thread Tim
That looks like a pretty good starting point. It's a little different
in that for my scenario, UserA and UserB would both be accessing
django admin, but would get different results based on what Namespaces
they have access to.

Seems like it should be pretty easy to create a Model Admin that
overwrites the has_*_permission functions and the queryset funtion.
Given the model above, this prevents users from editing objects that
are not in a namespace they have access to.

class NamespacedAdmin(admin.ModelAdmin):
def has_change_permission(self, request, obj=None):
if obj and not ( obj.namespace in
request.user.namespace_set.all() ):
return False
return super(NamespacedAdmin, self).has_change_permission
(request, obj)

The has_add_permission(self, request) function looks to be more
tricky, since it doesn't accept an obj instance. Maybe some more
overwriting of the ModelAdmin functions could resolve that.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: text in translation strings?

2010-01-11 Thread Tomasz Zieliński


On 10 Sty, 12:59, Andreas Pfrengle  wrote:
> I'm having a template, where a link shall be inside a translation-
> marked text. I see two ways how to accomplish this, but both don't
> work:
> 1. {% trans "You need to login before
> you can do anything" %}
(...)
> 2. {% blocktrans %}You need to login
> before you can do anything {% endblocktrans %}
(...)
>
> Is there a way with either of these tags to accomplish what I want?
>

I haven't tried this but maybe it will work:

{% url login as login_url %}
{% blocktrans %}You need to login before
you can do anything {% endblocktrans %}

I'm curious if this is good guess, so please let me know.

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




Re: If Statements inside For Loops

2010-01-11 Thread Dave Merwin
First of all, thanks to everyone for the help!!!

I'm not getting any output after the else. Nothing displays in the
template.

That is what is confusing.

Dave

On Jan 11, 8:58 am, Karen Tracey  wrote:
> On Mon, Jan 11, 2010 at 2:39 AM, Dave Merwin  wrote:
> > I have the following:
>
> > {% for group in user.groups.all %}
> >    {{ group.name }}
> >    {% ifequal group.name "subscribed" %}
> >        I'm subscribed
> >    {% else %}
> >        {{ group.name }}
> >    {% endifequal %}
> > {% endfor %}
>
> > The else part of the statement is not rendering. What am I missing?
> > Any help welcome.
>
> This template code, when cut-and-pasted into a template used by a view that
> uses RequestContext and when logged in as a user who belongs to two groups
> (name subscribed and other), produces this output:
>
> subscribed I'm subscribed other other
>
> This is with Django 1.1.1.  So the code posted appears to work fine.  You
> say the else part of the statement is not rendering, but you do not say what
> output, exactly, you get, nor what output you are expecting for whatever
> user you happen to have.  What are you getting and how does it differ from
> what you expect?
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Permissions (was: Namespace Security)

2010-01-11 Thread Shawn Milochik
This is something we've been thinking a lot about recently. The direction we 
are considering is something like this:

http://github.com/paltman/django-logicaldelete

This code, "logical delete," overrides the delete() method of models so that 
they are simply marked as deleted, and not returned in queryset results. 
However, an administrator is still able to view the data.

Our plan is to use this project as a jumping-off point, and create a scheme 
(perhaps a Unix-style read/write permission set for user/group/all), and have 
our models automatically do the right thing. This way, the views and other code 
don't need to check permissions or do any additional filtering. It's my 
understanding that record-level permissions is coming in Django 1.2, but we 
can't wait that long.

The goal is to have all the code written as though permissions didn't exist, 
with the models.Model subclass having special permission functionality behind 
the scenes that restricted access automatically.

Is anyone doing this, or something like it? I don't want to duplicate work, and 
I'd love to save time if this is a solved problem. Alternately, I'd be happy to 
test and contribute to such an effort if someone has something rolling already. 

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




Re: Design Question - Extending a model

2010-01-11 Thread Igor
Thanks a lot - I didn't know about generic relations, and will
definitely look at them - right now :).

The minimal subset - and that's where I'm trying to follow DRY - boils
down to a Title,  a slug, Content HTML of the entry, maybe a couple
more things - all are very much like what you would expect to have in
a blog entry. It of course will also have comments, tags, category
etc. - these should all be standard.

But then, I want to be able add little things like event dates to it.
And I'm trying to avoid having to create a whole new template just
because I want to have one (or a few) extra -s on the page which
will display the event's dates. But this is the thing - event dates
are not the only one thing I want to display. In another case I want
it to be the same thing but have a rating... Maybe you're right and
all of those things should come as generic addons, since ratings,
comments etc are applicable to anything.

I'm really scared of your last point - redesigning relationships. This
seems to be the ugliest part if one happens to have to do this.

I have over 12 years of Web experience... and still looking for the
holy grail of OOD :) Hence are all the concerns.

I'd be happy to see references to any more examples, guides etc... I'm
sure there are some, but they're somehow difficult to find..

Additionally, I want to have one way of displaying it within HTML so I
don't need

On Jan 11, 5:21 pm, Ethan Jucovy  wrote:
> My instinct is that you may be trying to be too generic.  Without knowing
> more details, a "generic Entry" sounds a lot like .. a database record. :)
> Django's model.Model base class already does a great job at being easily
> extensible.
>
> Is there a specific minimal-but-interesting set of database fields that you
> want shared among all your models?  If so, you might want to use an abstract
> base class that all your real models inherit from.[1]
>
> Is there a specific set of functionalities that you want several types of
> persistent objects to support?  For this, unless you have very specific
> pluggability requirements, I would probably just define the functionality in
> a standalone function and informally adapt or handle each type as needed.
>
> Generic foreign keys[2] might also be helpful, if your requirements sound
> anything like "I have a Tag model, and I want to be able to attach Tags to
> any kind of object" or "I have a Comment model, and I want to be able to
> attach Comments to any kind of object."
>
> There are plenty of other approaches you could use too, of course, depending
> on your particular requirements.  When in doubt keep it simple and keep it
> in Python -- it's a pain to refactor complex model relationships if you
> change your mind later on; far less so to replace ad-hoc Python functions
> with complex model relationships when you realize you actually need them. :)
>
> -Ethan
>
> [1]http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-...
> [2]http://www.djangoproject.com/documentation/models/generic_relations/
>
> On Mon, Jan 11, 2010 at 9:24 AM, Igor  wrote:
> > Hi all,
>
> > This is a general question for whoever is good with best practices for
> > Django design (software design that is).
>
> > I'd like to implement (well, kinda have implemented), a generic Entry
> > object that would be good for several uses. For example, an Event
> > (such as, say, a website presentation) is just an Entry with one or
> > more start/end dates attached. A business listing in a catalogue is
> > basically an Entry with some other properties such as business rating
> > or whatever else. There's more to it but I think you get the idea - I
> > want the Entry to be EASILY extensible with more features. This
> > includes easily extending the templates if possible.
>
> > Am I trying to be too generic? Or, if not, what's a good approach to
> > take - I can use model inheritance, or an Event model could have an
> > Entry as a Foreign Key (which is what it does now). Or maybe there's a
> > whole other approach that I've missed but everyone else does? In any
> > case, how difficult would it be to access, say, all events that have a
> > post, or the other way around?
>
> > I'm sorry if I'm not precise or if this sounds stupid. I have a great
> > trust in Django, but so far I've been advancing a bit slowly. It would
> > be great to hear your opinions.
>
> > Thanks,
> > Igor
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, 

Re: If Statements inside For Loops

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 2:39 AM, Dave Merwin  wrote:

> I have the following:
>
> {% for group in user.groups.all %}
>{{ group.name }}
>{% ifequal group.name "subscribed" %}
>I'm subscribed
>{% else %}
>{{ group.name }}
>{% endifequal %}
> {% endfor %}
>
> The else part of the statement is not rendering. What am I missing?
> Any help welcome.
>
>
This template code, when cut-and-pasted into a template used by a view that
uses RequestContext and when logged in as a user who belongs to two groups
(name subscribed and other), produces this output:

subscribed I'm subscribed other other

This is with Django 1.1.1.  So the code posted appears to work fine.  You
say the else part of the statement is not rendering, but you do not say what
output, exactly, you get, nor what output you are expecting for whatever
user you happen to have.  What are you getting and how does it differ from
what you expect?

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-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Namespace Security

2010-01-11 Thread Tim
There is an interesting requirement in a project I am working on. For
lack of a better term, I'll call it Namespace Security. Basically,
there are arbitrary namespaces that can be defined, and every object
belongs to a namespace. Then, users only have access to certain
namespaces. So if a user has "add/change/delete course", he/she would
only be able to perform those actions on the namespace that he/she has
access to.

Basic models would look like this. Then any additional models just add
the ForeignKey to Namespace.

model Namespace(models.Model):
name = models.CharField()
users = models.ManyToManyField("auth.User")

model Course(models.Model):
namespace = models.ForeignKey(Namespace)

If a user has "add course" permission, and access to NamespaceA, he
can add a course to that namespace, but would not be able to add a
course to NamespaceB.

The issue is getting Django admin to recognize this. Has anyone seen
or done anything like this? I have a few ideas where to begin, but
figured I would ask first so I don't end up re-inventing the wheel if
something has already been started.

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




Download avatar 2009 for free

2010-01-11 Thread avatar3

Download avatar 2009
In the future, Jake, a paraplegic war veteran, is brought to another planet, Pandora, which is inhabited by the Na'vi, a humanoid race with their own language and culture. Those from Earth find themselves at odds with each other and the local culture.
Download avatar 2009
 
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Download avatar 2009 for free

2010-01-11 Thread avatar3

Download avatar 2009
In the future, Jake, a paraplegic war veteran, is brought to another planet, Pandora, which is inhabited by the Na'vi, a humanoid race with their own language and culture. Those from Earth find themselves at odds with each other and the local culture.
Download avatar 2009
 
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Design Question - Extending a model

2010-01-11 Thread Ethan Jucovy
My instinct is that you may be trying to be too generic.  Without knowing
more details, a "generic Entry" sounds a lot like .. a database record. :)
Django's model.Model base class already does a great job at being easily
extensible.

Is there a specific minimal-but-interesting set of database fields that you
want shared among all your models?  If so, you might want to use an abstract
base class that all your real models inherit from.[1]

Is there a specific set of functionalities that you want several types of
persistent objects to support?  For this, unless you have very specific
pluggability requirements, I would probably just define the functionality in
a standalone function and informally adapt or handle each type as needed.

Generic foreign keys[2] might also be helpful, if your requirements sound
anything like "I have a Tag model, and I want to be able to attach Tags to
any kind of object" or "I have a Comment model, and I want to be able to
attach Comments to any kind of object."

There are plenty of other approaches you could use too, of course, depending
on your particular requirements.  When in doubt keep it simple and keep it
in Python -- it's a pain to refactor complex model relationships if you
change your mind later on; far less so to replace ad-hoc Python functions
with complex model relationships when you realize you actually need them. :)

-Ethan

[1]
http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes
[2] http://www.djangoproject.com/documentation/models/generic_relations/

On Mon, Jan 11, 2010 at 9:24 AM, Igor  wrote:

> Hi all,
>
> This is a general question for whoever is good with best practices for
> Django design (software design that is).
>
> I'd like to implement (well, kinda have implemented), a generic Entry
> object that would be good for several uses. For example, an Event
> (such as, say, a website presentation) is just an Entry with one or
> more start/end dates attached. A business listing in a catalogue is
> basically an Entry with some other properties such as business rating
> or whatever else. There's more to it but I think you get the idea - I
> want the Entry to be EASILY extensible with more features. This
> includes easily extending the templates if possible.
>
> Am I trying to be too generic? Or, if not, what's a good approach to
> take - I can use model inheritance, or an Event model could have an
> Entry as a Foreign Key (which is what it does now). Or maybe there's a
> whole other approach that I've missed but everyone else does? In any
> case, how difficult would it be to access, say, all events that have a
> post, or the other way around?
>
> I'm sorry if I'm not precise or if this sounds stupid. I have a great
> trust in Django, but so far I've been advancing a bit slowly. It would
> be great to hear your opinions.
>
> Thanks,
> Igor
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: mod_wsgi and stderr

2010-01-11 Thread Patrick May
On Jan 5, 1:55 pm, Patrick May  wrote:
>                 I'm running Django using mod_wsgi under Apache.  I'm trying 
> to write messages to the Apache error log with:
>
>                 sys.stderr.write('Message...')
>
> but for some reason they don't appear.  This is under OS X (Snow Leopard).  
> Do I have to configure something in httpd.conf to enable this?

I'm still having this problem.  The relevant section of my httpd.conf
looks like this:

. . .
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
. . .

WSGIScriptAlias /codestreet /Users/Patrick/codestreet/src/rest/
django.wsgi


Order deny,allow
Allow from all



My django.wsgi contains:

import os
import sys

sys.path.append('/Users/Patrick/codestreet/src/rest')

os.environ['DJANGO_SETTINGS_MODULE'] = 'server.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

The only errors I see in /var/log/apache2/error_log are:

[Mon Jan 11 11:12:05 2010] [error] [client ::1] mod_wsgi (pid=93049):
Exception occurred processing WSGI script '/Users/Patrick/codestreet/
src/rest/django.wsgi'.
[Mon Jan 11 11:12:05 2010] [error] [client ::1] IOError: failed to
write data


I have had some successful invocations, so I know the request is
getting to the appropriate handler.  Any thoughts?

Thanks,

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




How to get ModelAdmin given a Model

2010-01-11 Thread Marco Rogers
I'm reposting this from earlier to see if I have better luck. I need
to be able to get the ModelAdmin associated with a model at runtime.
Similar to how django.db.models.get_model allows you to retrieve a
model.

admin_class = get_admin(Model)

Is this possible?

The original post has more info.

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




Design Question - Extending a model

2010-01-11 Thread Igor
Hi all,

This is a general question for whoever is good with best practices for
Django design (software design that is).

I'd like to implement (well, kinda have implemented), a generic Entry
object that would be good for several uses. For example, an Event
(such as, say, a website presentation) is just an Entry with one or
more start/end dates attached. A business listing in a catalogue is
basically an Entry with some other properties such as business rating
or whatever else. There's more to it but I think you get the idea - I
want the Entry to be EASILY extensible with more features. This
includes easily extending the templates if possible.

Am I trying to be too generic? Or, if not, what's a good approach to
take - I can use model inheritance, or an Event model could have an
Entry as a Foreign Key (which is what it does now). Or maybe there's a
whole other approach that I've missed but everyone else does? In any
case, how difficult would it be to access, say, all events that have a
post, or the other way around?

I'm sorry if I'm not precise or if this sounds stupid. I have a great
trust in Django, but so far I've been advancing a bit slowly. It would
be great to hear your opinions.

Thanks,
Igor



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




models.DateTimeField - Filter only time

2010-01-11 Thread tom
Hi,

i have a datetime field for my model. Now i want to filter all entries
where the time is between 12:00:00 and 13:00:00 .
How to do this?

I tried Entry.objects.filter(begin__gt='12:00:00', end__lt='13:00:00')

Cheers,

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




Re: Inline Admin and ForeignKey

2010-01-11 Thread Igor
Thanks, you're right... was posting this late at night while
experimenting and copied the experimental version... The way it looks
now is this:

class EventInline(admin.TabularInline):
model = Event

class EntryAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }
inlines = [ EventInline ]

Now, I've realized it works, but it always shows at least 3 Event
items in an admin page which is slightly annoying... I'd rather have
none with an option to add more if the user wants to.



On Jan 11, 2:26 pm, Daniel Roseman  wrote:
> On Jan 11, 12:43 am, Igor  wrote:
>
>
>
> > Hi,
>
> > I have a blog model and would like to be able to add an arbitrary
> > number of event dates to it (i.e. turn a blog post into an event
> > announcement). For that I use
>
> > class Event(models.Model):
> >     entry = models.ForeignKey(Entry)
> >     begin_date = models.DateTimeField(default=datetime.datetime.now)
> >     end_date = models.DateTimeField(default=datetime.datetime.now)
>
> > I hope this is good so far.
> > What I would like to happen is to be able to add those events inline -
> > inside an Entry editing page in the admin interface:
>
> > class EventInline(generic.GenericTabularInline):
> >     model = Event
> >     max_num         = 1   #TODO: Fix this
>
> > class EntryAdmin(admin.ModelAdmin):
> >         prepopulated_fields = { 'slug': ['title'] }
> >         inlines = [ EventInline ]
>
> > But in the Entry admin page I see three blocks of begin_date and
> > end_date. No option to edit/delete them, or add a new one. The three
> > are basically static.
>
> > What am I doing wrong?
>
> > Thanks for any ideas!
>
> On Jan 11, 12:43 am, Igor  wrote:
>
>
>
> > Hi,
>
> > I have a blog model and would like to be able to add an arbitrary
> > number of event dates to it (i.e. turn a blog post into an event
> > announcement). For that I use
>
> > class Event(models.Model):
> >     entry = models.ForeignKey(Entry)
> >     begin_date = models.DateTimeField(default=datetime.datetime.now)
> >     end_date = models.DateTimeField(default=datetime.datetime.now)
>
> > I hope this is good so far.
> > What I would like to happen is to be able to add those events inline -
> > inside an Entry editing page in the admin interface:
>
> > class EventInline(generic.GenericTabularInline):
> >     model = Event
> >     max_num         = 1   #TODO: Fix this
>
> > class EntryAdmin(admin.ModelAdmin):
> >         prepopulated_fields = { 'slug': ['title'] }
> >         inlines = [ EventInline ]
>
> > But in the Entry admin page I see three blocks of begin_date and
> > end_date. No option to edit/delete them, or add a new one. The three
> > are basically static.
>
> > What am I doing wrong?
>
> > Thanks for any ideas!
>
> Why are you using generic.GenericTabularInline rather than
> admin.TabularInline? I don't know if that's the cause of your problem,
> but it's bound to lead to some issues since you don't have a generic
> relation.
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




how to use an internal (multi-table inherited) OneToOneField

2010-01-11 Thread }--o
Hi,

I have the following three models

class AbstractModel
   title = CharField

class Quote(AbstractModel)

class Project(AbstractModel)

Instead of creating a new Project when a Quote gets accepted, I would prefer
extending the Quote's abstractproject_prt instance

could someone show me how to do this, please?

thanks, V
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Form Validation in Admin

2010-01-11 Thread Daniel Roseman
On Jan 11, 3:24 am, "Sasuke"  wrote:
> Hi all,
> I'm using the form's clean() method to do validation for models in admin. The 
> validation we need to do is to make sure there are no more than a certain 
> number of items totally submitted. So I calculate the total number of items 
> in the clean() method and check whether it is in the given range. But the 
> exact total number is difficult ot get because I don't know whether the newly 
> submitted form'data is a modified item that is already submitted or it's a 
> newly added item. So is there any way in the clean() method to know whether 
> the form's data is a newly added item or a modified one?
> Thanks to all.

Check the value of self.instance. If it exists, and it has a pk, then
it is a modification rather than an add.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Inline Admin and ForeignKey

2010-01-11 Thread Daniel Roseman
On Jan 11, 12:43 am, Igor  wrote:
> Hi,
>
> I have a blog model and would like to be able to add an arbitrary
> number of event dates to it (i.e. turn a blog post into an event
> announcement). For that I use
>
> class Event(models.Model):
>     entry = models.ForeignKey(Entry)
>     begin_date = models.DateTimeField(default=datetime.datetime.now)
>     end_date = models.DateTimeField(default=datetime.datetime.now)
>
> I hope this is good so far.
> What I would like to happen is to be able to add those events inline -
> inside an Entry editing page in the admin interface:
>
> class EventInline(generic.GenericTabularInline):
>     model = Event
>     max_num         = 1   #TODO: Fix this
>
> class EntryAdmin(admin.ModelAdmin):
>         prepopulated_fields = { 'slug': ['title'] }
>         inlines = [ EventInline ]
>
> But in the Entry admin page I see three blocks of begin_date and
> end_date. No option to edit/delete them, or add a new one. The three
> are basically static.
>
> What am I doing wrong?
>
> Thanks for any ideas!

On Jan 11, 12:43 am, Igor  wrote:
> Hi,
>
> I have a blog model and would like to be able to add an arbitrary
> number of event dates to it (i.e. turn a blog post into an event
> announcement). For that I use
>
> class Event(models.Model):
>     entry = models.ForeignKey(Entry)
>     begin_date = models.DateTimeField(default=datetime.datetime.now)
>     end_date = models.DateTimeField(default=datetime.datetime.now)
>
> I hope this is good so far.
> What I would like to happen is to be able to add those events inline -
> inside an Entry editing page in the admin interface:
>
> class EventInline(generic.GenericTabularInline):
>     model = Event
>     max_num         = 1   #TODO: Fix this
>
> class EntryAdmin(admin.ModelAdmin):
>         prepopulated_fields = { 'slug': ['title'] }
>         inlines = [ EventInline ]
>
> But in the Entry admin page I see three blocks of begin_date and
> end_date. No option to edit/delete them, or add a new one. The three
> are basically static.
>
> What am I doing wrong?
>
> Thanks for any ideas!

Why are you using generic.GenericTabularInline rather than
admin.TabularInline? I don't know if that's the cause of your problem,
but it's bound to lead to some issues since you don't have a generic
relation.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: If Statements inside For Loops

2010-01-11 Thread G B Smith
If the docs are to be believed, {% ifequal %} does provide an option
for an {% else %} clause. See 
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal

That said, I can't tell from the code above why it would not work. But
if you are using Django dev version (post 1.1) then go for the built-
in smarter {% if %} tag, like so: -

{% for group in user.groups.all %}
{{ group.name }}
{% if group.name == "subscribed" %}
I'm subscribed
{% else %}
{{ group.name }}
{% endif %}
{% endfor %}

GBS.

On Jan 11, 1:09 pm, andreas schmid  wrote:
> i think ifequal does not accept an else in the statement.
>
> Dave Merwin wrote:
> > I have the following:
>
> > {% for group in user.groups.all %}
> >     {{ group.name }}
> >     {% ifequal group.name "subscribed" %}
> >         I'm subscribed
> >     {% else %}
> >         {{ group.name }}
> >     {% endifequal %}
> > {% endfor %}
>
> > The else part of the statement is not rendering. What am I missing?
> > Any help welcome.
>
> > Thanks,
> > Dave
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Reverse filtering via ManytoManyField

2010-01-11 Thread janedenone
Solved (in Django 1.1):

tags = Tag.objects.annotate(num_pages=Count('page')).filter
(num_pages__gt=0)

On 9 Jan., 19:50, janedenone  wrote:
> I defined two models (Tag and Page), where the Page model links to the
> Tag model:
>
> tags = models.ManyToManyField(Tag, blank=True)
>
> For a single tag, I can refer to the pages linked to that tag like so:
>
> for page in tag.page_set:
>    ...
>
> results = tag.page_set.count()
>
> But I cannot find a way to obtain a list of tags where each tag is
> linked to at least one page. My attempt
>
> tags = Tag.objects.filter(page_set__count__gt=0)
>
> results in an error: Django complains that the field 'page_set' is
> unknown. Why can I use page_set as a 'virtual' tag property (even
> though this set is not defined in the model), and how can I refer to
> the page_set in a query?
>
> Many thanks,
> Jan
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: autocomplete widget

2010-01-11 Thread Sam Walters
Hi
The widget source code is here, its pretty easy to see wats going on,
if im dealing with forms i spend a lot of time in here:
http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py

And the docs are here:
http://docs.djangoproject.com/en/1.1/ref/forms/widgets/#ref-forms-widgets
http://docs.djangoproject.com/en/1.1/ref/forms/fields/#ref-forms-fields
http://docs.djangoproject.com/en/1.1/ref/forms/api/#ref-forms-api

cheers
sam

On Sun, Jan 10, 2010 at 5:13 AM, nameless  wrote:
> Thank you it's very useful.
> Now I need to create a new widget in django but I don't know where is
> the documentation about widget.
>
>
> On Jan 9, 4:42 pm, "esatterwh...@wi.rr.com" 
> wrote:
>> What I do for auto completers ( in general ) is point the widget at a
>> URL that returns JSON objects and the parse the objects client side.
>> For the user object your function might look like this:
>>
>> from django.utils import simplejson
>> from django.contrib.auth.models import User
>> from django.http import HttpResponse
>>
>> def ajax_get_users(request):
>>  users  = User.objects.filter(username__istarstswith = request.POST
>> ['q'])
>>  return HttpResponse(simplejson.dumps([dict(username=u.username,
>> id=u.pk) for u in users]), mimetype='text/javascript'))
>>
>> should get something that looks like this
>>
>> [
>>    {username:'username',id:4},
>>    {username:'username2',id:5}
>> ]
>>
>> [urls.py]
>> url(r'^/member/search/$', 'path.to.views.ajax_get_users',
>> name="myapp_ajax_user_search"),
>>
>> if you have your widget set up to include the needed javascript that
>> should be it. Honestly, the JS parts is more difficult than the django
>> part.
>>
>> Hope that makes sense
>> On Jan 8, 1:46 pm, nameless  wrote:
>>
>> > Hi at all, I am looking for a working simple example on autocomplete
>> > widget for foreign key in Django. I have found many example but I
>> > don't understand and doesn't work.
>>
>> > This is my model:
>>
>> > class profile(models.Model):
>>
>> > user = models.ForeignKey(User, unique=True)
>>
>> > class profileForm(ModelForm):
>>
>> > user = forms.CharField(widget=AutoCompleteWidget())
>>
>> > class Meta:
>> >     model = profile
>>
>> > I wish an AutoCompleteWidget working for this example.
>>
>> > Could anyone help me pleaseee ?
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: text in translation strings?

2010-01-11 Thread Michael P. Jung
> I'm having a template, where a link shall be inside a translation-
> marked text. (...)

I've recently run across a similar problem and solved it using some
nasty with-tag trickery.

In your case the following code should do the trick:

{% url login as login_url %}
{% with "" as link_begin %}
{% with "" as link_end %}
{% blocktrans %}Please {{ link_begin }}login{{ link_end }} to proceed.
{% endblocktrans %}
{% endwith %}
{% endwith %}


{% blocktrans %} also has a builtin "with" support, but for some reason
it does not support escaping special characters.

So the following doesn't work:

{% blocktrans with "" as link_begin
and "" as link_end %}Please {{ link_begin }}login{{ link_end }} to
proceeed.{% endblocktrans %}


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




Re: handle astronomically high number of users via the new BigIntegerField and contrib.auth.user

2010-01-11 Thread G B Smith
That's a good snippet, but I am sticking with
django.contrib.auth.models.user.id = BigIntegerField(primary_key=True)
for now.

On Jan 10, 11:46 pm, Eric Chamberlain  wrote:
> We used one of the UUID fields from djangosnippets.org 
> .
>
> On Jan 9, 2010, at 6:56 PM, G B Smith wrote:
>
> > Eric, could you explain how this UUID implementation was achieved?
> > Django doesn't have a built-in UUID, so I can only guess that you used
> > a varchar field within Django. ?
>
> > On Jan 10, 2:29 am, Eric Chamberlain  wrote:
> >> On Jan 9, 2010, at 8:59 AM, G B Smith wrote:
>
> >>> Thanks, that is a good resource. So this is what I am going to do : -
> >>> -- modify the contrib.auth.models.user to explicitly include id =
> >>> models.BigIntegerField(primary_key=True)
> >>> -- modify the contrib.auth.models.user.id field in the database using
> >>> creecode's method above or via the mysql shell or phpmyadmin or other
> >>> tools (still deciding)
>
> >>> I am pretty sure this is going to have zero side-effects. If someone
> >>> knows otherwise, would be helpful to have that information.
>
> >> If your going to go to all that trouble, you may as well use a UUID field 
> >> instead.  We went with UUID, because we didn't want membership counts to 
> >> leak via an autoincrementing integer.
>
> >> --
> >> Eric Chamberlain, Founder
> >> RF.com -http://RF.com/
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.