A Query question about Many-to-many relationships

2010-02-21 Thread Jason
Dear All,

Model source code:

from django.db import models

class Publication(models.Model):
title = models.CharField(max_length=30)

class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)


If I already had a QuerySet of Article named articles, how to get a
QuerySet of Publication by these articles, and count the articles by
the Publication?

Thanks a lot!

Jason

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



Re: custom auth backend and ./manage.py test

2010-02-21 Thread Mike Dewhirst

On 22/02/2010 10:53am, Stephen Crosby wrote:

I'm working on a project that requires a custom auth backend which
I've just written by subclassing contrib.auths.backends.ModelBackend
and overriding the authenticate method so it takes a third parameter.
It works nicely, but of course there are now lots of failed auth-
related tests because of the required third parameter to authenticate
when I run ./manage.py test. Related tests for my subclass of
contrib.auth.forms.AuthenticationForm also fail.

I'm just getting my feet wet with testing, so I don't know how to deal
with this properly. Can I override the default tests with new,
relevant ones? Should I just not subclass ModelBackend and
AuthenticationForm? Can I just tell django to skip certain tests?


I would leave existing tests to prove that the un-subclassed ancestral 
code stays wholesome and just write specific tests to prove your own new 
stuff.


hth

Mike




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



Re: Generate random data for Django models

2010-02-21 Thread Timothy Kinney
Okay, I've got such a button and I have copied a template from admin to
serve as a stand-in for it. I have created functions under ProvinceAdmin (in
myapp\admin.py) that look like:

** code **
def ProvinceAdmin(admin.ModelAdmin):
 # other stuff

def add_random_samurai(self, request):
from django.http import HttpResponse
# do stuff
return HttpResponse("This is where the template will render.")

def get_urls(self):
from django.conf.urls.defaults import patterns
urls = super(ProvinceAdmin, self).get_urls()
my_urls = patterns('',
(r'^/(?P\d+)/add_random_samurai/$',
self.admin_site.admin_view(self.add_random_samurai))
)
return my_urls + urls
** / code **

But I'm getting a ValueError:
invalid literal for int() with base 10: '1/add_random_samurai'

If I hardcode: (r'^/1/add_random_samurai/$',
self.admin_site.admin_view(self.add_random_samurai))
Then it works.

So I think my regular expression is not picking up the right integer. Can
you help me re-write the regular expression to catch the province number?

Or can I ignore the province number since I am presumably calling a function
from within the instance of the province I want to update? If so, how do I
tell the pattern matching to ignore that?

-Tim

On Fri, Feb 19, 2010 at 5:21 PM, Peter Herndon  wrote:

>
> On Feb 19, 2010, at 5:51 PM, Timothy Kinney wrote:
>
> > So I have a nice little database now stocked with items and provinces.
> > I now want to generate random samurai and populate the database with
> > them. I can think of two ways to do this:
> >
> > 1) Through the admin interface. But how do I install a button that
> > will add a random samurai? Adding samurai is a built-in function on
> > the template, but the fields are always empty. Is there a
> > straightforward way to add another button called "Add Random Samurai"
> > that does the same thing but with the fields randomly filled from
> > appropriate choices?
> >
> > 2) Use a python script. This seems to have two possible methods:
> > a) Randomly generate samurai desired, output a JSON flatpage, and call
> > manage.py loaddata that_flatpage
> >
> > b) Randomly generate the samurai desired, access the database directly
> > and insert them using SQL syntax. (not very Django like)
> >
> > I have listed these in order of preference. Can someone tell me the
> > easiest way to implement a new admin button? I'm not even sure where
> > the admin templates are stored. :/
> >
> > -Tim
>
> Hi Tim,
>
> Docs for overriding admin are here:
> http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#overriding-admin-templates
>
> You will probably want to override the change_form.html template at
> whatever level is appropriate for your needs (Province, if you are adding
> Samurai to random rooms), and add a button "Generate Random Samurai".  That
> button will be the submit for a form that points to a view you will write.
>  That view should generate a random number, loop over that number, create a
> Samurai object and assign it to a randomly-chosen Room (pick a random number
> from 1 through the total number of rooms, get the room via "room =
> Room.objects.get(pk=").  You will need to add a URL that will
> tie together the view and the submit button.
>
> For an added bonus, add an IntegerField to your form allowing you to set an
> upper bound on the number of Samurai generated.
>
> An approach similar to 2b would be to implement a custom management command
> (skeletal docs here:
> http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/#howto-custom-management-commandsbut
>  Google for better examples) that would allow you to run "python
> manage.py create_samurai".  That command would use the same logic as I
> outlined for the view, and create Samurai via the ORM and assign them to
> random Rooms.
>
> ---Peter Herndon
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



django and its interactive shell on osx

2010-02-21 Thread Massimo Di Stefano
Hi All,

I'm on osx 10.6.x (system python, django trunk, ipython from bazar repository)
tring to run the django shell i have :

MacBook-Pro-15-di-Massimo-Di-Stefano:geodjango sasha$ python manage.py 
shellTraceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", 
line 438, in execute_manager
utility.execute()
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", 
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 
195, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 
222, in execute
output = self.handle(*args, **options)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 
351, in handle
return self.handle_noargs(**options)
  File 
"/Library/Python/2.6/site-packages/django/core/management/commands/shell.py", 
line 29, in handle_noargs
shell = IPython.Shell.IPShell(argv=[])
AttributeError: 'module' object has no attribute 'Shell'
MacBook-Pro-15-di-Massimo-Di-Stefano:geodjango sasha$ 


Thanks for any suggestion to fix this problem!

regards,

Massimo.

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



Job opportunity - Newcastle, NSW, Australia

2010-02-21 Thread Peter
Hi all

Please see:

http://tinyurl.com/djangojob

for a job being advertised by NSW Rural Doctors Network in Newcastle,
NSW, Australia.

Thanks.

Peter J Williams
Information Manager
NSW Rural Doctors Network
Head Office
Suite 19, Level 3
133 King Street
Newcastle NSW 2300
Telephone: (02) 4924-8000
Facsimile: (02) 4924-8010
Mailto:pwilli...@nswrdn.com.au
Web: http://www.nswrdn.com.au

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



SAAS User and Auth situation.

2010-02-21 Thread orokusaki
I'm developing an SAAS which means that I will have Accounts and those
Accounts will have Users. Each account's Users are completely
orthogonal to the Users of another Account. When a user logs in,
they'll supply an Account ID, a username, and a password so username
only needs to be unique with regards to the Account in question.
Firstly, is there an app out there or somebody who knows how to
conquer this? If so, I would truly appreciate the help or a link.


Problem 1 (with built-in User object), maybe there is a way around
this:

A) User of Account 'acme' might have the username "mike" and the user
for Account "general mills" might have a user with the username
"mike" (since "mike" is a very common name this will certainly happen
within the first day of getting clients). I can't control what
Accounts' Users decide to make their username and I certainly don't
want to make it like domain registration, like if a User has to check
if a username is available before creating it (all common names would
be taken after the first 100 accounts if the average account had 2-3
users).

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



Re: Use admin tools for "normal users" pages

2010-02-21 Thread Timothy Kinney
You basically just need to copy the admin templates and views (see the
django.contrib.admin directory) to your user templates and views (you can
set where this directory is in settings.py, but it's often a directory
called templates under your project or your app). Then it should be easy to
look through them and remove any actions you don't want users to make (like
delete or change).

