streaming file uploads not working with Django 1.0

2008-09-26 Thread Faheem Mitha


Hi,

I just upgraded to Django 1.0, and I've just finished fixing all my unit 
tests. However, streaming file uploads are still broken. The behaviour I'm 
seeing is as follows:

When I start the upload of the file, a file which looks like eg. 
/tmp/tmpGjWpee.upload appears almost immediately, but does not change in 
size thereafter. The size is either empty or 16M. I haven't seen any other 
values appear. The file upload completes some of the time, regardless, but 
is very slow. For very large files, like 1g, it took so long I stopped it.

A model I'm using for testing purposes appears below.

I've seen this behavior on two independent installations of 1.0, with the 
same project/application. I have a different installation with a pre-1.0 
snapshot with a patch from #2070 applied, and that works fine with an 
earlier version of the same model/application, with the temporary file in 
/tmp appearing and growing in size as the upload progresses, as expected.

Suggestions for debugging would be appreciated. Please CC me on any reply. 
Thanks.

   Sincerely, Faheem Mitha.

class OldFileUpload(models.Model):
 upload_date = models.DateTimeField(default=datetime.now(), blank=True, 
editable=False)
 upload = models.FileField(upload_to=".")
 #name = models.CharField(core=True, max_length=100)
 name = models.CharField(max_length=100)
 description = models.CharField(blank=True, max_length=200)

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



Re: Ordering results by m2m relations without multiply results

2008-09-26 Thread Malcolm Tredinnick


On Fri, 2008-09-26 at 16:29 +0200, Alessandro wrote:
> I have a model with a m2m field "provincia".
> I want to order my objects in this way:
> If the object has a provincia = 'AA' on m2m relation must be the
> bottom of my list.
> 
> I tried query = query.order_by('-provincia') and it works correctly
> (because AA is the first of the values), but I duplicates the results
> because of multiple m2m relationships:
> If an object has both "FC" and "BO" in provincia, I will have 2
> objects in queryset also If I use distinct().

That's correct, since the fields you are ordering on are part of the
selected columns, so they make the entries non-distinct.
> 
> Is there a solution?

Not really, except for writing a raw SQL query. The raw SQL for this
type of query is very complicated and it's such an edge case (it's
trying to do if-then logic in SQL when you write it out) and not always
even possible, so Django doesn't even try. If you order on a
multi-valued field and have more than one related value, you'll get
multiple rows.

You might want to prefer to do the ordering in Python or as a second
pass. Or you could try to write the raw SQL, but it could be fairly
messy.

Regards,
Malcolm


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



Re: Django v0.95 issue

2008-09-26 Thread Malcolm Tredinnick


On Thu, 2008-09-25 at 20:20 -0400, Xian Chen wrote:
> Hi All,
> 
> I have a problem with Django v0.95 ( I cannot convince the
> administrator to install 1.0 for me.)
> 
> I got this feedback:(
> 
> AttributeError at /xianchen/
> 'function' object has no attribute 'rindex'

You might have stumbled over ticket #2875, so manually applying the
patch that was used to fix that ticket might work. Unfortunately, if you
can't modify the source or install a copy locally (and if you could
install locally and run 1.0, that would be the preferred method), you're
not going to be able to do that.

> After looking up the internet, I found the urls.py should in this
> format(r'^$', 'app.views.main_page'),
> 
> But, it still does not work.

By "does not work", do you mean that it raised exactly the same error?
If so, I suspect that isn't the line that was originally causing the
problem, but that sort of change is certainly one way to work around the
problem in #2875. To work around the exception you're reporting, you
need to make sure there is at least one dot ('.') in the view name.

Regards,
Malcolm

> 


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



Re: How to View Raw Generated SQL

2008-09-26 Thread Malcolm Tredinnick


On Wed, 2008-09-24 at 20:45 -0700, Chris wrote:
> I'm trying to debug a usage of callproc, which doesn't return any rows
> when used inside Django. Is there anyway to view the SQL and escaped
> values sent from db cursor? 

There is no public API in the Python database wrappers to determine how
the values are escaped, so the second part of that question is "no".

> I found
> http://docs.djangoproject.com/en/dev/faq/models/#how-can-i-see-the-raw-sql-queries-django-is-running
> by this doesn't show anything. When they say "just do this", are they
> implying we should run that from a manage.py shell?

Yes. It only works when DEBUG=True, since connection.queries saves a
record of every query run in each request, which can sometimes consume a
lot of memory.

Alternatively, if you have a queryset, you can see the SQL it is about
to run (before it is executed) by looking at the output of 

my_queryset.query.as_sql()

That will work always, since it is exactly how Django generates the SQL
that it sends to the database (it returns a string and the list of
parameters that are substituted into the query).

Regards,
Malcolm



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



Re: Templates, context-setting custom tag and nested blocks - doesn't work ? (and is it supposed to anyway ?)

2008-09-26 Thread Malcolm Tredinnick


On Wed, 2008-09-24 at 02:36 -0700, bruno desthuilliers wrote:
> Hi all
> 
> I don't know wether it's me doing something wrong, or if it's a normal
> limitation of Django's templates, or else, but anyway, here's the
> problem:
> 
> I have a custom tag that sets a variable in the context (the usual
> way, ie 'context[self.varname] = something'). This is not my first
> custom tag, nor the first context-updating one, so I don't think
> there's anything wrong so far.
> 
> Now I have this template that extends a base template - I didn't wrote
> personnaly FWIW - that has quite a lot of nested blocks definitions -
> the idea being to let you override either a whole block or just part
> of it. Might be a good idea or not, don't know (as far as I'm
> concerned, I wouldn't have done such a thing, but that's another
> question...). The doc doesn't mention nesting blocks, but well, it
> seems to work fine... *as long* as you only access vars defined in the
> view itself *or* have the call to the context-setting tag in the same
> block where you access the var. That is : when calling a context-
> setting tag anywhere else (top level, prior block at the same level
> etc), the var is just not there.

I may not be completely understanding the problem you're explaining -- a
short example from you may help illustrate the exact difficulty.
However, it looks like what you're seeing is expected behaviour:
whenever a block ends (when an "endblock" marker is encountered),
anything set inside that block in the context is popped off the stack
and removed. The idea is that the Context instance is a stack of values
and each new nesting level introduces a new entry on the stack. When you
go to look up variable "foo", it finds the first occurence of "foo" in
the stack -- maybe in the current block, or in one of the ancestor
blocks (all the way back to the top-level template). When a block
finished, we remove all the context for that block so as not to pollute
any other processing.

It sounds like you're saying that an outer block cannot access an inner
block's context and that would be correct, since the context for the
inner block is only available inside that block (and to any children of
that block, not to any ancestors).

Again, if I haven't understood what you are describing, please write a
short example of two templates demonstrating what you are trying to
achieve.

Regards,
Malcolm



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



Re: Percentages in templates

2008-09-26 Thread Malcolm Tredinnick


On Wed, 2008-09-24 at 06:20 -0700, [EMAIL PROTECTED] wrote:
> I have an app that tracks football stats, I'd like to use bar graphs
> similar to what's on Everyblock. This is their code:
> 
> http://dpaste.com/80211/
> 
> I was curious, how, if possible at all, in the template I could get
> the percentage for the height.
> 
> So, for my first graph, so far I'd have these numbers:
> 
> 390
> 314
> 402
> 429
> 
> The 429 should be 100%, and then down from there 402 (94%), 390 (91%),
> 314 (73%), etc, etc.

Have a look at the "widthratio" template tag that comes with Django
(refer to the documentation for details). Despite the name, there's
nothing particularly width-only about it. It just generates a value,
which could just as easily put into a height style attribute.

Regards,
Malcolm



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



Form field rendering question--how to add css classes?

2008-09-26 Thread Chris Stromberger
I have a form field that will render as a drop-down in which I need to apply
a css class to each of the  tags within the .  A
complicating factor is that each of the 's will have a different css
class.  The Form class uses a ModelChoiceField to create the form field.
 Works great w/o needing any classes, just wondering if there is a way to
inject a class into each  tag.
Thanks,
Chris

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



Re: Apache with home directory Django

2008-09-26 Thread Graham Dumpleton



Erik Allik wrote:
> I don't think virtualenv will help you set up your project running
> with Apache. But it's a good practice nevertheless.

Yes virtualenv can be used to get it to work. The problem is that one
can't explain the way it would be used without the OP posting how the
hosting service has mod_python configured to allow him to run a Python
web application in the first place.

FWIW, any hosting service that offers shared hosting for different
users under the same Apache instance probably doesn't know what they
are doing and you'd probably want to avoid them. This is the case as
mod_python isn't safe to use for shared hosting for unrelated users
who you can't trust as neither running code nor writable areas of
filesystem are isolated from each other. Do you really want to trust
your application to a web hosting service that either doesn't realise
this or doesn't care enough to setup their systems so your application
is properly protected.

Graham

> If your hosting provider supports custom FastCGI handlers/processes,
> you could look into setting up Django with FastCGI. It's quite easy.
> Also if you don't have a way to set up FastCGI (or mod_wsgi or
> mod_python but I doubt your hosting provider lets you do that if
> they're not a Python hosting provider) but your hosting has a cgi-bin
> directory, you can use that to get up and running. It uses plain CGI
> which would be slow if your whole Django project code was to be loaded
> on each request, but there's a nifty little tool called cgi-fcgi which
> routes CGI requests so a persistent FastCGI process which it can spawn
> itself as needed. Just as with "true" FastCGI, this will enable you to
> set up a completely customized environment for your project.
>
> If you have SSH access to the hosting machine which you hopefully do,
> you should be able to compile anything you might need for the
> environment such as database drivers or PIL and any other extensions
> that require compilation.
>
> Regards,
> Erik Allik
>
> On 26.09.2008, at 1:39, Graham Dumpleton wrote:
>
> >
> > On Sep 26, 8:26 am, "Xian Chen" <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> I want to run my Django app on a shared web server.
> >>
> >> As so many people share this server, I install python and
> >> Django(1.0) under
> >> my home directory.
> >>
> >> How can I configure the Apache with mod_python to make the django
> >> under my
> >> directory running?
> >>
> >> The server administrator refused to install Django in the /usr/bin
> >> directory
> >
> > With mod_python you cannot make it use a different Python installation
> > than the one it was compiled with. The best you can manage is to use
> > virtualenv to build a Python virtual environment in your home
> > directory where you install all the Python modules/packages you want
> > and then refer to that.
> >
> >  http://pypi.python.org/pypi/virtualenv
> >
> > Only problem I see is that documentation for virtualenv seems to have
> > changed lately and no longer mentions the easy approach for using it
> > with mod_python. It has some new mechanism mentioned which I can't see
> > at the moment how it works.
> >
> > 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Matthew Crist

It was the quotes.

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



Re: Form controls for choosing from long lists

2008-09-26 Thread Diego Ucha

Donn,

You could use the filter_(horizontal|vertical) solution available on
Admin.
For more details: 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#filter-horizontal

[]s,
Diego Ucha
http://www.diegoucha.com/

On 26 set, 18:28, bruno desthuilliers <[EMAIL PROTECTED]>
wrote:
> On 26 sep, 19:12, Donn <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I thought I'd ask before rolling my own (at tedious pace) widget/whatever:
>
> > If you have a foreign key field to a table of thousands of, say, author 
> > names,
> > the drop-down control becomes a real problem:
> > 1. It's not paged so all the items have to be stuffed into the html.
> > 2. It's damn hard to use.
>
> > What are the alternatives? Any working solutions out there? How does one 
> > offer
> > a choice out of thousands?
>
> Most answers will require javascript. The 'simplest' one is to use a
> "popup" window in which you'll have paging, filtering etc. More
> complex (well... not necessarily more complex in fact) are ajax based
> - like, as David mentioned, an autocomplete combo. If you want to
> avoid javascript, you'll need to store the current form's state and
> whatnots (using session) and redirect to a page displaying possible
> choices with (just like with the popup solution) paging, filtering
> etc, and once choice made "return" to the form's page restoring saved
> state.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form controls for choosing from long lists

2008-09-26 Thread bruno desthuilliers

On 26 sep, 19:12, Donn <[EMAIL PROTECTED]> wrote:
> Hi,
> I thought I'd ask before rolling my own (at tedious pace) widget/whatever:
>
> If you have a foreign key field to a table of thousands of, say, author names,
> the drop-down control becomes a real problem:
> 1. It's not paged so all the items have to be stuffed into the html.
> 2. It's damn hard to use.
>
> What are the alternatives? Any working solutions out there? How does one offer
> a choice out of thousands?

Most answers will require javascript. The 'simplest' one is to use a
"popup" window in which you'll have paging, filtering etc. More
complex (well... not necessarily more complex in fact) are ajax based
- like, as David mentioned, an autocomplete combo. If you want to
avoid javascript, you'll need to store the current form's state and
whatnots (using session) and redirect to a page displaying possible
choices with (just like with the popup solution) paging, filtering
etc, and once choice made "return" to the form's page restoring saved
state.


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



Re: Passing object to another server and back again.

2008-09-26 Thread bruno desthuilliers



On 26 sep, 22:03, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> My online store keeps everything in a cart. When someone makes an
> order, it sends the order to the bank's server for payment processing
> then sends them back -- similar to paypal.
>
> What I'm trying to do is pass their cart, complete with everything in
> it, over to the bank and back again.

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



Incorrect cache headers

2008-09-26 Thread Jeff

I have an application that is getting incorrect cache headers set,
including pragma "no-cache".  It is running via mod_apache without
mod_expires or mod_cache.

I am setting the upstream cache headers in the view with the
cache_control decorator, which should override anything set by the
framework.  I am incidentally using cache_page on this view as well.
I don't have CACHE_ANONYMOUS_ONLY on, so it should not be that,
either.  From the development server I am getting the correct headers,
but I don't see anything relevant in my apache configs.

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



Re: recommended method for administrative scripts?

2008-09-26 Thread Brian Neal

On Sep 26, 2:50 pm, ssam <[EMAIL PROTECTED]> wrote:
> Hello
>
> I have just made my first django site for my uncles wedding photos. It
> is very simple, just photos and tags, with a ManyToMany relationship.
> I have only made views for viewing the photos and am using the django
> admin system for uploading and tagging.
>
> I am wondering what is the best way to add scripts to do
> administrative tasks, that dont need to be triggerable by a URL.
>
> For example, a decided that the settings i had used to make the
> thumbnails where to low, and wanted to rerun the thumbnailing on each
> photo. I did this by making a function in views.py that did the
> looping through and resizing. Then adding a URL, and visiting it.
>
> This seemed like a rather kludgy method.
>
> I have a few other tasks that i might want to do. extract the date
> from the photos EXIF data, and put it in a field in the database (i
> already have the field).
>
> also i think i could save some time if it could scp a bunch of photos
> to a folder on my server, and add them into the database with a single
> command.
>
> So is there a recommended method of doing this soft of thing?
>
> Thanks
>
> Sam

Check out the django Photologue application. It's really slick. You
can upload through the admin interface a zip file of photos and it
will create a gallery for you from that. It also automatically resizes
photos according to a set of sizes you specify, and creates them only
on demand.