-Tim


On Sun, Feb 21, 2010 at 4:44 PM, sebsheep <
sebastien.fabrice.besn...@gmail.com> wrote:

> Hello,
>
> I've just discovered Django and its amazing admin part management. Is
> it possible to use these tools in production ?
>
> I would like to realize a kind of wiki-organizer(nothing exceptionnal,
> just need to have a very specific tool), where each user can add
> events. I thought to use the admin module of Django in order to create
> quickly and easily the forms.
>
> It seems technically possible : create groups and give some
> appropriate permissions ; but it looks  very nasty : give an admin
> acces for all the users is not verry clean ;p
>
> So, is it a clean solution to use admins tools for the site itself ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Working with outside data sources

2010-02-21 Thread Michael Lissner
Thanks again for these replies. Very helpful indeed.

Rishabh Manocha wrote on 02/18/2010 07:47 PM:
>
>
> On Fri, Feb 19, 2010 at 11:23 AM, Michael Lissner
>  > wrote:
>
> Thanks for the reply.
>
> My teammate that writing the scrapers is a java guy, and he's
> planning to use that rather than django/python. I haven't looked
> at the kinds of databases that django creates, but do you think
> that will cause any problems?
>
> If not, I think we'll proceed with plan B, below.
>
>
> I don't think it should be a problem, as long as you guys can come to
> a consensus about how your tables will be defined and named (I made
> the table naming mistake early on - django expects certain table names
> names for models you have defined in your models.py files - of-course
> you can override that by setting db_table in the Meta class for said
> model) . Also, if he plans on serializing any data, make sure he does
> so in something like JSON or XML so that you can have access to it via
> Python.
>
> Also, have you taken a look at the inspectdb management command - it
> might go a long way in helping you get your models.py files setup -
> see http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb
>  
>
>
> Michael Lissner
> mliss...@michaeljaylissner.com 
> 909-576-4123
>
>
> Rishabh Manocha wrote on 02/18/2010 07:16 PM:
>>
>>
>> On Fri, Feb 19, 2010 at 10:04 AM, mjlissner > > wrote:
>>
>> I'm using django for a final project in my masters program at UC
>> Berkeley, and I'm trying to sort out exactly how the database
>> works. I
>> would spend a bunch of time figuring this out myself, but I
>> am working
>> in a team, and my teammates need this info asap.
>>
>> My teammates are making scrapers that pull information from
>> various .gov websites, and then dump that information into a
>> mysql
>> database.
>>
>> It's my job to use django to make queries on that database,
>> and to
>> build a web front end to it.
>>
>> We've developed a data model for the database, but my question is
>> what's the best way to interface between the data they're
>> dumping in,
>> and django? I have two thoughts about this...both of which are
>> probably wrong:
>> 1. They can build a separate database, and I can pull from it
>> using
>> custom sql queries within my django code; or
>> 2. I can use django models to flesh out the database, and
>> then they
>> can dump into the tables that were created by the syncdb command.
>>
>> Can people opine as to what the best way to do this might be,
>> or what
>> kinds of problems we can anticipate if we do the above?
>>
>> --
>> 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
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> I've done something similar with my project. I setup up my
>> database tabels such that they work with both my scraping code as
>> well as my django code. To insert data from my scraping code, I
>> used sqlalchemy (though, you can just as easily use django's ORM
>> for this - this method would probably be better in the longer run
>> 'cause you can define your models in one place and just include
>> them in both your scraping code as well as your django site) and
>> then just accessed that data from my django site accessing the
>> same database (no replication, parsing etc.). This method has
>> worked out quiet well for me, so far.
>>
>> -- 
>>
>> Best,
>>
>> R
>> -- 
>> 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
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com
> 

custom auth backend and ./manage.py test

2010-02-21 Thread Stephen Crosby
I'm working on a project that requires a custom auth backend which
I've just written by subclassing contrib.auths.backends.ModelBackend
and overriding the authenticate method so it takes a third parameter.
It works nicely, but of course there are now lots of failed auth-
related tests because of the required third parameter to authenticate
when I run ./manage.py test. Related tests for my subclass of
contrib.auth.forms.AuthenticationForm also fail.

I'm just getting my feet wet with testing, so I don't know how to deal
with this properly. Can I override the default tests with new,
relevant ones? Should I just not subclass ModelBackend and
AuthenticationForm? Can I just tell django to skip certain tests?

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



Overriding widget for forms.ModelMultipleChoiceField in ModelForm

2010-02-21 Thread Zodiak
Does anybody know how to make this?
This variant:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets

DOES NOT WORK for forms.ModelMultipleChoiceField

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



Use admin tools for "normal users" pages

2010-02-21 Thread sebsheep
Hello,

I've just discovered Django and its amazing admin part management. Is
it possible to use these tools in production ?

I would like to realize a kind of wiki-organizer(nothing exceptionnal,
just need to have a very specific tool), where each user can add
events. I thought to use the admin module of Django in order to create
quickly and easily the forms.

It seems technically possible : create groups and give some
appropriate permissions ; but it looks  very nasty : give an admin
acces for all the users is not verry clean ;p

So, is it a clean solution to use admins tools for the site itself ?

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



Most Recent Distinct Results

2010-02-21 Thread max
Hi,
I have a list of "news" matches for certain companies, ordered by the
date they were found.  I want to grab 5 results for each company up to
5 companies.  I initially approached this problem by just grabbing a
large amount of the newest results (LIMIT 100 or so) and then, through
python, grouping them into lists for each company.  However, this has
a pitfall in that if one company has most of the results for the last
100 newest results, I will only have one company in the final set,
rather than 5.

I thought I might be able to use  DISTINCT query and do something like