As for your question about how to make your own admin apps, check out
the online Django book, which has a chapter on how to do that
(suprisingly this isn't really covered in the online Django docs).

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



Passing object to another server and back again.

2008-09-26 Thread [EMAIL PROTECTED]

My online store keeps everything in a cart. When someone makes an
order, it sends the order to the bank's server for payment processing
then sends them back -- similar to paypal.

What I'm trying to do is pass their cart, complete with everything in
it, over to the bank and back again. This is where I'm running into a
problem.

So far, the closest I've come is pickling it, passing it in a hidden
field, then unpickling it when it comes back:

picklecart = cPickle.dumps(cart.items())
fields +=   '\n' %
(picklecart)

then, at the other end:
cart = cPickle.loads(str(page_data['picklecart']))

Problem is, that throws an ImportError (No module named cart_manager)
cart_manager.py holds the Cart classes. Directory structure is
store/cart_manager
store/models
store/urls
store/views

I know it's there, but it's not finding it when this all comes back.

So, any ideas on how to make this work? Something I'm missing?


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



Re: recommended method for administrative scripts?

2008-09-26 Thread Erik Allik

With sorl.thumbnail you don't have to do that at all. It allows you to  
specify resize size on the fly, then caches the resulting image and  
always recreates the image if the size changes automatically.

Erik

On 26.09.2008, at 22:50, ssam wrote:

>
> Hello
>
> I have just made my first django site for my uncles wedding photos. It
> is very simple, just photos and tags, with a ManyToMany relationship.
> I have only made views for viewing the photos and am using the django
> admin system for uploading and tagging.
>
> I am wondering what is the best way to add scripts to do
> administrative tasks, that dont need to be triggerable by a URL.
>
> For example, a decided that the settings i had used to make the
> thumbnails where to low, and wanted to rerun the thumbnailing on each
> photo. I did this by making a function in views.py that did the
> looping through and resizing. Then adding a URL, and visiting it.
>
> This seemed like a rather kludgy method.
>
> I have a few other tasks that i might want to do. extract the date
> from the photos EXIF data, and put it in a field in the database (i
> already have the field).
>
> also i think i could save some time if it could scp a bunch of photos
> to a folder on my server, and add them into the database with a single
> command.
>
> So is there a recommended method of doing this soft of thing?
>
> Thanks
>
> Sam
> >


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



Re: Can I create unique instances of a model to live under another model?

2008-09-26 Thread bruno desthuilliers

On 26 sep, 21:10, Robert <[EMAIL PROTECTED]> wrote:

(snip)

> > On Sep 26, 1:39 pm, Rock <[EMAIL PROTECTED]> wrote:
>
> > > It may be as simple as creating an intermediary field between Document
> > > and agency called Study. (See the Django docs regarding adding extra
> > > fields to a many-to-many relationship.)

> I freely admit my biggest problem is that I am quite used to thinking
> in terms of classes, and almost not at all in terms of database
> schema.

"the results of an higher education..." (F.Zappa)

Not to start a troll, but when it comes to domain modeling, OO is IMHO
a regression wrt/ the relational model - even if SQL dbms are pretty
bad when it comes to graphs and/or polymorphic relationships.

Anyway... back to your problem:

required_docs = []

for country in study.countries:
for agency in country.agencies:
for document in agency.documents:
required_docs.append(document)

I derive from this that the required set of documents for a given
agency doesn't depend on the study ? If so, what's the meaning of "a
document is created for that study" and "the same document created for
a different study" ?

FWIW, I suspect there's something wrong in the definition of
"document" (FWIW, you didn't defined what a "document" is at all).

If you're more at ease with OO modeling (and then UML), could you post
an UML class diagram of your domain somewhere ?


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



Re: Apache with home directory Django

2008-09-26 Thread James Matthews
Yes i am using FastCgi

On Fri, Sep 26, 2008 at 12:46 PM, Erik Allik <[EMAIL PROTECTED]> wrote:

> As stated before, by changing the PYTHONPATH, you it is NOT possible to
> change the python interpreter when using mod_python. Certainly you can load
> your own libraries, but the python itself remains the same.
> Erik
>
> On 26.09.2008, at 22:07, James Matthews wrote:
>
> I run my own installation of python out of my home dir. It's not hard...
> All you need to do is to compile your own version of python (or use your
> hosts mine was 2.3 so i got 2.5.1) and change your PATH. Everything should
> work from there.
> James
>
> On Fri, Sep 26, 2008 at 6:01 AM, Erik Allik <[EMAIL PROTECTED]> wrote:
>
>>
>> I don't think virtualenv will help you set up your project running
>> with Apache. But it's a good practice nevertheless.
>>
>> If your hosting provider supports custom FastCGI handlers/processes,
>> you could look into setting up Django with FastCGI. It's quite easy.
>> Also if you don't have a way to set up FastCGI (or mod_wsgi or
>> mod_python but I doubt your hosting provider lets you do that if
>> they're not a Python hosting provider) but your hosting has a cgi-bin
>> directory, you can use that to get up and running. It uses plain CGI
>> which would be slow if your whole Django project code was to be loaded
>> on each request, but there's a nifty little tool called cgi-fcgi which
>> routes CGI requests so a persistent FastCGI process which it can spawn
>> itself as needed. Just as with "true" FastCGI, this will enable you to
>> set up a completely customized environment for your project.
>>
>> If you have SSH access to the hosting machine which you hopefully do,
>> you should be able to compile anything you might need for the
>> environment such as database drivers or PIL and any other extensions
>> that require compilation.
>>
>> Regards,
>> Erik Allik
>>
>> On 26.09.2008, at 1:39, Graham Dumpleton wrote:
>>
>> >
>> > On Sep 26, 8:26 am, "Xian Chen" <[EMAIL PROTECTED]> wrote:
>> >> Hi,
>> >>
>> >> I want to run my Django app on a shared web server.
>> >>
>> >> As so many people share this server, I install python and
>> >> Django(1.0) under
>> >> my home directory.
>> >>
>> >> How can I configure the Apache with mod_python to make the django
>> >> under my
>> >> directory running?
>> >>
>> >> The server administrator refused to install Django in the /usr/bin
>> >> directory
>> >
>> > With mod_python you cannot make it use a different Python installation
>> > than the one it was compiled with. The best you can manage is to use
>> > virtualenv to build a Python virtual environment in your home
>> > directory where you install all the Python modules/packages you want
>> > and then refer to that.
>> >
>> >  http://pypi.python.org/pypi/virtualenv
>> >
>> > Only problem I see is that documentation for virtualenv seems to have
>> > changed lately and no longer mentions the easy approach for using it
>> > with mod_python. It has some new mechanism mentioned which I can't see
>> > at the moment how it works.
>> >
>> > Graham
>> > >
>>
>>
>>
>>
>
>
> --
> http://www.goldwatches.com/
>
>
>
>
>
> >
>


-- 
http://www.goldwatches.com/

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



Re: Apache with home directory Django

2008-09-26 Thread Erik Allik
As stated before, by changing the PYTHONPATH, you it is NOT possible  
to change the python interpreter when using mod_python. Certainly you  
can load your own libraries, but the python itself remains the same.

Erik

On 26.09.2008, at 22:07, James Matthews wrote:

> I run my own installation of python out of my home dir. It's not  
> hard... All you need to do is to compile your own version of python  
> (or use your hosts mine was 2.3 so i got 2.5.1) and change your  
> PATH. Everything should work from there.
>
> James
>
> On Fri, Sep 26, 2008 at 6:01 AM, Erik Allik <[EMAIL PROTECTED]> wrote:
>
> I don't think virtualenv will help you set up your project running
> with Apache. But it's a good practice nevertheless.
>
> If your hosting provider supports custom FastCGI handlers/processes,
> you could look into setting up Django with FastCGI. It's quite easy.
> Also if you don't have a way to set up FastCGI (or mod_wsgi or
> mod_python but I doubt your hosting provider lets you do that if
> they're not a Python hosting provider) but your hosting has a cgi-bin
> directory, you can use that to get up and running. It uses plain CGI
> which would be slow if your whole Django project code was to be loaded
> on each request, but there's a nifty little tool called cgi-fcgi which
> routes CGI requests so a persistent FastCGI process which it can spawn
> itself as needed. Just as with "true" FastCGI, this will enable you to
> set up a completely customized environment for your project.
>
> If you have SSH access to the hosting machine which you hopefully do,
> you should be able to compile anything you might need for the
> environment such as database drivers or PIL and any other extensions
> that require compilation.
>
> Regards,
> Erik Allik
>
> On 26.09.2008, at 1:39, Graham Dumpleton wrote:
>
> >
> > On Sep 26, 8:26 am, "Xian Chen" <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> I want to run my Django app on a shared web server.
> >>
> >> As so many people share this server, I install python and
> >> Django(1.0) under
> >> my home directory.
> >>
> >> How can I configure the Apache with mod_python to make the django
> >> under my
> >> directory running?
> >>
> >> The server administrator refused to install Django in the /usr/bin
> >> directory
> >
> > With mod_python you cannot make it use a different Python  
> installation
> > than the one it was compiled with. The best you can manage is to use
> > virtualenv to build a Python virtual environment in your home
> > directory where you install all the Python modules/packages you want
> > and then refer to that.
> >
> >  http://pypi.python.org/pypi/virtualenv
> >
> > Only problem I see is that documentation for virtualenv seems to  
> have
> > changed lately and no longer mentions the easy approach for using it
> > with mod_python. It has some new mechanism mentioned which I can't  
> see
> > at the moment how it works.
> >
> > Graham
> > >
>
>
>
>
>
>
> -- 
> http://www.goldwatches.com/
>
> >


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



recommended method for administrative scripts?

2008-09-26 Thread ssam

Hello

I have just made my first django site for my uncles wedding photos. It
is very simple, just photos and tags, with a ManyToMany relationship.
I have only made views for viewing the photos and am using the django
admin system for uploading and tagging.

I am wondering what is the best way to add scripts to do
administrative tasks, that dont need to be triggerable by a URL.

For example, a decided that the settings i had used to make the
thumbnails where to low, and wanted to rerun the thumbnailing on each
photo. I did this by making a function in views.py that did the
looping through and resizing. Then adding a URL, and visiting it.

This seemed like a rather kludgy method.

I have a few other tasks that i might want to do. extract the date
from the photos EXIF data, and put it in a field in the database (i
already have the field).

also i think i could save some time if it could scp a bunch of photos
to a folder on my server, and add them into the database with a single
command.

So is there a recommended method of doing this soft of thing?

Thanks

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



Re: Form controls for choosing from long lists

2008-09-26 Thread David Durham, Jr.

On Fri, Sep 26, 2008 at 12:12 PM, Donn <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I thought I'd ask before rolling my own (at tedious pace) widget/whatever:
>
> If you have a foreign key field to a table of thousands of, say, author names,
> the drop-down control becomes a real problem:
> 1. It's not paged so all the items have to be stuffed into the html.
> 2. It's damn hard to use.
>
> What are the alternatives? Any working solutions out there? How does one offer
> a choice out of thousands?

You could use something like an auto completing combo box.  I don't
have any examples of how this is done with Django.

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



admin.site.register breaks unittests

2008-09-26 Thread Gerard Petersen

Hi all,

When I run my test suite, commands like these 'admin.site.register(Product, 
ProductAdmin)' in models.py break my tests with this error:

django.contrib.admin.sites.AlreadyRegistered: The model Product is already 
registered

When I (temporarily) remove them the tests run properly.

What am I misssing?

Thanx!

Gerard.
-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


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



Re: importing models from other apps

2008-09-26 Thread Efrain Valles

Gee, sorry about my bad wording of the problem, I think I tried
importing the models from a different application, however when I try
to do the variable asignment to a ForeignKey Model it does not take
the Model.


I import the models:

import rocola_erp.fact_rocola.models

I create the class with the variable impuesto making reference to a
model that is in the fact_rocola app

class producto (models.Model):
idprod = models.AutoField(primary_key=True)
nombre = models.CharField(max_length = 30,
verbose_name="Nombre de producto")
marca = models.ForeignKey(marca)
categoria = models.ForeignKey(categoria)
descripcion = models.CharField(max_length=250)
existencia = models.DecimalField(max_digits=19, decimal_places=2)
cantidad_maxima = models.DecimalField(max_digits=19, decimal_places=0)
cantidad_minima = models.DecimalField(max_digits=19, decimal_places=0)
codigo = models.CharField(max_length=30)
precio_minimo = models.DecimalField(max_digits=19, decimal_places=2)
precio_descuento = models.DecimalField(max_digits=19, decimal_places=2)
precio_normal = models.DecimalField(max_digits=19, decimal_places=2)
impuesto = models.ForeignKey(rocola_erp.fact_rocola.models.Impuesto)
imagenproduco = models.ImageField(upload_to='imagenes/',
verbose_name="Imagen de producto")
def __unicode__(self):
return self.nombre
class Admin:
pass


[EMAIL PROTECTED]:~/workspace/urbe_rocola/rocola_erp$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 340, in execute_manager
utility.execute()
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 77, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 95, in execute
self.validate()
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 122, in validate
num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.5/site-packages/django/core/management/validation.py",
line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 128, in get_app_errors
self._populate()
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 57, in _populate
self.load_app(app_name, True)
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py",
line 72, in load_app
mod = __import__(app_name, {}, {}, ['models'])
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/fact_rocola/models.py",
line 3, in 
from rocola_erp.inventario.models import producto
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/inventario/models.py",
line 21, in 
class producto (models.Model):
  File 
"/home/evalles/workspace/urbe_rocola/rocola_erp/../rocola_erp/inventario/models.py",
line 34, in producto
impuesto = models.ForeignKey(rocola_erp.fact_rocola.models.Impuesto)
AttributeError: 'module' object has no attribute 'models'




On Sat, Sep 27, 2008 at 1:02 PM, bruno desthuilliers
<[EMAIL PROTECTED]> wrote:
>
> On 26 sep, 17:53, "Efrain Valles" <[EMAIL PROTECTED]> wrote:
>> I have been trying to reference a model from another application I
>> wrote for the same project.  basically what I need to do is asign a
>> relationship between two model classes  in different apps.
>>
>> example
>>
>> module Product has a model class that belongs to the inventory app and
>> the tax field of Product should use the tax module from the Billing
>> app.
>>
>> I tried a simple import
>>
>> from myproject.app1.models import tax
>
> You'd better use:
>
> from app1.models import Tax
>
> hints :
> - use CamelCase for classes
> - if app1 is in the same project, then you don't need to reference
> your project package
> - else, you'll have to add app1 to your pythonpath anyway
> - in both cases, you don't want to mention the project package itself
> - else it will break if you rename the 'myproject' directory, or try
> to reuse both apps in another project.
>
> Reading Python's FineManual(tm), specially the section about modules,
> packages and imports (in the tutorial) might be a good idea.
>
>> and then I:
>>
>> tax = models.ManyToManyField(tax)
>
> The results of this statement is that the name 'tax' is rebound to the
> models.ManyToManyField, sus shadowing the binding to the imported
> 'tax' class in the current class namespace. This may (or not) be the
> cause of your problem.
>
> You may want to search comp.lang.python's archive for posts about 

Re: Duplicate files being created on ImageField.save

2008-09-26 Thread ssam

David Christiansen wrote:
> The idea is that image_scaled has a version that is a thumbnail of the
> originally updated photo.  I've removed that code for testing
> purposes, and this still happens.  What happens is that two images are
> created in content_images/page/PAGE_ID/scaled/, one with an underscore
> after the name.  image_scaled.path shows that the version with the
> extra underscore is the current one referred to after running this.
>
> This behavior happens on both Windows and Linux servers.  I'm running
> Django 1.0.  As far as I can tell, I'm using the FileField API
> correctly.  Is there something obvious that I'm missing?
>
> Thanks in advance!

I had a similar issue.

The fix i have found on the web is to wrap your action in an if
statement to make sure you only do it once

Something like

  def save(self):
 if not image_scaled:
scaled_name = os.path.split(self.image_original.name)[-1]
self.image_scaled.save(scaled_name, self.image_original,
save=False)
 super(Page, self).save()

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



Re: A question about spaces and passing variables...

2008-09-26 Thread djandrow

Thanks Karen, its working fine now,
Brian, I will have a look at slug fields, for now i'm trying just to
get a basic site going, but then I'm going to try and come back and
improve things so i will take a look at then then.

Regards,

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



Re: Can I create unique instances of a model to live under another model?

2008-09-26 Thread Robert

I freely admit my biggest problem is that I am quite used to thinking
in terms of classes, and almost not at all in terms of database
schema.  I'll check into that reading you recommended.

Kind regards,
Robert

On Sep 26, 12:42 pm, Rock <[EMAIL PROTECTED]> wrote:
> Oops. I meant intermediary class, not intermediary field.
>
> On Sep 26, 1:39 pm, Rock <[EMAIL PROTECTED]> wrote:
>
> > It may be as simple as creating an intermediary field between Document
> > and agency called Study. (See the Django docs regarding adding extra
> > fields to a many-to-many relationship.)
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Apache with home directory Django

2008-09-26 Thread James Matthews
I run my own installation of python out of my home dir. It's not hard... All
you need to do is to compile your own version of python (or use your hosts
mine was 2.3 so i got 2.5.1) and change your PATH. Everything should work
from there.
James

On Fri, Sep 26, 2008 at 6:01 AM, Erik Allik <[EMAIL PROTECTED]> wrote:

>
> I don't think virtualenv will help you set up your project running
> with Apache. But it's a good practice nevertheless.
>
> If your hosting provider supports custom FastCGI handlers/processes,
> you could look into setting up Django with FastCGI. It's quite easy.
> Also if you don't have a way to set up FastCGI (or mod_wsgi or
> mod_python but I doubt your hosting provider lets you do that if
> they're not a Python hosting provider) but your hosting has a cgi-bin
> directory, you can use that to get up and running. It uses plain CGI
> which would be slow if your whole Django project code was to be loaded
> on each request, but there's a nifty little tool called cgi-fcgi which
> routes CGI requests so a persistent FastCGI process which it can spawn
> itself as needed. Just as with "true" FastCGI, this will enable you to
> set up a completely customized environment for your project.
>
> If you have SSH access to the hosting machine which you hopefully do,
> you should be able to compile anything you might need for the
> environment such as database drivers or PIL and any other extensions
> that require compilation.
>
> Regards,
> Erik Allik
>
> On 26.09.2008, at 1:39, Graham Dumpleton wrote:
>
> >
> > On Sep 26, 8:26 am, "Xian Chen" <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> I want to run my Django app on a shared web server.
> >>
> >> As so many people share this server, I install python and
> >> Django(1.0) under
> >> my home directory.
> >>
> >> How can I configure the Apache with mod_python to make the django
> >> under my
> >> directory running?
> >>
> >> The server administrator refused to install Django in the /usr/bin
> >> directory
> >
> > With mod_python you cannot make it use a different Python installation
> > than the one it was compiled with. The best you can manage is to use
> > virtualenv to build a Python virtual environment in your home
> > directory where you install all the Python modules/packages you want
> > and then refer to that.
> >
> >  http://pypi.python.org/pypi/virtualenv
> >
> > Only problem I see is that documentation for virtualenv seems to have
> > changed lately and no longer mentions the easy approach for using it
> > with mod_python. It has some new mechanism mentioned which I can't see
> > at the moment how it works.
> >
> > Graham
> > >
>
>
> >
>


-- 
http://www.goldwatches.com/

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



Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Rock


Hmmm... Here are some guesses:

If that return statement in render is a single doublequote instead of
2 singlequotes, then your code probably won't parse and, even if it
does,  get_latest certainly won't be found.

It seems to me like you need to coerce the string being assigned to
self.num as make it an int. (Better yet, put that logic in the parse
section.) However that is unlikely to be the cause of the error that
you are seeing.

You might want to try compiling the code by hand to make sure there
are no stray typos.


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



Re: Can I create unique instances of a model to live under another model?

2008-09-26 Thread Rock

Oops. I meant intermediary class, not intermediary field.

On Sep 26, 1:39 pm, Rock <[EMAIL PROTECTED]> wrote:
> It may be as simple as creating an intermediary field between Document
> and agency called Study. (See the Django docs regarding adding extra
> fields to a many-to-many relationship.)
>

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



Re: Can I create unique instances of a model to live under another model?

2008-09-26 Thread Rock


It may be as simple as creating an intermediary field between Document
and agency called Study. (See the Django docs regarding adding extra
fields to a many-to-many relationship.)

In any event, it is wise not to think of models as objects so much as
stand-ins for DB tables (which is what they are.) So this should be
treated like a schema design problem, not an OO design problem. (Yes I
know models can be inherited abstractly and concretely and I take
advantage of that in my own code, but that can gt you into trouble if
you aren't clear of the limitations that inheriting models imposes.)

If you are unclear on the difference between database schema design
and OO design, then you might want to consider procuring a consultant
to review your schema design in light of your complete set of project
requirements at some time point early in the design process. That
might save you a ton of time and money in the long run.

Rock

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



Printing a specific form within a formset in a template file

2008-09-26 Thread SnappyDjangoUser

Hi Folks-

Is it possible to access a specific form (i.e. form 1 of n) within a
formset and print that form within a template file?  All the examples
on the Django documentation page show accessing formset forms via a
forloop and I have not been able to find my answer within the docs.

For example, I want to do something like this to access form 1 of n:
>>> formset = MyFormSet()
>>> print formset.forms[1]

This does not seem to work for me, however.

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



Re: Converting .96 to 1.0 How to admin models?

2008-09-26 Thread Lance F. Squire



On Sep 26, 1:53 pm, bruno desthuilliers
<[EMAIL PROTECTED]> wrote:
>
> # relative import is simpler and safer
> import models
>
> # using introspection
> from django.db.models import Model
> for name in dir(models):
> obj = getattr(models, name)
> if obj is not Model and issubclass(obj, Model):
>try:
> admin.site.register(obj)
>except AlreadyRegistred:
>  # XXX : not sure about this is the exact exception type,
>  # but you should be able to find this out easily
>  pass
>

Got this error trying that...

issubclass() arg 1 must be a class

> > b.t.w. I presume the
>
> > class Admin:
> > pass
>
> > in the Models.py is useless now...
>
> Definitevely. And that's a GoodThing(tm), since it has nothing to do
> in the models.

I can understand why, but is seems like we've made more work from
something that was simple.

Though I suspect the admin.py can now do way more to modify the admin
than previously.

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



Can I create unique instances of a model to live under another model?

2008-09-26 Thread Robert

Hi everyone.  I'm quite new to Django and have been using the web
tutorials as well as the two Django books extensively.  If have tried
searching for a solution to my problem, but in truth, I barely know
how to ask, so I'll explain the scenario as briefly as possible.

I'm building a document tracker for a global, highly-regulated
industry.  Here are my models (briefly summarized).

Study - Each study takes place in many different countries, each with
their own requirements.  Countries will be added to the study via a
ManyToMany relationship.

Country - Each country has several Agencies that must grant approval.
These agencies are unique to a country (no agency operates in two
countries).  Agencies are added with a ForeignKey relationship.

Agency - Each agency requires a specific set of documents in order to
grant approval.  The documents may or may not be unique (it is
possible for two countries to require the same document).  Documents
are added to this model with a ManyToMany relationship.

Document - Each possible document is listed in this model.  Agencies
select their documents from this list, and cannot require documents
not in this list.

That's all well and good, but my problem it this: Because each study
takes place in different countries, different agencies must be applied
to which require different documents, and therefore each study will
have its own unique set of documents that must be tracked.  I need to
somehow create a unique set of documents that is shared amongst the
countries and agencies of that study ('shared' meaning that if a
document is created for that study, it is available to all agencies
for that study, but only for that study.  The same document created
for a different study would not be connected to this document).  This
set must have the ability to be altered and tracked without affecting
the master list of documents and that is unique to this study.

If I were writing my own code and using objects instead of models, it
would look like this:

required_docs = []

for country in study.countries:
for agency in country.agencies:
for document in agency.documents:
required_docs.append(document)

Each study would then have a required_docs which could be adjusted
independently of all other studies.  But I don't know how that would
look in Django!  :)

I'm pretty good at learning stuff on my own, so if anyone could even
point me in the right direction, I would appreciate it.  Maybe this is
a common problem, I don't now, but I'm stumped.

Thanks in advance.
Robert

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



Re: Converting .96 to 1.0 How to admin models?

2008-09-26 Thread bruno desthuilliers

On 26 sep, 18:07, "Lance F. Squire" <[EMAIL PROTECTED]> wrote:
> Converting a .96 site I was working on to the 1.0 set-up.
>
> Is there a quick way to list all my models in the admin?
>
> Or do I have to :
>
> from HCVGM.systems.models import System
>
> admin.site.register(System)
>
> for every one?

# relative import is simpler and safer
import models

# using introspection
from django.db.models import Model
for name in dir(models):
obj = getattr(models, name)
if obj is not Model and issubclass(obj, Model):
   try:
admin.site.register(obj)
   except AlreadyRegistred:
 # XXX : not sure about this is the exact exception type,
 # but you should be able to find this out easily
 pass


> b.t.w. I presume the
>
> class Admin:
> pass
>
> in the Models.py is useless now...

Definitevely. And that's a GoodThing(tm), since it has nothing to do
in the models.

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



Re: get_template problem

2008-09-26 Thread Håkan Waara

from django.template.loader import get_template

I recommend learning some general python before you dive into django.  
There are lots of great sites for this, for example www.diveintopython.org

/H

26 sep 2008 kl. 15.44 skrev NoviceSortOf:

>
>
> this works
>
 from django.template import loader
 loader.get_template('myfile.html')
>
> but how do i get this syntax to work?
>
 get_template('myfile.html')
>
> >


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



AdminDateWidget outside admin

2008-09-26 Thread Thomas Guettler

Hi,

I try to use AdminDateWidget outside of the admin page, like documented:
http://docs.djangoproject.com/en/dev/topics/forms/media/

form.media returns:



But still some files are missing: jsi18n and core.js:



Now the widget is usable, but looks ugly. Some css files are missing

After adding widgets.css it works.

Is this a bug or an undocumented feature?

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: How to get unique names for items in admin site

2008-09-26 Thread bruno desthuilliers



On 26 sep, 18:19, gv <[EMAIL PROTECTED]> wrote:
> Oops - I just saw the relevant bit in the tutorial, so it is done like
> this:
>
> class Server(models.Model):
> def __unicode__(self):
> return self.question

The answer is 42 !-)


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