Match.objects.filter(type='company').values('contact_id__company').order_by('-
added_date').distinct()[:5]

To get the newest 5 companies mentioned, and then take those names and
do some more queries for each company.  But that has a failure that
I've read about in the docs (http://docs.djangoproject.com/en/dev/
topics/db/aggregation/#interaction-with-default-ordering-or-order-by)

I also tried an annotate method like this:

Match.objects.filter(client_id__pk=42,
result_type='company').order_by('-
added_date').values('contact_id__company').annotate().order_by('contact_id__company')

But the problem with this is that I can't LIMIT after I sort by order,
so I end up just getting a DISTINCT list of all companies that have
Match objects for them.

Is there another way I could do this, where I'm guaranteed at least 5
distinct company names sorted by the date news was found for them?

Thanks.

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread arserangel
ho ho,studing from every one!
  tutorial!
  
  -- Original --
  From:  "Shawn Milochik";
 Date:  Sun, Feb 21, 2010 08:43 PM
 To:  "django-users@googlegroups.com"; 
 
 Subject:  Re: How to Create models with columns not corresponding to database.

  
>From your question, it is clear that you don't understand what the  
admin app is. At least do the Django tutorial before you start asking  
how to do things.

Your question is like asking how to use PHPMyAdmin to create this  
report.

Shawn 
  

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

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



Re: Othogonal aspects to models

2010-02-21 Thread Shawn Milochik
Check out James Bennett's DjangoCon 2008 talk on reusable apps. He goes into 
some detail on how he made django-registration in such a way that it wasn't 
necessary to require a specific model in order for it to work. I haven't 
implemented anything this reusable myself so I can't really give you much, but 
you could do worse than checking out the work of one of the core developers of 
Django.

http://www.youtube.com/watch?v=A-S0tqpPga4

In addition, the actual app is here, for your reading pleasure:

http://bitbucket.org/ubernostrum/django-registration/


Shawn

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



Re: Djamgo cookies

2010-02-21 Thread adamjamesdrew
This is a default install for a computer associates firewall. Any
thoughts on why amazon would work with no url mods... Cookie domain ??
Expiration type

Dennis Kaarsemaker wrote:
> On zo, 2010-02-21 at 23:51 +, theikl...@gmail.com wrote:
> > I have a firewall that immediately expires cookies. [...] How can I
> > fix this
>
> Get a better firewall. Firewalls shouldn't mess with cookies.
> --
> Dennis K.
>
> The universe tends towards maximum irony. Don't push it.

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



Re: Djamgo cookies

2010-02-21 Thread Dennis Kaarsemaker
On zo, 2010-02-21 at 23:51 +, theikl...@gmail.com wrote:
> I have a firewall that immediately expires cookies. [...] How can I
> fix this

Get a better firewall. Firewalls shouldn't mess with cookies.
-- 
Dennis K.

The universe tends towards maximum irony. Don't push it.

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



Djamgo cookies

2010-02-21 Thread theiklabs
I have a firewall that immediately expires cookies. I can log into amazon and 
other websites without issue and they don't modify my url? How can I fix this
Sent from my Verizon Wireless BlackBerry

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



Othogonal aspects to models

2010-02-21 Thread klaasvanschel...@gmail.com
Hi all,

Maybe I'm asking the wrong questions, maybe I'm asking the impossible,
maybe I need to do the hard thinking myseld. Anyway: here's my
problem.

We have a bunch of projects (about 4 big customers), some of which
have significant overlap. The current approach is copy/paste,
supported by tools such as mercurial for cross-project patching. This
is not maintainable on the long run.

I've decided to work towards an "architecture" of apps. Everything
that does some small bunch of related things is an app, apps can be
dropped in to projects, projects define actual sites and their
particularities.

Now for the fun part: one of our bigger projects which lives in 3 (hg
forked) forms (2 for big customers and 1 for ourselves as an eat-your-
own dogfood) has this idea of what we call a "Realm". Read "company",
"site" or "user" for "realm". It basically means that (almost) all
model instances are only relevant for that particular realm. (Off
course, in particular cases cross realm goodies happen, which is the
reason to throw the stuff on a pile in the first place)

So say for this family of projects tracking of expenses is something
we do. This would mean that we can

A: add/delete/edit/view expenses
B: I can do this, but some other people have expenses of their own to
track

Now, looking at some speeches/talks/blogs on the internet the
recurring theme for apps is "as small as possible". So I'd say my app
is "expense tracking" Not: expense tracking "within the context of
'klaas'"

Now this is not entirely academic, because our second family of
projects has no such concept of "realm". So I'd like to be able to
make a bunch of apps "expense tracking", "basic billing", "time
tracking", etc etc. and put this whole concept of realms on top of it
later. Or as a separate decision at least.

One of the options that was discussed on the IRC when I brought this
up was "Abstract models". But I'm not really sure if that would lead
anywhere. It would mean introducing a whole layer of "abstract" stuff
which is not abstract at all in reality (the whole point of the
exercise would be that I can use the original "expense" out of the
box). Also: Django should not be Java. (and isn't as far as I'm aware)

Another idea (I tried this myself but it didn't work) was simply
moneky-patching an extra field in as an afterthought. It did not work
'cause the django magic is not also patched. Also: about 4 people
started warning me when I suggested this on IRC.

So what's the official/preferred/right way to go forward? I can hardly
believe I'm the first to encounter the need for orthogonality on the
model level?

thanks a lot,
Klaas

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



Re: have trouble with safe and linebreaks together

2010-02-21 Thread Benjamin
If you still want to give your users quite a bit of formatting power
(other than just 'title' and 'body' fields), consider letting them use
something like markdown, restructured test, or something similar. This
way your application is safe from running arbitrary HTML, but your
users get to make things look pretty.

Django-markup is a great reusable app that enables this sort of thing.
Take a look at its documentation for use in templates here:
http://docs.mahner.org/django-markup/usage_templates.html

On Feb 21, 4:41 pm, Ali Rıza Keleş  wrote:
> Hi all,
>
> I have a problem about template language.
>
> In my model there is a text field for body text of entries. And I markup
> my text with some html. Like below:
>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. "Ut enim ad
> minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
> ex ea commodo consequat."
>
> Section 1.10.32 of "de Finibus Bonorum et Malorum"
>
> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> proident, sunt in culpa qui officia deserunt.
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo.
>
> and in my templates use this text like that:
>
> {{ body|safe|linebreaks }}
>
> and the result is:
>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
> eiusmod tempor incididunt ut labore et dolore magna aliqua. "Ut
> enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
> aliquip ex ea commodo consequat."
>
> Section 1.10.32 of "de Finibus Bonorum et Malorum"
>
> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> proident, sunt in culpa qui officia deserunt.
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo.
>
> As you see, h2 tag is inside p tag. And this is not a valid usage for
> xhtml which is my document's type.
>
> I need paragraphs because their styles are applied by css. Also h2s are
> same.
>
> I don't want users-editors- do paragraphs manually, because many of
> texts are quite long, this is not efficient, so I use linebreaks. Users
> have some capability of writing html as much as they need. So they can
> markup h2, strong etc, if it is necessary in text.
>
> How can I fix this?
>
> Thanks.
>
> --
> Ali Rıza Keleş

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



Re: formatting results of search

2010-02-21 Thread Dennis Kaarsemaker
On wo, 2010-02-17 at 05:32 -0800, gintare wrote:
> @@in *.html
> @@using line  {{ word|escape }}
> 
> @@i am getting printed answer :(u'moi',)  instead of moi.
> @@I need only word moi (without any brakets, quatations) be visible in
> a webpage. 

In this case you want word.0|escape

values() always returns a sequence of tuples.
-- 
Dennis K.

The universe tends towards maximum irony. Don't push it.

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



Re: Union of two query sets?

2010-02-21 Thread Dennis Kaarsemaker
On ma, 2010-02-15 at 18:22 -0800, ydjango wrote:
> I have two query sets with two different where clause on same table
> and same columns. Is it possible to have their union.
> 
> I tried qryset = qryset1 + qryset2 - It gave me - "+ unsupported
> argument"

One possible way:

queryset = yourmodel.object.filter(Q(queryset1_args) | Q(queryset2_args))

-- 
Dennis K.

The universe tends towards maximum irony. Don't push it.

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



Re: django and caching

2010-02-21 Thread Itay Donenhirsch
Thanks for the replies folks, you've been very helpful.
One more question though - I didn't find any "official" way to clear
the cache of a certain object. Any suggestions?

On Sun, Feb 21, 2010 at 11:52 PM, Christophe Pettus  wrote:
>
> On Feb 21, 2010, at 1:22 PM, Itay Donenhirsch wrote:
>
>> hi folks, a little question: when using any caching mechanism (say,
>> memcache) with django, how does django know when to "refresh" the
>> cache?
>>
>> a scenario for example:
>> 1. user gets a page, gets page content A
>> 2. someone changes the state of the database so A -> A'
>> 3. user refreshes the same page, does he get A or A'?
>>
>> how does django know to handle this?
>
> Django doesn't; hopefully, you do. :)
>
> The "binding" (in a very general sense) between your model and the templates
> that get rendered to the client is your view function; Django doesn't
> inherently know what cached templates depend on which rows in the database.
>  Thus, it's really your code that knows what cached templates need to be
> invalidated when a database change occurs.  The typical way of doing this
> for the view function that handles the database update also does the
> appropriate cached template invalidation.
>
> --
> -- Christophe Pettus
>   x...@thebuild.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: have trouble with safe and linebreaks together

2010-02-21 Thread cootetom
You have a mix of techniques here. You are allowing markup to be saved
into the database and then when being displayed in a template you are
again adding mark up there to! Why don't you have a model which has a
"title" field and a "body" field. That way the user doesn't have to
get involved with entering in any markup at all. Then you template can
do the following:

{{ heading }}

{{ body|linebreaks }}




On Feb 21, 9:41 pm, Ali Rıza Keleş  wrote:
> Hi all,
>
> I have a problem about template language.
>
> In my model there is a text field for body text of entries. And I markup
> my text with some html. Like below:
>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. "Ut enim ad
> minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
> ex ea commodo consequat."
>
> Section 1.10.32 of "de Finibus Bonorum et Malorum"
>
> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> proident, sunt in culpa qui officia deserunt.
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo.
>
> and in my templates use this text like that:
>
> {{ body|safe|linebreaks }}
>
> and the result is:
>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
> eiusmod tempor incididunt ut labore et dolore magna aliqua. "Ut
> enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
> aliquip ex ea commodo consequat."
>
> Section 1.10.32 of "de Finibus Bonorum et Malorum"
>
> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> proident, sunt in culpa qui officia deserunt.
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo.
>
> As you see, h2 tag is inside p tag. And this is not a valid usage for
> xhtml which is my document's type.
>
> I need paragraphs because their styles are applied by css. Also h2s are
> same.
>
> I don't want users-editors- do paragraphs manually, because many of
> texts are quite long, this is not efficient, so I use linebreaks. Users
> have some capability of writing html as much as they need. So they can
> markup h2, strong etc, if it is necessary in text.
>
> How can I fix this?
>
> Thanks.
>
> --
> Ali Rıza Keleş

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



Best practices for restricting media?

2010-02-21 Thread Brett Thomas
Hey, this is a pretty basic sysadmin question, but seems pretty critical for
django development. What's the best way to limit media on a django site to
certain users?

A typical example is a photo gallery app. Suppose you are recreating Flickr,
and a user's photos should only be viewable by his/her friends. You can
restrict other users from accessing the django view that presents the photo.
But if the image is on a static media server, the image is still publicly
accessible by its direct URL.

So, question is: can you add restrictions to a media server connected to
django to say "this image can only be served in a page that was rendered by
a django view"?

Thanks for the help --
Brett

Surprisingly (or not?) Facebook has no such permissions...here's a random
photo from one of my friend's private albums that apparently you can see
without even having a facebook account:
http://photos-f.ak.fbcdn.net/photos-ak-snc1/v2681/23/22/30008/n30008_36329813_2721261.jpg

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



Re: django and caching

2010-02-21 Thread Christophe Pettus


On Feb 21, 2010, at 1:22 PM, Itay Donenhirsch wrote:


hi folks, a little question: when using any caching mechanism (say,
memcache) with django, how does django know when to "refresh" the
cache?

a scenario for example:
1. user gets a page, gets page content A
2. someone changes the state of the database so A -> A'
3. user refreshes the same page, does he get A or A'?

how does django know to handle this?


Django doesn't; hopefully, you do. :)

The "binding" (in a very general sense) between your model and the  
templates that get rendered to the client is your view function;  
Django doesn't inherently know what cached templates depend on which  
rows in the database.  Thus, it's really your code that knows what  
cached templates need to be invalidated when a database change  
occurs.  The typical way of doing this for the view function that  
handles the database update also does the appropriate cached template  
invalidation.


--
-- Christophe Pettus
   x...@thebuild.com

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



have trouble with safe and linebreaks together

2010-02-21 Thread Ali Rıza Keleş
Hi all,

I have a problem about template language. 

In my model there is a text field for body text of entries. And I markup
my text with some html. Like below:


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. "Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat."

Section 1.10.32 of "de Finibus Bonorum et Malorum"

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt
explicabo.


and in my templates use this text like that:

{{ body|safe|linebreaks }}

and the result is:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. "Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat."

Section 1.10.32 of "de Finibus Bonorum et Malorum"

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt
explicabo.


As you see, h2 tag is inside p tag. And this is not a valid usage for
xhtml which is my document's type.

I need paragraphs because their styles are applied by css. Also h2s are
same.

I don't want users-editors- do paragraphs manually, because many of
texts are quite long, this is not efficient, so I use linebreaks. Users
have some capability of writing html as much as they need. So they can
markup h2, strong etc, if it is necessary in text.

How can I fix this?

Thanks.

--
Ali Rıza Keleş

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



Re: django and caching

2010-02-21 Thread cootetom
Hi,

The user gets A. Django's caching doesn't know that the database data
changed. You could override the save method on the model so that when
data is saved you clear the cache, or update the cache maybe.





On Feb 21, 9:22 pm, Itay Donenhirsch  wrote:
> hi folks, a little question: when using any caching mechanism (say,
> memcache) with django, how does django know when to "refresh" the
> cache?
>
> a scenario for example:
> 1. user gets a page, gets page content A
> 2. someone changes the state of the database so A -> A'
> 3. user refreshes the same page, does he get A or A'?
>
> how does django know to handle this?
>
> thanks,
> itay

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



django and caching

2010-02-21 Thread Itay Donenhirsch
hi folks, a little question: when using any caching mechanism (say,
memcache) with django, how does django know when to "refresh" the
cache?

a scenario for example:
1. user gets a page, gets page content A
2. someone changes the state of the database so A -> A'
3. user refreshes the same page, does he get A or A'?

how does django know to handle this?

thanks,
itay

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



Re: how to get as_sql() to work again

2010-02-21 Thread felix

from django.db import connections


def dbug():
pdb.set_trace()

def qbug(qs,caption=""):
connection = connections['default']
aa,bb=qs._as_sql(connection)
print caption, aa % bb
return qs

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



apparent bug in QuerySet

2010-02-21 Thread felix

This seems so blatant that it couldn't really be a bug without someone
noticing. Django 1.2

qs = Apt.objects.filter(list_on_web=True,is_available=True)

 # FastAdderStatus has Apt and Service as fk
qs = qs.filter(fastadderstatus__service=self.service)

# later on here's another filter on the same table
qs = qs.filter(fastadderstatus__running_status__in= (2, 3, 4))

produces this:

  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
"fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") INNER JOIN
"fastadder_fastadderstatus" U3 ON (U0."id" = U3."apt_id") WHERE
(U0."list_on_web" = True  AND U0."is_available" = True  AND
U1."service_id" = 4  AND U3."running_status" IN (2, 3, 4))

Note that it joins the same table twice, and the Apt is not returning
distinct.  Postgres is not liking the query.

count: 2837

[, , , , , , , ,
, , , , , , , ,
, , , , '...(remaining elements
truncated)...']

what it should say (manually fixed) :

  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
"fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") WHERE
(U0."list_on_web" = True  AND U0."is_available" = True  AND
U1."service_id" = 4  AND U1."running_status" IN (2, 3, 4))

count: 611, no dups


My solution:

params = {}
if self.service:
params['fastadderstatus__service'] = self.service
if self.agent:
params['agents'] = self.agent

if self.status:
 
params.update( 
FastAdderStatus.objects.filter_params_for_status(self.status,'fastadderstatus') 
)

# a single call to filter
qs = qs.filter(**params)

which avoids the (?) bug and also is vastly more efficient.

Having just stepped through with the debugger and seen how much work
is involved with .filter I am in future going to avoid any multiple
calls to filter. Its better to pass around dicts.


SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
"fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") INNER JOIN
"nsproperties_apt_agents" U2 ON (U0."id" = U2."apt_id") WHERE
(U0."is_available" = True  AND U0."list_on_web" = True  AND
U1."running_status" IN (2, 3, 4) AND U2."agent_id" = 175  AND
U1."service_id" = 4 )

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



Re: what if I need to use two objects to get a third object in my templates?

2010-02-21 Thread Jeremy Dillworth
On Feb 21, 11:14 am, Jeremy Dillworth  wrote:
> and a view named list:
>
> def list(request):
>     people = Person.objects.all()
>     for p in people:
>         p.columns = [None, None, None]
>         for c in DataPoint.objects.filter(person=p, value__gt=4):
>             p.columns.append(c)
>
>     return render_to_response('people/listing.html',
> dict(people=people))

I should probably mention too that the view code in my example may be
a bit unwise. I just wanted to keep it simple. For real production
code, I would wonder if doing a query in a loop like that would scale.
Potentially this view could do dozens of queries during a single HTTP
request. A better option would be to do one hit on the DataPoint table
that pulls all the DataPoints for all the Person objects, then use
some dictionaries and lists to get them into their proper places. Or
you could even just do select_related on the DataPoints and get the
Person objects at the same time...

Jeremy

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



update

2010-02-21 Thread shofty
just wanted to add in that i worked out that this was due to changing
the PIL installed on my local box.
don't know if there is a bug, suspect it was more that i coded the
solution around 1.6 then upgraded to 1.7 for something else, which
unfortunately broke this app.

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



Re: How to make the login forms available to the entire site?

2010-02-21 Thread rebus_
On 21 February 2010 19:38, Timothy Kinney  wrote:
> There may be a more elegant way, but I think you could just call the login
> view from whatever view the url directs the user too. So it fills in the
> login info and then renders the rest of the page...but on second thought
> maybe you need to include the login form in every view...
>
>
>
> On Sun, Feb 21, 2010 at 10:44 AM, Patrick  wrote:
>>
>> I thought that if I put the login forms on the base template and then
>> extend all others from that base template, the login forms would be
>> available all the way through. But there is a problem: the login forms
>> are only displayed if the url is processed by the 'login' view. That
>> login view provides the forms needed for authentication, among other
>> things.
>>
>> The thing is, what I want is to allow user to authenticate no matter
>> what page from the site he is visitting. How can that be done?
>>
>> Many thanks in advance,
>>
>> Patrick Steiger
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Well you could put form HTML in base.html for example and just make it
post on login URL.
Or perhaps you could put it in context processor [1].