Re: importing models from other apps

2008-09-26 Thread bruno desthuilliers

On 26 sep, 17:53, "Efrain Valles" <[EMAIL PROTECTED]> wrote:
> I have been trying to reference a model from another application I
> wrote for the same project.  basically what I need to do is asign a
> relationship between two model classes  in different apps.
>
> example
>
> module Product has a model class that belongs to the inventory app and
> the tax field of Product should use the tax module from the Billing
> app.
>
> I tried a simple import
>
> from myproject.app1.models import tax

You'd better use:

from app1.models import Tax

hints :
- use CamelCase for classes
- if app1 is in the same project, then you don't need to reference
your project package
- else, you'll have to add app1 to your pythonpath anyway
- in both cases, you don't want to mention the project package itself
- else it will break if you rename the 'myproject' directory, or try
to reuse both apps in another project.

Reading Python's FineManual(tm), specially the section about modules,
packages and imports (in the tutorial) might be a good idea.

> and then I:
>
> tax = models.ManyToManyField(tax)

The results of this statement is that the name 'tax' is rebound to the
models.ManyToManyField, sus shadowing the binding to the imported
'tax' class in the current class namespace. This may (or not) be the
cause of your problem.

You may want to search comp.lang.python's archive for posts about name
bindings and namespaces in Python.