Can't think of more elegant solution right now.

[1] http://docs.djangoproject.com/en/dev/ref/templates/api/

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



Re: Ajax request, json object, fields with instance of inherits class converted in regular string

2010-02-21 Thread Kev Dwyer
On Fri, 19 Feb 2010 07:00:36 -0800, manixor wrote:


> 
> The very big problem is, when I loop into object on template, in the
> monday field is not enymore the Day instance, but the string 1. How can
> I convert to an json object the week object, and to keep the instance of
> the inherits class, or how can I modify the ForeignField model, to point
> to another field, like name in my case and not to the pk, which is an
> integer in my case?

Hello Maxinor,

If I understand your problem correctly, I can think of two ways around this:

(1) Use the development release  (1.2, the natural keys 
(http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys)
enhancement may do what you want.
(2) Set Day.name to have primary_key=True, that way the name will be 
serialised instead of the automatically generated primary key.  As
you have already set Day.name to be unique making it the primary key 
shouldn't prove to be a problem.

Cheers,

Kev

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread Timothy Kinney
Maybe the problem is that you don't quite understand what models are for. If
you just want to create a report from your SQL data you use the models to
structure the data and define relationships, not to report it. You use the
views and the templates to generate the actual report.

Does that make sense?

-Tim

On Sun, Feb 21, 2010 at 9:27 AM, Atamert Ölçgen  wrote:

> On Sunday 21 February 2010 16:16:56 Amps wrote:
> > ok i had read, but was unclear ... ok, now , i am not using admin
> > module.
> > but can we create a model in model.py which doesnt reflect any table/
> > columns in the database, but should reflect a report columns.
> AFAIK no.
>
> A practical approach could be to create a normal model that points to a
> normal
> table and then save your analytic data on it. It doesn't matter whether the
> data is coming from a Queryset or raw SQL, you can
> MyModel.objects.create(**my_data) as long as you create a my_data dict for
> each entry. (you don't even have to save via ORM, but it's safer)
>
> Perhaps we can help better if you tell us what **exactly** you are trying
> to
> achieve and why you need a tableless model.
>
>
> --
> Saygılarımla,
> Atamert Ölçgen
>
>  -+-
>  --+
>  +++
>
> www.muhuk.com
> mu...@jabber.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



how to get as_sql() to work again

2010-02-21 Thread felix
As of 1.2 and multi-db how do I get the sql that will be produced from
a query set ?

Since 1.2 and multi-db, the previous methods are no longer working.
Its been said here that we shouldn't depend on internal functions as
they may change.

However getting the SQL that will be produced is essential.  There
needs to be a utility method somewhere that will give us this sql and
it needs to remain stable.  If the class structure and implementation
gets moved around then this utility method would be updated to
continue to offer this most basic and essential of debugging tools.

(Pdb) qs.query

(Pdb) qs.query.as_sql()
*** AttributeError: 'GeoQuery' object has no attribute 'as_sql'

(Pdb) qs.query.compiler
'GeoSQLCompiler'


Please let's not assume that Django's ORM is completely magical and we
should never have need to investigate what it is doing.

SELECT "nsproperties_apt"."id" FROM
"nsproperties_apt" INNER JOIN "fastadder_fastadderstatus" ON
("nsproperties_apt"."id" = "fastadder_fastadderstatus"."apt_id")
INNER JOIN "nsproperties_apt_agents" ON ("nsproperties_apt"."id" =
"nsproperties_apt_agents"."apt_id")
WHERE ("nsproperties_apt"."is_available" = True
AND "nsproperties_apt"."list_on_web" = True
AND "nsproperties_apt"."id" IN
(SELECT U0."id" FROM "nsproperties_apt" U0
INNER JOIN "fastadder_fastadderstatus" U1 ON (U0."id" =
U1."apt_id")
INNER JOIN "nsproperties_apt" U2 ON (U1."apt_id" =
U2."id")
INNER JOIN "nsproperties_apt_agents" U3 ON (U2."id" =
U3."apt_id")
INNER JOIN "fastadder_fastadderstatus" U5 ON (U0."id" =
U5."apt_id")
INNER JOIN "fastadder_fastadderstatus" U6 ON (U0."id" =
U6."apt_id")
WHERE (U0."is_available" = True
AND U0."list_on_web" = True
AND U3."agent_id" = 175
AND U5."running_status" = 2
AND U6."priority" >= 1
AND U6."agent_priority" = 1 ))
AND "fastadder_fastadderstatus"."service_id" = 4
AND "nsproperties_apt_agents"."agent_id" = 175 )

When I get garbage like this I need to investigate different points in
my chain and see how the query evolved to this point.




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



Re: How to make the login forms available to the entire site?

2010-02-21 Thread Timothy Kinney
There may be a more elegant way, but I think you could just call the login
view from whatever view the url directs the user too. So it fills in the
login info and then renders the rest of the page...but on second thought
maybe you need to include the login form in every view...



On Sun, Feb 21, 2010 at 10:44 AM, Patrick  wrote:

> I thought that if I put the login forms on the base template and then
> extend all others from that base template, the login forms would be
> available all the way through. But there is a problem: the login forms
> are only displayed if the url is processed by the 'login' view. That
> login view provides the forms needed for authentication, among other
> things.
>
> The thing is, what I want is to allow user to authenticate no matter
> what page from the site he is visitting. How can that be done?
>
> Many thanks in advance,
>
> Patrick Steiger
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Creating new Thread in a view?

2010-02-21 Thread Eric Chamberlain

On Feb 17, 2010, at 9:36 AM, justind wrote:

> 
> What is a better solution to this problem? Actually, I feel like I
> can't solve it because I lack an understanding at what's happening
> where Django touches Apache and I'd like to fill that gap, so in
> addition to help with this particular problem, descriptions of what's
> going on at apache/mod_wsgi process level and how that interacts with
> me spawning threads etc (or pointers to docs) would help me out and be
> appreciated.


Take a look at pyapns.  It holds opens a socket to Apple's push notification 
service and works with django.

--
Eric Chamberlain, Founder
RF.com - http://RF.com/







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



Re: choices in model field error

2010-02-21 Thread carlos
hi copy de code in first line your models.py or views.py

 # -*- coding: UTF-8 -*-

bye :)


On Thu, Feb 18, 2010 at 7:55 PM, Karen Tracey  wrote:

> On Thu, Feb 18, 2010 at 11:18 AM, hooda_28  wrote:
>
>> hi im having a problem for about an hour now, i have a model
>>
>> class Dummy(models.Model):
>>sell = models.CharField(max_length=20, choices=Z_CHOICES)
>>
>>def __unicode__(self):
>>return u'%s' % (self.sell)
>>
>> where Z_CHOICES =('9 , 'ñññ'),('10' , 'ña'),('11' , "aña"),) that is
>> dynamically created by a script
>>
>> and here is my admin part
>>
>> class DummyAdmin(admin.ModelAdmin):
>>fields = ('sell',)
>> admin.site.register(Dummy, DummyAdmin)
>>
>> there is no select box/input box appearing and no error being returned
>> by django..  i know its the non-ascii characters that cause this but
>> how can i fix it?
>>
>>
> Ensure the strings containing non-ASCII characters are unicode strings, not
> bytestrings.
>
> Karen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Passenger 57 - a Django query problem

2010-02-21 Thread derek
First off - my apologies to all who have replied so diligently without
so much as a "hi" from me before now...  soon after posting this I
fell ill and did not have an opportunity to reply.

Second; I posted this same message three days ago and for some unknown
reason, it did not show up on the mailing list (?).

Finally, thanks to Emily and Bruno for supplying suggestions and
having to make educated guesses or do crystal-ball gazing... apologies
for not phrasing or constructing my original question very clearly.

Now back to the problem...

This _is_ a somewhat artificially constructed problem as I am trying
to get a bearing on how to do this in my actual code, without getting
bogged down in all its nuances.  Nonetheless, this is a very good
parallel to the situation I am dealing with.

I am not trying to calculate an _actual_ discount here (although the
code supplied by Emily may be helpful at some point) - rather I am
trying to figure how to ask a question (i.e write a query) that has a
True/False answer - which I would state loosely in English "does this
qualify for a discount"? or, more explicitly "does the Passenger's
membership of (one or more) Alliances match any of the Airline's
membership of (one or more) Alliances"?

To expand further:

Case 1: If Passenger 57 has membership of Alliance==Pacific and
Alliance==European, then according to the situation postulated above
the answer should be "False".
Case 2: If, however, Passenger 57 has membership of Alliance==Pacific
and Alliance==Star, then the answer would be "True" (because AIA also
has membership of Alliance==Star).

I was hoping there would be a simple "one liner" that could give this
result... I am more looking for guidance in how to do this kind of
querying with the Django ORM rather than help with model or database
construction.

Thanks again - I will try and clarify more quickly in future.

Derek

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



Re: Passenger 57 - a Django query problem

2010-02-21 Thread Sithembewena Lloyd Dube
Thank you everybody. Chapter closed.

On Sun, Feb 21, 2010 at 4:11 AM, Steven Elliott Jr
wrote:

> I've always found both the Django and Python communities to be among the
> friendliest and most helpful. Please be kind to one another and respectful
> of everyones comments. We are here to support one another in our efforts to
> better our django skills and to better the community and project as a whole.
> Let's not start bickering amongst ourselves...
>
> Best,
> Steven Elliott
>
> Sent from my iPhone
>
>
> On Feb 20, 2010, at 7:19 PM, Russell Keith-Magee 
> wrote:
>
>  On Sun, Feb 21, 2010 at 4:11 AM, Sithembewena Lloyd Dube
>>  wrote:
>>
>>> I wonder what Atamert the peacemaker has to say now, since the person to
>>> whose defense he came admitted he was wrong. Amazing to note that Atamert
>>> noticed my directness to Bruno, but did not notice how nasty Bruno was to
>>> other respondents (namely Emily and Derek).
>>>
>>> What have you to say, o' wise Atamert?
>>>
>>
>> Ok, I'm stepping in here.
>>
>> Emily is right - this sort of tone is *exactly* what we don't want on
>> Django users. Django-users has historically been a very friendly
>> place. I don't want that to change.
>>
>> Bruno; Lloyd; Atamert -  at this point, I don't care who started it.
>> When you wrestle in mud, everyone gets dirty - even the bystanders. So
>> Stop. Now.
>>
>> If you want to have some petty name calling argument, take it somewhere
>> else.
>>
>> If you persist in posting to django-users with anything other than
>> helpful responses to the original question, I will start banning
>> accounts.
>>
>> Yours,
>> Russ Magee %-)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

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