> but it does nto work

I can only second Steve's remark on this : "does not work" is almost
the worst possible description of a problem.  The useful thing to do
is to:

1/ post minimal working code exhibiting the problem.
2/ explain clearly what you expected
3/ explain clearly what you got instead. If an exception is raised,
please post the *whole* traceback.


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



Re: actual django stack

2008-09-26 Thread David Zhou


On Sep 26, 2008, at 5:54 AM, Peter Bengtsson wrote:

> On Sep 25, 8:41 pm, "Frédéric Sidler" <[EMAIL PROTECTED]>
> wrote:
>> What it the best Django stack today.
>>
>> In django doc, it says that apache with mod_python is the best
>> solution in production. But in the same time I see that everyblock  
>> use
>> nginx (probably in mode fastcgi).
>>
>> Did you some of you test different solution and can share some  
>> output here.
>>
>> Here are the ones I see actually
>>
>> Apache mod_python
>> Apache in fastcgi mode
>> Lighttpd in fastcgi mode
>> Nginx in fastcgi mode
>>
>
> I've noticed a small performance boost from using Nginx + fcgi
> compared to Apache + mod_python and I hear that Nginx is also a better
> performer on the static content but haven't personally experienced
> that but the blogosphere will probably agree that Nginx is faster.
> The benefit to us with Apache is that we have more knowledge about it
> within the team but this only matters when you do more complicated
> stuff such as advanced authentication stuff or additional security
> hardening. This will probably be the case for many teams since Nginx
> is so new.

I've also heard good things about WSGI -- though I haven't heavily  
tested its stability compared to, say, mod_python.
---
David Zhou
[EMAIL PROTECTED]





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



Re: How to get unique names for items in admin site

2008-09-26 Thread Erik Allik

You might want to remove the id field as it's not needed. You also  
might consider converting siteid and authid to ForeignKey fields to  
the Model that corresponds to the table that these fkeys are  
referencing. So if you have Auth and Site models, you could do:

site = models.ForeignKey(Site, null=True, blank=True, dbcolumn='siteid')
auth = models.ForeignKey(Auth, null=True, blank=True, dbcolumn='authid')

Also maybe:
server_name = models.CharField(max_length=192, dbcolumn='servername')
domain_name = models.CharField(max_length=96, blank=True,  
dbcolumn='domainname')
backed_up_to = models.CharField(max_length=192, blank=True,  
dbcolumn='backedupto')

for better readability of the code.

And there is a IPAddressField, too, if you're interested.

Erik

On 26.09.2008, at 19:12, gv wrote:

>
> Hello
>
> I'm making a small app that holds data of servers in our organisation
> (the database existed previously, and I've created the models.py using
> the inspectdb as described in:
> http://docs.djangoproject.com/en/dev/howto/legacy-databases/  )
>
> The admin site works OK, but each server is displayed as "Server
> object".  I would like the admin site to display each item under its
> servername.  How can I do that?
>
> part of the models.py:
> class Server(models.Model):
>id = models.IntegerField(primary_key=True)
>servername = models.CharField(max_length=192)
>ip = models.CharField(max_length=48)
>domainname = models.CharField(max_length=96, blank=True)
>os = models.CharField(max_length=96, blank=True)
>drives = models.CharField(max_length=24, blank=True)
>backedupto = models.CharField(max_length=192, blank=True)
>purpose = models.CharField(max_length=384, blank=True)
>comment = models.CharField(max_length=768, blank=True)
>siteid = models.IntegerField(null=True, blank=True)
>authid = models.IntegerField(null=True, blank=True)
>class Meta:
>db_table = u'server'
>
>
>
>
> >


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



Form controls for choosing from long lists

2008-09-26 Thread Donn

Hi,
I thought I'd ask before rolling my own (at tedious pace) widget/whatever:

If you have a foreign key field to a table of thousands of, say, author names, 
the drop-down control becomes a real problem:
1. It's not paged so all the items have to be stuffed into the html.
2. It's damn hard to use.

What are the alternatives? Any working solutions out there? How does one offer 
a choice out of thousands?

\d

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



How do I make a Form -> Email safe and without escaped chars.

2008-09-26 Thread 7timesTom

I have a public form that's used to email details of stuff on my site
to an email address.

Here is a snippet of the email received:

Fred says:
**
Hi, I thought youd like this.
**

How do I prevent escaped chars like this while not endangering
recipients to any form of javascript or other attack?

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



Re: importing models from other apps

2008-09-26 Thread Steve Holden

Efrain Valles wrote:
> I have been trying to reference a model from another application I
> wrote for the same project.  basically what I need to do is asign a
> relationship between two model classes  in different apps.
>
> example
>
> module Product has a model class that belongs to the inventory app and
> the tax field of Product should use the tax module from the Billing
> app.
>
> I tried a simple import
>
> from myproject.app1.models import tax
>
> and then I:
>
> tax = models.ManyToManyField(tax)
>
> but it does nto work and I seem to be referencing it the wrong way.
>
> Any help appreciated.
>
>   
First piece of help: "it does not work" is a poor description of your
problem. We need a little more information to deduce what the problem
might actually be.

It might be easier to read the code if you had used

import myproject.app1.models


class Goods(models.Model):
tax = models.ManyToManyField(myproject.app1.models.tax)

That only affects readability, however. Since your assignment statement
has no indentation I find myself wondering if you are trying to declare
the ManyToMany outside a class? If so, that will be the problem> a
ManyToMany should be a field of one of the related classes.

If my psychic powers have failed me then please reply with more
information about the nature of the failure.

regards
 Steve


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



Re: How to get unique names for items in admin site

2008-09-26 Thread gv

Oops - I just saw the relevant bit in the tutorial, so it is done like
this:

class Server(models.Model):
def __unicode__(self):
return self.question

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



How to get unique names for items in admin site

2008-09-26 Thread gv

Hello

I'm making a small app that holds data of servers in our organisation
(the database existed previously, and I've created the models.py using
the inspectdb as described in:
http://docs.djangoproject.com/en/dev/howto/legacy-databases/  )

The admin site works OK, but each server is displayed as "Server
object".  I would like the admin site to display each item under its
servername.  How can I do that?

part of the models.py:
class Server(models.Model):
id = models.IntegerField(primary_key=True)
servername = models.CharField(max_length=192)
ip = models.CharField(max_length=48)
domainname = models.CharField(max_length=96, blank=True)
os = models.CharField(max_length=96, blank=True)
drives = models.CharField(max_length=24, blank=True)
backedupto = models.CharField(max_length=192, blank=True)
purpose = models.CharField(max_length=384, blank=True)
comment = models.CharField(max_length=768, blank=True)
siteid = models.IntegerField(null=True, blank=True)
authid = models.IntegerField(null=True, blank=True)
class Meta:
db_table = u'server'




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



Converting .96 to 1.0 How to admin models?

2008-09-26 Thread Lance F. Squire

Converting a .96 site I was working on to the 1.0 set-up.

Is there a quick way to list all my models in the admin?

Or do I have to :

from HCVGM.systems.models import System

admin.site.register(System)

for every one?

b.t.w. I presume the

class Admin:
pass

in the Models.py is useless now...

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



How can I filter the items of a many to many relationship in the admin interface?

2008-09-26 Thread Ottavio Campana

I have a last problem before finishing my first django application.

I have a many to many relationship that connects two models.
Everything is fine in the admin, with the exception that I would like
to filter the shown items in the corrponding widget.

I tried by overwriting queryset, but it doesn't even seem to be
called. Which function is called to fill the list?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



importing models from other apps

2008-09-26 Thread Efrain Valles

I have been trying to reference a model from another application I
wrote for the same project.  basically what I need to do is asign a
relationship between two model classes  in different apps.

example

module Product has a model class that belongs to the inventory app and
the tax field of Product should use the tax module from the Billing
app.

I tried a simple import

from myproject.app1.models import tax

and then I:

tax = models.ManyToManyField(tax)

but it does nto work and I seem to be referencing it the wrong way.

Any help appreciated.

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



Re: Update: Date formatting between model and form output

2008-09-26 Thread Gerard Petersen

Found an error in the model code. It should be this:

if isinstance(self.period_start_date, datetime): 

Regards,

Gerard,

koenb wrote:
> On 26 sep, 16:00, Gerard Petersen <[EMAIL PROTECTED]> wrote:
>> Getting closer. This works: product.period_start_date.strftime('%d-%m-%Y')
>>
>> But I definitely do not want this in all view handlers. It should go in the 
>> model .. or the modelform.
>>
>> Thanx again!
>>
>> Gerard.
>>
>> Gerard Petersen wrote:
>>> Hi all,
>>> I'm trying to have a formfield filled with a correlctly formatted date 
>>> value.
>>> Validation is already in place. It only accepts "dd-mm-" on submitting 
>>> but when it gets the existing value from the model it shows it in the 
>>> formfield like "-mm-dd"
>>> So the sequence is almost complete. But where do I format the value so the 
>>> formfield shows the correct formatted value when editing. In the model, the 
>>> form or the view method?
>>> Thanx a lot.
>>> Gerard.
>> --
>> urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl'}
> 
> Hi Gerard,
> 
> the DateTimeInput widget already accepts a format parameter.
> What I do is I have a subclass of ModelForm that in its init goes over
> the fields and replaces the widget for Datefields with a datetimeinput
> with the correct format. I also change the input format their (I
> prefer dd/mm/).
> 
> something like:
> 
> for field in self.fields:
> if isinstance(self.fields[field], forms.Datefield):
> self.fields[field].input_formats = settings.DATE_INPUT_FORMATS
> self.fields[field].widget = forms.DateTimeInput(format =
> settings.DATE_OUTPUT_FORMAT)
> 
> as you can see, I put the formats in my settings file, but of course
> you could just plug them right in here too.
> 
> I am not sure this is the best way to do this, but maybe this helps.
> 
> Koen
> > 

-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


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



Re: Model with a foreign key and a percentage

2008-09-26 Thread Fabio Natali

bruno desthuilliers scrisse:
[...]
> # 
> http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

That seems exactly what I was looking for! I'll use it in my app,
using your code as a starting point.

Thank you very much,
Fabio.

-- 
Fabio Natali

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



Re: collecting field values from bound forms (beginner question)

2008-09-26 Thread I.K.

Oops sorry for the duplicate post!

I am looking to get controll of a specific field.  The docs say I can
get my hands on the following parts of a field:
{{ field.label }}
The label of the field, e.g. E-mail address.
{{ field.label_tag }}
The field's label wrapped in the appropriate HTML  tag,
e.g. E-mail address
{{ field.html_name }}
The name of the field that will be used in the input element's
name field. This takes the form prefix into account, if it has been
set.
{{ field.help_text }}
Any help text that has been associated with the field.
{{ field.errors }}

what about the value of the field, if it is text for example:



I don't want django to write the whole form for me.  I'm probably
missing something quite obvious!

On Sep 25, 12:56 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Sep 25, 9:36 am, "I.K." <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I've spent a short while reading the documentation but not spotted
> > what I need. Could somebody point me to the right place please?
>
> > Is there a way to put a bound  Django form into a template to render
> > an HTML form with the previously posted values in it?  I'd like to get
> > the field value specifically, as I introduce javascript handlers on
> > some fields and don't want django to render the whole field.
>
> > For example, a user fills in an html form with their address but
> > leaves out a mandatory field, after validation I wish to render the
> > same HTML with all of the previously submitted values in the form.
>
> > Thanks in advance
>
> I'm not really sure what you're asking here - at first you say you
> don't want Django to render the form, then you say you want it
> completely rendered.
>
> Assuming all you want is to redisplay a partially filled form that
> failed validation along with all the entered values, that's actually
> the standard way to handle forms in Django. See 
> here:http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-...
> On a POST, the form is bound to the data, and if it is not valid, the
> bound form is redisplayed.
>
> Does that answer your question?
>
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Update: Date formatting between model and form output

2008-09-26 Thread Gerard Petersen

Hi Koen,

I'm using modelform, having tried the 'output_format' there does not seems to 
work. In the mean time I figured out a solution within the model like this:

def __init__(self, *args, **kwargs):
super(Product, self).__init__(*args, **kwargs)

if not isinstance(self.period_start_date, unicode): 
self.period_start_date = self.period_start_date.strftime('%d-%m-%Y')

nb: the unicode test is for when a new empty object is invoked.

I'm not sure yet whether formatting like this belongs on the model or the form 
side.

Anyway, thanx for the response.


Regards,

Gerard.

koenb wrote:
> On 26 sep, 16:00, Gerard Petersen <[EMAIL PROTECTED]> wrote:
>> Getting closer. This works: product.period_start_date.strftime('%d-%m-%Y')
>>
>> But I definitely do not want this in all view handlers. It should go in the 
>> model .. or the modelform.
>>
>> Thanx again!
>>
>> Gerard.
>>
>> Gerard Petersen wrote:
>>> Hi all,
>>> I'm trying to have a formfield filled with a correlctly formatted date 
>>> value.
>>> Validation is already in place. It only accepts "dd-mm-" on submitting 
>>> but when it gets the existing value from the model it shows it in the 
>>> formfield like "-mm-dd"
>>> So the sequence is almost complete. But where do I format the value so the 
>>> formfield shows the correct formatted value when editing. In the model, the 
>>> form or the view method?
>>> Thanx a lot.
>>> Gerard.
>> --
>> urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl'}
> 
> Hi Gerard,
> 
> the DateTimeInput widget already accepts a format parameter.
> What I do is I have a subclass of ModelForm that in its init goes over
> the fields and replaces the widget for Datefields with a datetimeinput
> with the correct format. I also change the input format their (I
> prefer dd/mm/).
> 
> something like:
> 
> for field in self.fields:
> if isinstance(self.fields[field], forms.Datefield):
> self.fields[field].input_formats = settings.DATE_INPUT_FORMATS
> self.fields[field].widget = forms.DateTimeInput(format =
> settings.DATE_OUTPUT_FORMAT)
> 
> as you can see, I put the formats in my settings file, but of course
> you could just plug them right in here too.
> 
> I am not sure this is the best way to do this, but maybe this helps.
> 
> Koen
> > 

-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


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



collecting field values from bound forms (beginner question)

2008-09-26 Thread I.K.

Hi,

I've been reading the documentation around forms and templates but I
can't find what I'm looking for, I'd be grateful if somebody could
point me to the right documentation.

In the situation where a bound form object has been passed back to a
template, I would like to get hold of the field value specifically.  I
have seen in the documentation that I can get hold of lots of field
information, names labels etc, but I can't see where to get the
value?  I would like to add some javascript handlers to form elements
so I'd like to create my own form elements.

An example is where somebody fills in an HTML form about addresses,
but forgets a mandatory field, I would like to send the user back to
the HTML form, with the correct fields populated with the submitted
values.

Thanks in advance.


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



Ordering results by m2m relations without multiply results

2008-09-26 Thread Alessandro
I have a model with a m2m field "provincia".
I want to order my objects in this way:
If the object has a provincia = 'AA' on m2m relation must be the
bottom of my list.

I tried query = query.order_by('-provincia') and it works correctly
(because AA is the first of the values), but I duplicates the results
because of multiple m2m relationships:
If an object has both "FC" and "BO" in provincia, I will have 2
objects in queryset also If I use distinct().

Is there a solution?

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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



Re: Update: Date formatting between model and form output

2008-09-26 Thread koenb

On 26 sep, 16:00, Gerard Petersen <[EMAIL PROTECTED]> wrote:
> Getting closer. This works: product.period_start_date.strftime('%d-%m-%Y')
>
> But I definitely do not want this in all view handlers. It should go in the 
> model .. or the modelform.
>
> Thanx again!
>
> Gerard.
>
> Gerard Petersen wrote:
> > Hi all,
>
> > I'm trying to have a formfield filled with a correlctly formatted date 
> > value.
>
> > Validation is already in place. It only accepts "dd-mm-" on submitting 
> > but when it gets the existing value from the model it shows it in the 
> > formfield like "-mm-dd"
>
> > So the sequence is almost complete. But where do I format the value so the 
> > formfield shows the correct formatted value when editing. In the model, the 
> > form or the view method?
>
> > Thanx a lot.
>
> > Gerard.
>
> --
> urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl'}

Hi Gerard,

the DateTimeInput widget already accepts a format parameter.
What I do is I have a subclass of ModelForm that in its init goes over
the fields and replaces the widget for Datefields with a datetimeinput
with the correct format. I also change the input format their (I
prefer dd/mm/).

something like:

for field in self.fields:
if isinstance(self.fields[field], forms.Datefield):
self.fields[field].input_formats = settings.DATE_INPUT_FORMATS
self.fields[field].widget = forms.DateTimeInput(format =
settings.DATE_OUTPUT_FORMAT)

as you can see, I put the formats in my settings file, but of course
you could just plug them right in here too.

I am not sure this is the best way to do this, but maybe this helps.

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



Update: Date formatting between model and form output

2008-09-26 Thread Gerard Petersen

Getting closer. This works: product.period_start_date.strftime('%d-%m-%Y')

But I definitely do not want this in all view handlers. It should go in the 
model .. or the modelform. 

Thanx again!

Gerard.

Gerard Petersen wrote:
> Hi all,
> 
> I'm trying to have a formfield filled with a correlctly formatted date value.
> 
> Validation is already in place. It only accepts "dd-mm-" on submitting 
> but when it gets the existing value from the model it shows it in the 
> formfield like "-mm-dd"
> 
> So the sequence is almost complete. But where do I format the value so the 
> formfield shows the correct formatted value when editing. In the model, the 
> form or the view method?
> 
> Thanx a lot.
> 
> Gerard.
> 
> 

-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


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



Re: virtualmerchant

2008-09-26 Thread Chris Moffitt
Satchmo - http://www.satchmoproject.com is a Django-based store framework
with several credit card processing modules. Feel free to use that code as
the basis.

-Chris

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



get_template problem

2008-09-26 Thread NoviceSortOf


this works

>>>from django.template import loader
>>>loader.get_template('myfile.html')

but how do i get this syntax to work?

>>>get_template('myfile.html')

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



forms -> label for required fields

2008-09-26 Thread Brot

Hello,

is there a general solution for required fields in models? It would be
nice if there could be a class "required" attribute for the label if
the field is required.
I think this solution is implemented in the django admin, because in
the admin the required fields are bold and when I look at the html
source there is the required class.

What do I have to do to mark my labels for required fields with a
required class?

~Bernd


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



Looking for an example on how to use us.forms.USZipCodeField

2008-09-26 Thread Adam Stein

Using Django v1.0.

One of my models is a standard address table.  I knew about
us.models.PhoneNumberField, so I used that for a phone number field.  It
uses us.forms.USPhoneNumberField so that validation works nicely on an
Admin form.  Same thing for USStateField.

While there is are phone number and US state model fields, there doesn't
seem to be the equivalent zip code field, even though there is a zip
code form element.  Not sure why that would be.

I've searched around, but the best I get are syntax errors (at least
Python/Django complains about a syntax error when I try to set up a form
and have my zip code field use USZipCodeField).

Given that, how do you actually tell the Admin form to use
us.forms.USZipCodeField for a given model field or somehow associate the
zip code model field with USZipCodeField?  Right now my zip code model
is a CharField() for lack of a better choice.

Thanks for any links, pointers, examples, etc.
-- 
Adam Stein @ Xerox Corporation   Email: [EMAIL PROTECTED]

Disclaimer: Any/All views expressed
here have been proven to be my own.  [http://www.csh.rit.edu/~adam/]


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



Re: shared model

2008-09-26 Thread Erik Allik

You don't have to put your model to the root of your project to be  
able to share it amongst your apps. You can reference models across  
applications. You might consider creating another application for that  
shared model, too.

Erik

On 26.09.2008, at 15:46, Gabriel Rossetti wrote:

>
> Gabriel Rossetti wrote:
>> Hello everyone,
>>
>> I would like to share a model with all my apps. I moved it from the  
>> app
>> to the project's root dir, but now the admin interface can't find it!
>> Does anyone know how to do this? I thought of createing empty  
>> models in
>> each app and importing everything from the shared model, but I don't
>> really like this.
>>
>> Thank you,
>> Gabriel
>>
> I think I got it, I added the project' s root to the INSTALLED_APPS in
> settings.py and now the model appears in the admin page. I'd apreciate
> any feedback.
>
> Gabriel
>
> >


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



Re: nested applications and syncdb question

2008-09-26 Thread Erik Allik

This might be off topic, but maybe you should consider splitting your  
application into multiple smaller reusable applications? If the models  
of a single application need categorizing, you might have a sign of  
needing to split them up.

A talk on reusable applications by James Bennet from DjangoCon 2008: 
http://www.youtube.com/watch?v=A-S0tqpPga4

Erik

On 26.09.2008, at 9:46, Thomas Guettler wrote:

>
> Stephen Sundell schrieb:
>> I really was just looking for a way
>> to separate models into different modules or files within the same
>> application.  Is this possible?
>>
> Hi,
>
> I do it like this:
>
> Directory myapp/models/ contains:
>__init__.py
>myclass.py
>
> file __init__.py:
> from myclass import MyClass
>
> file myclass.py:
> class MyClass(models.Model):
>class Meta:
>app_label='myapp'
>
> HTH,
>  Thomas
>
>
> -- 
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
>
> >


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



Re: Apache with home directory Django

2008-09-26 Thread Erik Allik

I don't think virtualenv will help you set up your project running  
with Apache. But it's a good practice nevertheless.

If your hosting provider supports custom FastCGI handlers/processes,  
you could look into setting up Django with FastCGI. It's quite easy.
Also if you don't have a way to set up FastCGI (or mod_wsgi or  
mod_python but I doubt your hosting provider lets you do that if  
they're not a Python hosting provider) but your hosting has a cgi-bin  
directory, you can use that to get up and running. It uses plain CGI  
which would be slow if your whole Django project code was to be loaded  
on each request, but there's a nifty little tool called cgi-fcgi which  
routes CGI requests so a persistent FastCGI process which it can spawn  
itself as needed. Just as with "true" FastCGI, this will enable you to  
set up a completely customized environment for your project.

If you have SSH access to the hosting machine which you hopefully do,  
you should be able to compile anything you might need for the  
environment such as database drivers or PIL and any other extensions  
that require compilation.

Regards,
Erik Allik

On 26.09.2008, at 1:39, Graham Dumpleton wrote:

>
> On Sep 26, 8:26 am, "Xian Chen" <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I want to run my Django app on a shared web server.
>>
>> As so many people share this server, I install python and  
>> Django(1.0) under
>> my home directory.
>>
>> How can I configure the Apache with mod_python to make the django  
>> under my
>> directory running?
>>
>> The server administrator refused to install Django in the /usr/bin  
>> directory
>
> With mod_python you cannot make it use a different Python installation
> than the one it was compiled with. The best you can manage is to use
> virtualenv to build a Python virtual environment in your home
> directory where you install all the Python modules/packages you want
> and then refer to that.
>
>  http://pypi.python.org/pypi/virtualenv
>
> Only problem I see is that documentation for virtualenv seems to have
> changed lately and no longer mentions the easy approach for using it
> with mod_python. It has some new mechanism mentioned which I can't see
> at the moment how it works.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: shared model

2008-09-26 Thread Gabriel Rossetti

Gabriel Rossetti wrote:
> Hello everyone,
>
> I would like to share a model with all my apps. I moved it from the app 
> to the project's root dir, but now the admin interface can't find it! 
> Does anyone know how to do this? I thought of createing empty models in 
> each app and importing everything from the shared model, but I don't 
> really like this.
>
> Thank you,
> Gabriel
>   
I think I got it, I added the project' s root to the INSTALLED_APPS in 
settings.py and now the model appears in the admin page. I'd apreciate 
any feedback.

Gabriel

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



Date formatting between model and form output

2008-09-26 Thread Gerard Petersen

Hi all,

I'm trying to have a formfield filled with a correlctly formatted date value.

Validation is already in place. It only accepts "dd-mm-" on submitting but 
when it gets the existing value from the model it shows it in the formfield 
like "-mm-dd"

So the sequence is almost complete. But where do I format the value so the 
formfield shows the correct formatted value when editing. In the model, the 
form or the view method?

Thanx a lot.

Gerard.


-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


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



Re: Restrict users to their own data

2008-09-26 Thread Orne

This example doesn't work for me:
Error: 'super' object has no attribute 'filter'

At the Django Wiki (http://code.djangoproject.com/wiki/
NewformsAdminBranch) I found this:

class BookAdmin(admin.ModelAdmin):
def queryset(self, request):
"""
Filter based on the current user.
"""
return self.model._default_manager.filter(user=request.user)

Orne

On Sep 11, 7:51 pm, Simon Willison <[EMAIL PROTECTED]> wrote:
> On Sep 11, 5:23 pm, Glimps <[EMAIL PROTECTED]> wrote:
>
> >     I would like to restrict users to the data they can see/modify/
> > delete on a table. I have a Reservation table that holds reservations
> > for multiple banners of Restaurant chain. I don't want the user from
> > franchiseX to be able to see/confirm reservations from franchiseY.
>
> > Since all the add/edit/delete is made with the admin interface (Django
> > 1.0) I went and search for something I could override in the
> > ModelAdmin class. No success.
>
> Take another look at ModelAdmin - the methods you want to over-ride
> are queryset(request) which returns the QuerySet used to create the
> "change list" view and has_add_permission(request),
> has_change_permission(request, obj) and has_delete_permission(request,
> obj).
>
> You can over-ride those methods on your ModelAdmin subclass to
> implement your permissions logic. Your code will end up looking
> something like this:
>
> class ReservationAdmin(admin.ModelAdmin):
>     def queryset(self, request):
>         return super(ReservationAdmin, self).filter(user =
> request.user)
>
>     def has_change_permission(self, request, obj=None):
>         if not obj:
>             return False
>         return obj.user == request.user
>
>     def has_delete_permission(self, ...)
>         # similar
>
> Cheers,
>
> Simon

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



shared model

2008-09-26 Thread Gabriel Rossetti

Hello everyone,

I would like to share a model with all my apps. I moved it from the app 
to the project's root dir, but now the admin interface can't find it! 
Does anyone know how to do this? I thought of createing empty models in 
each app and importing everything from the shared model, but I don't 
really like this.

Thank you,
Gabriel

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



problem with the ImageField using ModelForm

2008-09-26 Thread alex

Hi,

i have a problem with the form.ImageField  using ModelForm.
I define a ImageField in my  model and I  configure all path in the
settings file. I have no problem when i use the django admin
interface : the images are uploaded  correctly to the directory and
correctly added in the DB. But when i use the form i make with
ModelForm.  Nothing append. I don't understand because i don't
customise the form, i just exclude some fields.
Is it possible there is a bug in ModelForm.ImageField ??

Thanks
Alex

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



Re: Model with a foreign key and a percentage

2008-09-26 Thread bruno desthuilliers

On 26 sep, 12:02, Fabio Natali <[EMAIL PROTECTED]> wrote:
> Hi everybody.
>
> my django website has to deal with a set of workers, each of them
> earning a given amount of money for their own work.
>
> So I have:
>
> class Worker(models.Model):
> name = models.CharField(max_length=30)
> hourly_wage = models.DecimalField(max_digits=10, decimal_places=2)
>
> A part from their own work, those workers work together in groups and
> receive additional gains for those extra team work. The more a worker
> has been involved in a certain team, the more money he/she gets. Each
> worker can take part to any number of teams.
>
> The problem is: how can I use a model to depict this scenario? Model
> "Team" should be a subset of the set of workers, each of them provided
> with a percentage (= the involvment of worker W within team T).
>
> If Alice, Bob, Carl, David, Emmanuel, Frank are workers, then a team
> could be:
>
> Team0 = {(Alice, 60%), (David, 30%), (Frank, 10%)}

Assuming you're using Django >= 1.0 (if you don't, you'll have to drop
the 'through' argument for ManyToManyField and probably add custom
helper methods and/or a custom Manager):

class Team(models.Model):
name = models.CharField(max_length=128)

# 
http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany
workers = models.ManyToManyField(
Worker,
through='TeamMembership'
)


class TeamMembership(models.Model):
team = models.ForeignKey(Team)
worker = models.ForeignKey(Worker)
involvement = models.FloatField()

class Meta:
unique_together = (('team', 'worker'),)



Not tested of course, but this should get you started

Next point is probably to ensure that the sum of
TeamMembership.involvements for a given team is not > 1.0. I think
you'll have no other solution than overriding the save method of
TeamMembership.

My 2 cents



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



Re: INSTALLED_APPS from a template

2008-09-26 Thread Tim Sawyer

That's just what I needed, thanks very much.

Tim.

On Thursday 25 Sep 2008, Rock wrote:
> from django import template
> from django.conf import settings
> from django.template.defaultfilters import stringfilter
>
> register = template.Library()
>
> @register.filter
> @stringfilter
> def installed(value):
>     apps = settings.INSTALLED_APPS
>     if "." in value:
>         for app in apps:
>             if app == value:
>                 return True
>     else:
>         for app in apps:
>             fields = app.split(".")
>             if fields[-1] == value:
>                 return True
>     return False



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



Re: 'get_latest' is not a valid tag library

2008-09-26 Thread Matthew Crist
I've got that. Here's my directory structure:

-blog
  -templatetags
 -__init__.py
 -get_latest.py

On Sep 25, 11:39 pm, Rock <[EMAIL PROTECTED]> wrote:
> You need an empty __init.py__ in the directory or else the python
> files there will not be found.
>
> On Sep 25, 10:29 pm, Matthew Crist <[EMAIL PROTECTED]> wrote:
>
> > Here's my template:
>
> > {% load get_latest %}
> >  > "http://www.w3.org/TR/html4/loose.dtd;>
> > 
> >         
> >                 My Site - {%block pagetitle %}{% endblock %}
> >         
> >         
> >                 My Site
> >                 
> >                         
> >                                 home
> >                                 Blog
> >                                 Links
> >                                 About
> >                         
> >                 
> >                 
> >                         
> >                                 {% block title %}{% endblock %}
> >                                 {% block primary %}{% endblock %}
> >                         
> >                         
> >                                 Recent Entries:
> >                                 {% get_latest blog.Entry 5 as recent_posts 
> > %}
> >                             
> >                                 {% for obj in recent_posts %}
> >                                         
> >                                                 {{ obj.title}}
> >                                         
> >                                         {% endfor %}
> >                                 
> >                         
> >                 
> >         
> > 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to reject save of a model with many to many relation

2008-09-26 Thread Ottavio Campana

On 25 Set, 22:31, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> You should consider using a custom ModelForm[1] instead of this
> approach. Override its clean() method to perform your checks and throw
> a ValidationError when you don't want the save to proceed. You can
> then also make the Admin use this custom form[2].

thanks it worked! now I still have a problem, but I'll open a new
thread.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Model with a foreign key and a percentage

2008-09-26 Thread Fabio Natali

Hi everybody.

my django website has to deal with a set of workers, each of them
earning a given amount of money for their own work.

So I have:

class Worker(models.Model):
name = models.CharField(max_length=30)
hourly_wage = models.DecimalField(max_digits=10, decimal_places=2)

A part from their own work, those workers work together in groups and
receive additional gains for those extra team work. The more a worker
has been involved in a certain team, the more money he/she gets. Each
worker can take part to any number of teams.

The problem is: how can I use a model to depict this scenario? Model
"Team" should be a subset of the set of workers, each of them provided
with a percentage (= the involvment of worker W within team T).

If Alice, Bob, Carl, David, Emmanuel, Frank are workers, then a team
could be:

Team0 = {(Alice, 60%), (David, 30%), (Frank, 10%)}

Thanks for your help,
Fabio.

-- 
Fabio Natali

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



Re: actual django stack

2008-09-26 Thread Peter Bengtsson



On Sep 25, 8:41 pm, "Frédéric Sidler" <[EMAIL PROTECTED]>
wrote:
> What it the best Django stack today.
>
> In django doc, it says that apache with mod_python is the best
> solution in production. But in the same time I see that everyblock use
> nginx (probably in mode fastcgi).
>
> Did you some of you test different solution and can share some output here.
>
> Here are the ones I see actually
>
> Apache mod_python
> Apache in fastcgi mode
> Lighttpd in fastcgi mode
> Nginx in fastcgi mode
>

I've noticed a small performance boost from using Nginx + fcgi
compared to Apache + mod_python and I hear that Nginx is also a better
performer on the static content but haven't personally experienced
that but the blogosphere will probably agree that Nginx is faster.
The benefit to us with Apache is that we have more knowledge about it
within the team but this only matters when you do more complicated
stuff such as advanced authentication stuff or additional security
hardening. This will probably be the case for many teams since Nginx
is so new.

When I last evaluated whether to go for Nginx or Lighttpd I remember
seeing a lot of concern for Lighttpd's stability. The blogosphere
talked about seg faults and slightly higer footprint than Nginx.

> I'm not talking about load balancer, memcached and database here, just
> the application.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Duplicate files being created on ImageField.save

2008-09-26 Thread David Christiansen

I'm in the process of developing a site in Django that includes the
following in the models.py:

def image_path(page, filename):
return "content_images/page/%s/original/%s" % (page.pk, filename)
def image_scaled_path(page,filename):
return "content_images/page/%s/scaled/%s" % (page.pk, filename)

class Page(models.Model):
# 
image_original = models.ImageField('Picture',
upload_to=image_path, blank=True)
image_scaled = models.ImageField(upload_to=image_scaled_path,
blank=True)
# 
def save(self):
#
scaled_name = os.path.split(self.image_original.name)[-1]
self.image_scaled.save(scaled_name, self.image_original,
save=False)
super(Page, self).save()

The idea is that image_scaled has a version that is a thumbnail of the
originally updated photo.  I've removed that code for testing
purposes, and this still happens.  What happens is that two images are
created in content_images/page/PAGE_ID/scaled/, one with an underscore
after the name.  image_scaled.path shows that the version with the
extra underscore is the current one referred to after running this.

This behavior happens on both Windows and Linux servers.  I'm running
Django 1.0.  As far as I can tell, I'm using the FileField API
correctly.  Is there something obvious that I'm missing?

Thanks in advance!

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



Re: Absolute URLs (including domain name)

2008-09-26 Thread bruno desthuilliers

On 26 sep, 06:40, Karish <[EMAIL PROTECTED]> wrote:
> I am using {{ MEDIA_URL }} in my templates for images, CSS and JS. For
> example, {{ MEDIA_URL }}img/abc.gif
>
> I want to do something similar when I need absolute URLs, and I was
> wondering what approaches exist.

http://docs.djangoproject.com/en/dev/ref/contrib/sites/#getting-the-current-domain-for-full-urls

Then you have a couple options availables:
-  add a context processor (if there isn't already one in the Sites
app) to inject the current site domain name (with or without trailing
slash !-) in your context

- or write a custom filter that adds the domain name to your urls, ie:

{% url 'view_name'|with_domain %}


@register.filter
def with_domain(url):
   # XXX : should check if the url already has a domain before
   return  'http://%s%s' % (Site.objects.get_current().domain, url)

- or write a custom template tag that replaces {% url %}


My 2 cents...

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



virtualmerchant

2008-09-26 Thread yozhik

Is there a django module dealing with processing a credit card
payment? I noticed in one of the django snippets (
http://www.djangosnippets.org/snippets/907/ ) a line:

 from virtualmerchant import VirtualMerchant



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



Re: nested applications and syncdb question

2008-09-26 Thread Thomas Guettler

Stephen Sundell schrieb:
> I really was just looking for a way
> to separate models into different modules or files within the same
> application.  Is this possible?
>   
Hi,

I do it like this:

Directory myapp/models/ contains:
__init__.py
myclass.py

file __init__.py:
 from myclass import MyClass

file myclass.py:
class MyClass(models.Model):
class Meta:
app_label='myapp'

HTH,
  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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