How to make the login forms available to the entire site?

2010-02-21 Thread Patrick
I thought that if I put the login forms on the base template and then
extend all others from that base template, the login forms would be
available all the way through. But there is a problem: the login forms
are only displayed if the url is processed by the 'login' view. That
login view provides the forms needed for authentication, among other
things.

The thing is, what I want is to allow user to authenticate no matter
what page from the site he is visitting. How can that be done?

Many thanks in advance,

Patrick Steiger

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



Re: what if I need to use two objects to get a third object in my templates?

2010-02-21 Thread Jeremy Dillworth
You could also put a columns property onto each person object.

Given the models:

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

class DataPoint(models.Model):
person = models.ForeignKey(Person)
value = models.IntegerField()

and a view named list:

def list(request):
people = Person.objects.all()
for p in people:
p.columns = [None, None, None]
for c in DataPoint.objects.filter(person=p, value__gt=4):
p.columns.append(c)

return render_to_response('people/listing.html',
dict(people=people))

(the columns property above is a bit contrived, I think given your
situation--needing a certain number of columns--you'd need some logic
to put None into columns whose DB value was greater than what you
wanted, that way each person's columns property has the same number of
elements and things will line up)

You could then have a pretty simple view:



{% for person in people %}

{{ person.name }}
{% for col in person.columns %}
{% if col %}
{{ col.value }}
{% else %}
(blank)
{% endif %}
{% endfor %}

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



Re: Do Django TestCases reload fixtures on every method?

2010-02-21 Thread bobhaugen
On Feb 21, 9:43 am, Russell Keith-Magee 
wrote:
> It sounds like what you actually want to write is one long test,
> rather than N order dependent short tests. If you want to break things
> into methods for the sake of clarity/code organization, you can - just
> break the test_* entry method into smaller parts:
>
> class MyTest(TestCase):
>
>     def test_long_test(self):
>         self._part1()
>         self._part2()
>         ...
>         self._partN()
>
>     def _part1(self):

Got it.  Thanks, that is exactly what I need to do in a couple of
cases.  Won't be really long tests, just 2 parts per.

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



Re: Do Django TestCases reload fixtures on every method?

2010-02-21 Thread Russell Keith-Magee
On Sun, Feb 21, 2010 at 11:20 PM, bobhaugen  wrote:
> I see here http://toastdriven.com/fresh/whats-wrong-django-slight-return/
> a claim that "TestCase-style tests truncate and reload all the
> fixtures in your database on every test method".
>
> Is that true?

Yes. From the docs [1]:
"""
This flush/load procedure is repeated for each test in the test case,
so you can be certain that the outcome of a test will not be affected
by another test, or by the order of test execution.
"""
[1] http://docs.djangoproject.com/en/dev/topics/testing/#fixture-loading

> If so, how would I create a series of test methods that build on each
> other: for example, one view test creates an object that then will be
> retrieved by the next view test?

You wouldn't. :-)

Each test in a unittest TestCase is supposed to stand alone. You
should be able to run any single test from the suite, or any subset of
tests, in any order, and get the same passes or failures.

Tests *shouldn't* be order dependent.

It sounds like what you actually want to write is one long test,
rather than N order dependent short tests. If you want to break things
into methods for the sake of clarity/code organization, you can - just
break the test_* entry method into smaller parts:

class MyTest(TestCase):

def test_long_test(self):
self._part1()
self._part2()
...
self._partN()

def _part1(self):


Better still, write separate test cases, with separate test fixtures.

 1) CreateTestCase, starting with an empty database, checking that you
can create new objects
 2) EditTestCase, starting with a populated database, checking that
you can edit an existing object. Each edit operation starts with the
same starting point.

Yours,
Russ Magee %-)

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread Atamert Ölçgen
On Sunday 21 February 2010 16:16:56 Amps wrote:
> ok i had read, but was unclear ... ok, now , i am not using admin
> module.
> but can we create a model in model.py which doesnt reflect any table/
> columns in the database, but should reflect a report columns.
AFAIK no.

A practical approach could be to create a normal model that points to a normal 
table and then save your analytic data on it. It doesn't matter whether the 
data is coming from a Queryset or raw SQL, you can 
MyModel.objects.create(**my_data) as long as you create a my_data dict for 
each entry. (you don't even have to save via ORM, but it's safer)

Perhaps we can help better if you tell us what **exactly** you are trying to 
achieve and why you need a tableless model.


-- 
Saygılarımla,
Atamert Ölçgen

 -+-
 --+
 +++

www.muhuk.com
mu...@jabber.org

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



Do Django TestCases reload fixtures on every method?

2010-02-21 Thread bobhaugen
I see here http://toastdriven.com/fresh/whats-wrong-django-slight-return/
a claim that "TestCase-style tests truncate and reload all the
fixtures in your database on every test method".

Is that true?

If so, how would I create a series of test methods that build on each
other: for example, one view test creates an object that then will be
retrieved by the next view test?

(That's what appears to be happening to a series of tests I created
using Eric Holscher's TestMaker.  Each method appears to be starting
from the original fixture, rather than the results of the previous
method.)

If that is not true, never mind, I am doing something else wrong.

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread Amps
ok i had read, but was unclear ... ok, now , i am not using admin
module.
but can we create a model in model.py which doesnt reflect any table/
columns in the database, but should reflect a report columns.

On Feb 21, 7:15 pm, Amps  wrote:
> ok i had read, but was unclear ... ok, now , i am not using admin
> module.
> but can we create a model model.py which doesnt reflect any table/
> columns in the database, but should reflect a report columns.
>
> On Feb 21, 5:43 pm, Shawn Milochik  wrote:
>
> >  From your question, it is clear that you don't understand what the  
> > admin app is. At least do the Django tutorial before you start asking  
> > how to do things.
>
> > Your question is like asking how to use PHPMyAdmin to create this  
> > report.
>
> > Shawn

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread Amps
ok i had read, but was unclear ... ok, now , i am not using admin
module.
but can we create a model model.py which doesnt reflect any table/
columns in the database, but should reflect a report columns.

On Feb 21, 5:43 pm, Shawn Milochik  wrote:
>  From your question, it is clear that you don't understand what the  
> admin app is. At least do the Django tutorial before you start asking  
> how to do things.
>
> Your question is like asking how to use PHPMyAdmin to create this  
> report.
>
> Shawn

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



Re: How to Create models with columns not corresponding to database.

2010-02-21 Thread Shawn Milochik
From your question, it is clear that you don't understand what the  
admin app is. At least do the Django tutorial before you start asking  
how to do things.


Your question is like asking how to use PHPMyAdmin to create this  
report.


Shawn 
 


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



How to Create models with columns not corresponding to database.

2010-02-21 Thread Amps
Hi

I am new to Django.
I am trying to use admin module to generate some reports from data in
Mysql database.
The query is a complex query which involves group by and joins.
The resulting columns of the query are not in  database, since they
are custom/created during the query.

I want to create a model only for this report, and this model will not
point to any table but will only have columns (created during query).

steps i followed:
i have created a model in models.py called

class GR(models.Model):
crt_date = models.CharField(max_length=10);
genre = models.CharField(max_length=20);
repManager = grreport()

and registered in admin.py in my application.
I created a ModelAdmin also for this.

How should i go about ... creating a custom report (Accesing just data
from the database and show using admin intrerface) ...

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



Re: Django CMS

2010-02-21 Thread @ Rocteur CC


On 21 Feb 2010, at 04:38, Shawn Milochik wrote:

I used the same comparison you did, and I ended up going with Django- 
CMS. I like it a lot.


As for importing the content, that should be pretty easy. Once you  
see how Django-CMS works you'll just need to make a simple HTML  
template and then transfer the data from your old database into the  
appropriate places.


However, if you only just discovered Django this weekend, I think  
there will be a learning curve you need to overcome before trying to  
understand Django-CMS (or any other large reusable Django app). I  
recommend reading "The Definitive Guide to Django," and  
supplementing it with questions on this list. In that order -- if  
you ask questions here before doing the reading yourself you'll just  
end up dependent on others and they'll lose interest in doing your  
work for you.


Welcome to Django! I did Perl before Python as well, and now Python  
is my favorite language, by far. Also, as has been noted many times  
before, if you're not that comfortable with Python, a lot of your  
questions about how to do something 'in Django' is really how to do  
it in Python. Django is Python. I hope my rambling is helpful.


Shawn


Thanks very much for your advice Shawn and Timothy.

Taking your advice I will keep my first priority to continue studying  
Python, at the moment I'm reading Building Skills in Python by Steven  
F. Lott. (I'm open to suggestions if you have other books I should be  
reading) Once I'm comfortable with Python I'll read "The Definitive  
Guide to Django" as you suggested. I've already installed Django on my  
Server and ran the tutorial part one and tow and so I will play with  
it in parallel.


Thanks for the advice and the Welcome, I'm excited about learning  
Python, if only it was accepted at work I could start writing in  
Python instead of Perl but at the moment Python is not yet recognized  
by our build system!


Thanks and Regards,

Jerry

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



Re: Treat two fields as one in a queryset

2010-02-21 Thread shacker
Thanks for the suggestions. The "convert to list" approach sounded
appealing, but I had to get back a queryset since this was for an RSS
feed.

After reading up more, finally decided it might actually make more
sense to go with a bit of denormalization and create a "combined_date"
field on the model, with a custom save() method that keeps the right
thing in that new field.

def save(self):
if self.completed == True:
 self.combined_date = self.completed_date
else:
self.combined_date =  self.created_date

super(Item, self).save()

That turned out to be trivial, gave me a single date field to sort on,
and kept everything in a queryset.

Thanks,
./s

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