Re: distinct() ?

2010-07-21 Thread jaymzcd
"I've solved the problem by passing the returned dictionary through my
own distinct() function which strips out duplicates."

Don't roll your own implementations unless you actually really need
to! It's bad practise and can introduce added complexity to your
solution. The .distinct() call will work fine, you just need to order
correctly.

Also, if you needed to do something in sql that you couldnt get to
work via the django ORM i would use the new raw sql features so that
you at least get back queryset objects that you can use "as is" rather
than converting & flattening it to a dict and whatnot.

On 21 July, 18:29, rmschne  wrote:
> Yep.  (as I slap my forehead).
>
> I read that but erroneously concluded that since I had no sort_by on
> the query, I didn't pursue it.  There is a default ordering in the
> model.
> I've solved the problem by passing the returned dictionary through my
> own distinct() function which strips out duplicates.
>
> 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: Plese guide to solve this

2010-07-21 Thread jaymzcd
I'm going to guess you have been following along with the 
http://www.djangobook.com/
site. It was great in the day but *do not use that* now-a-days as it
covers 0.96. There have been significant changes, one of which is the
maxlength to max_length on CharFields. Stick with the particular
version you are using from docs.djangoproject.com. Even changes from
1.1 to 1.2 are significant enough that reading the wrong version's
docs can give you headaches.

On 21 July, 18:05, Subhranath Chunder  wrote:
> Must be using very old docs:
>
> Use these instead:http://docs.djangoproject.com/en/dev/
>
> Thanks,
> Subhranath Chunder.
>
>
>
> On Wed, Jul 21, 2010 at 8:47 PM, n3ph  wrote:
> >  Another one who's confused about all the deep API-Changes in Django :-(
>
> > But reading the doc's is very helpful to preventing you from thees traps...
>
> > Am 21.07.2010 17:04, schrieb euan.godd...@googlemail.com:
>
> >  The traceback tells you exactly what the problem is. The correct kwarg
> >> is max_length
>
> >> On Jul 21, 2:00 pm, balu  wrote:
>
> >>> Respected sir
>
> >>> This is balu studying B.Tech third year. I started working on django
> >>> in order to create dynamic website. My Python version is 2.6.5. While
> >>> I'm using creating a app the following error has displayed in the
> >>> command line.
>
> >>> /
>
> >>> ***
> >>>  **/
>
> >>> Microsoft Windows XP [Version 5.1.2600]
> >>> (C) Copyright 1985-2001 Microsoft Corp.
>
> >>> C:\Documents and Settings\Administrator>cd c:\
>
> >>> C:\>cd projects
>
> >>> C:\projects>manage.py startapp books
> >>> 'manage.py' is not recognized as an internal or external command,
> >>> operable program or batch file.
>
> >>> C:\projects>cd mysite
>
> >>> C:\projects\mysite>python manage.py startapp books
>
> >>> C:\projects\mysite>cd books
>
> >>> C:\projects\mysite\books>div
> >>> 'div' is not recognized as an internal or external command,
> >>> operable program or batch file.
>
> >>> C:\projects\mysite\books>dir
> >>>  Volume in drive C has no label.
> >>>  Volume Serial Number is 3474-4CF2
>
> >>>  Directory of C:\projects\mysite\books
>
> >>> 07/21/2010  04:59 PM            .
> >>> 07/21/2010  04:59 PM            ..
> >>> 07/21/2010  04:59 PM                60 models.py
> >>> 07/21/2010  04:59 PM               537 tests.py
> >>> 07/21/2010  04:59 PM                27 views.py
> >>> 07/21/2010  04:59 PM                 0 __init__.py
> >>>                4 File(s)            624 bytes
> >>>                2 Dir(s)  27,813,937,152 bytes free
>
> >>> C:\projects\mysite\books>cd C:\projects\mysite
>
> >>> C:\projects\mysite>python manage.py validate
> >>> Traceback (most recent call last):
> >>>   File "manage.py", line 11, in
> >>>     execute_manager(settings)
> >>>   File "C:\python26\lib\site-packages\django\core\management
> >>> \__init__.py", line
> >>> 438, in execute_manager
> >>>     utility.execute()
> >>>   File "C:\python26\lib\site-packages\django\core\management
> >>> \__init__.py", line
> >>> 379, in execute
> >>>     self.fetch_command(subcommand).run_from_argv(self.argv)
> >>>   File "C:\python26\lib\site-packages\django\core\management\base.py",
> >>> line 191,
> >>>  in run_from_argv
> >>>     self.execute(*args, **options.__dict__)
> >>>   File "C:\python26\lib\site-packages\django\core\management\base.py",
> >>> line 218,
> >>>  in execute
> >>>     output = self.handle(*args, **options)
> >>>   File "C:\python26\lib\site-packages\django\core\management\base.py",
> >>> line 347,
> >>>  in handle
> >>>     return self.handle_noargs(**options)
> >>>   File "C:\python26\lib\site-packages\django\core\management\commands
> >>> \validate.p
> >>> y", line 9, in handle_noargs
> >>>     self.validate(display_num_errors=True)
> >>>   File "C:\python26\lib\site-packages\django\core\management\base.py",
> >>> line 245,
> >>>  in validate
> >>>     num_errors = get_validation_errors(s, app)
> >>>   File "C:\python26\lib\site-packages\django\core\management
> >>> \validation.py", lin
> >>> e 28, in get_validation_errors
> >>>     for (app_name, error) in get_app_errors().items():
> >>>   File "C:\python26\lib\site-packages\django\db\models\loading.py",
> >>> line 146, in
> >>>  get_app_errors
> >>>     self._populate()
> >>>   File "C:\python26\lib\site-packages\django\db\models\loading.py",
> >>> line 61, in
> >>> _populate
> >>>     self.load_app(app_name, True)
> >>>   File "C:\python26\lib\site-packages\django\db\models\loading.py",
> >>> line 78, in
> >>> load_app
> >>>     models = import_module('.models', app_name)
> >>>   File "C:\python26\lib\site-packages\django\utils\importlib.py", line
> >>> 35, in im
> >>> port_module
> >>>     __import__(name)
> >>>   File "C:\projects\mysite\..\mysite\books\models.py", line 5, in
> >>> 
> >>>     class Publisher(models.Model):
> >>>   File "C:\projects\mysite\..\mysite\books\models.py", 

Re: distinct() ?

2010-07-21 Thread jaymzcd
I'm guessing your Members model is referencing the User model? Check
the ordering as related models will influence your distinct. If your
Members model has its own ordering that will also come into effect
even though your picking your value out explicitly:

"If you order by fields from a related model, those fields will be
added to the selected columns and they may make otherwise duplicate
rows appear to be distinctThe moral here is that if you are using
distinct() be careful about ordering by related models. Similarly,
when using distinct() and values() together, be careful when ordering
by fields not in the values() call."

Member.objects.values('status').order_by('status').distinct()

Should give the correct count.

-- 
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: URL to specify when accessing subdomains using Django

2010-07-20 Thread jaymzcd
Have you been through everything here: 
http://docs.djangoproject.com/en/dev/ref/contrib/sites/
? It goes through the whole process of working with the sites
framework, its even encouraged to be used when running just a single
site. It sounds like you are making it more complicated that needs be.
If you just want to do one separate action for a certain subdomain you
can check the contents of request.META['SERVER_NAME'] and switch on
that in your view, but it sounds like you want to do separate things
per subdomain. The django docs really go go through it all.

The purpose of the sites framework is to have different domains that
may or may not have a completely different look and feel share the
same common core code. Thats why they have they're own settings.py
files, they're essentially separate sites with a common underbelly.

jaymz

On Jul 20, 5:55 am, nandu <navanitach...@gmail.com> wrote:
> Could someone please help me and answer my question in the last email?
>
> Thank you.
> Nanda
>
> On Jul 19, 9:52 pm, nandu <navanitach...@gmail.com> wrote:
>
>
>
> > Dear All,
>
> > I have now set up my subdomains as separate sites using the sites
> > framework but I have a few queries:
>
> > 1. Does each site really require a separate django instance or can I
> > run all the subdomains on one instance? I have seven subdomains and
> > running seven django instances seems wasteful.
>
> > 2. Currently I have a Django app corresponding to each subdomain since
> > each subdomain now needs a unique settings.py file is it ok to have
> > the settings file within the app or is it necessary for the app to
> > become a project in this case a project within a project?
>
> > 3. Is it OK for me to put all my urls in the one single urls.py file
> > or would it be best to separate them on a per app basis.
>
> > I just need a pointer in the right direction since I have never used
> > the sites framework before, and as far as I know I could not find too
> > many tutorials or howtos on how to use it either.
>
> > Thank you for all the help all of you have given me so far.
>
> > Yours sincerely,
> > Nanda
>
> > On Jul 19, 3:00 pm,nandu<navanitach...@gmail.com> wrote:
>
> > > Thank you to all whohave replied.
>
> > > I will give the sites framework an honest effort and solve my problem.
>
> > > Thank you very much for your time and effort. :-)
>
> > > Nanda
>
> > > On Jul 19, 2:42 pm, jaymzcd <jaym...@googlemail.com> wrote:
>
> > > > Like Daniel & Steve have said already, urls.py only deals with the
> > > > path component of the URL, not the domain. The sites framework is what
> > > > you need to use, its pretty simple. All you really need to do is
> > > > something like:
>
> > > > 1. in urls.py match the URL you want that is common for both
> > > > subdomains
> > > > 2. in your view for that pattern get the current site id
> > > > 3. based on what subdomain (site) is returned execute the appropriate
> > > > function
>
> > > > urls.py *cant* know about the subdomain.  If you have an aversion to
> > > > using the sites framework you could maybe hack it to work by looking
> > > > at the contents of request.META['SERVER_NAME'] in your view but i
> > > > wouldnt do that. Check the sites framework...
>
> > > > jaymz
>
> > > > On Jul 19, 7:05 am,nandu<navanitach...@gmail.com> wrote:
>
> > > > > Thank you to all who have replied to my query.
>
> > > > > I do not think I need to use the sites framework because my subdomains
> > > > > are not on different servers and hence are not really different sites.
> > > > > Possibly what I am working with are actually pseudo-subdomains and not
> > > > > subdomains in the real sense. I will explain what I am intending to do
> > > > > below:
>
> > > > > Let us say that I have a domain "example.com"
>
> > > > > This site contains subdomains like the following:
>
> > > > > subdomain1.example.com
> > > > > subdomain2.example.com
>
> > > > > and so on.
>
> > > > > In my urls.py if I want to map the subdomain1.example.com to some
> > > > > function and I need to know what regular expression I should use.
> > > > > Another problem I am facing is that I testing this on localhost so I
> > > > > need to get a URL that I believe looks like "subdomain1.127.0.0.1:
> > > > > 8000" instead if &q

Re: should i use django

2010-07-19 Thread jaymzcd
Oh, also, as you sound like you're a coder, the thing I normally try
and sell my desktop-side friends to django for web development is that
you have the entire python library sitting there for you. You can code
however you like, the way you like. You just need to remember that
your eventual output is going to be an HTML page of some sort rather
than a GUI. You don't have to "think web" so to speak, you can work
with your data as you would right up until your sending it off to
render on the browser.

I find a lot of my mates tend to think because its a web framework
they have to throw away the way they "normally" code. It's one of the
reasons I enjoy using python for web apps, we write a lot of code here
that has crossover use so we can take that same code and adapt it for
other internal projects here.

Good luck!

On Jul 19, 10:45 pm, jaymzcd <jaym...@googlemail.com> wrote:
> If you dont really need to do anything web specific bar displaying
> some XML you could use something like cherrypy - its a python
> framework for building web apps very much from the ground up. That
> said, it's so easy to use django to handle a few urls and it won't add
> much overhead so it's a fine choice. Either way, I find it less
> overkill than doing it myself.
>
> For graphing I would have a look at flot.js or the google chart api's
> (both on google code). They're pretty easy to use. You can use
> python's xml minidom to parse your data, django to handle the urls you
> want to a basic view and then output your transformed xml as json for
> flot or google to draw a graph for you.
>
> If you're interested in a "lighter" framework though have a look at
> cherrypy.
>
> jaymz
>
> On Jul 19, 7:22 pm, gary_p <gary.pa...@gmail.com> wrote:
>
>
>
> > On Jul 16, 9:56 pm, gary_p <gary.pa...@gmail.com> wrote:
>
> > > On Jul 16, 7:46 pm, uday <ukapa...@gmail.com> wrote:
>
> > > > Hi,
>
> > > >    I need to design a simple web app that would mostly display data
> > > > from an xml file in different forms(like graphs,charts etc) after some
> > > > processing.I have to do this in two weeks
> > > >    I don't have any web development background.I am more of a systems
> > > > programmer and thus use C/C++ a lot.But since i have used and liked
> > > > python i turned to django.Have i made the right choice ? Is django too
> > > > much complexity for what i want to do ? Are there lighter options that
> > > > i can turn to ?
>
> > > > Udayan
>
> > > I have a question that is so similar to this that I've decided to jump
> > > on this thread.
>
> > > I program scientific desktop apps in python, usually using the
> > > Enthought Tool Suite.  I know nothing about web programming.
> > > I'm now considering running my apps on some kind of server and
> > > controlling with a browser.  I read data from instruments, and/or
> > > enter parameters by hand, then run an app that crunches the data
> > > producing graphs and, in my dreams, animations.  Can Django do this
> > > smoothly?  Is it the wrong tool for this kind of thing? What would be
> > > the right tool?
>
> > > I've never in my life needed or used a database, but most Django
> > > tutorials I see involve databases.  I store data in hdf5 files.  Are
> > > there examples of Django programing that don't depend on a database?
> > > Are databases an essential part of using Django?  (I really would
> > > rather not learn about databases for the sole purpose of understanding
> > > a tutorial.)  Should I be looking at other solutions (pyjamas?)  ?
>
> > > -gary
>
> > If anyone else finds themselves looking for a non-database starting
> > point:  I just discovered that the django book starts off without
> > using databases.  For me, much easier to get through than the tutorial
> > on the web site.
>
> > -gary

-- 
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: should i use django

2010-07-19 Thread jaymzcd
If you dont really need to do anything web specific bar displaying
some XML you could use something like cherrypy - its a python
framework for building web apps very much from the ground up. That
said, it's so easy to use django to handle a few urls and it won't add
much overhead so it's a fine choice. Either way, I find it less
overkill than doing it myself.

For graphing I would have a look at flot.js or the google chart api's
(both on google code). They're pretty easy to use. You can use
python's xml minidom to parse your data, django to handle the urls you
want to a basic view and then output your transformed xml as json for
flot or google to draw a graph for you.

If you're interested in a "lighter" framework though have a look at
cherrypy.

jaymz

On Jul 19, 7:22 pm, gary_p  wrote:
> On Jul 16, 9:56 pm, gary_p  wrote:
>
>
>
>
>
> > On Jul 16, 7:46 pm, uday  wrote:
>
> > > Hi,
>
> > >    I need to design a simple web app that would mostly display data
> > > from an xml file in different forms(like graphs,charts etc) after some
> > > processing.I have to do this in two weeks
> > >    I don't have any web development background.I am more of a systems
> > > programmer and thus use C/C++ a lot.But since i have used and liked
> > > python i turned to django.Have i made the right choice ? Is django too
> > > much complexity for what i want to do ? Are there lighter options that
> > > i can turn to ?
>
> > > Udayan
>
> > I have a question that is so similar to this that I've decided to jump
> > on this thread.
>
> > I program scientific desktop apps in python, usually using the
> > Enthought Tool Suite.  I know nothing about web programming.
> > I'm now considering running my apps on some kind of server and
> > controlling with a browser.  I read data from instruments, and/or
> > enter parameters by hand, then run an app that crunches the data
> > producing graphs and, in my dreams, animations.  Can Django do this
> > smoothly?  Is it the wrong tool for this kind of thing? What would be
> > the right tool?
>
> > I've never in my life needed or used a database, but most Django
> > tutorials I see involve databases.  I store data in hdf5 files.  Are
> > there examples of Django programing that don't depend on a database?
> > Are databases an essential part of using Django?  (I really would
> > rather not learn about databases for the sole purpose of understanding
> > a tutorial.)  Should I be looking at other solutions (pyjamas?)  ?
>
> > -gary
>
> If anyone else finds themselves looking for a non-database starting
> point:  I just discovered that the django book starts off without
> using databases.  For me, much easier to get through than the tutorial
> on the web site.
>
> -gary

-- 
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: URL to specify when accessing subdomains using Django

2010-07-19 Thread jaymzcd
Like Daniel & Steve have said already, urls.py only deals with the
path component of the URL, not the domain. The sites framework is what
you need to use, its pretty simple. All you really need to do is
something like:

1. in urls.py match the URL you want that is common for both
subdomains
2. in your view for that pattern get the current site id
3. based on what subdomain (site) is returned execute the appropriate
function

urls.py *cant* know about the subdomain.  If you have an aversion to
using the sites framework you could maybe hack it to work by looking
at the contents of request.META['SERVER_NAME'] in your view but i
wouldnt do that. Check the sites framework...

jaymz

On Jul 19, 7:05 am, nandu  wrote:
> Thank you to all who have replied to my query.
>
> I do not think I need to use the sites framework because my subdomains
> are not on different servers and hence are not really different sites.
> Possibly what I am working with are actually pseudo-subdomains and not
> subdomains in the real sense. I will explain what I am intending to do
> below:
>
> Let us say that I have a domain "example.com"
>
> This site contains subdomains like the following:
>
> subdomain1.example.com
> subdomain2.example.com
>
> and so on.
>
> In my urls.py if I want to map the subdomain1.example.com to some
> function and I need to know what regular expression I should use.
> Another problem I am facing is that I testing this on localhost so I
> need to get a URL that I believe looks like "subdomain1.127.0.0.1:
> 8000" instead if "127.0.0.1:8000/subdomain1" and get urls.py to
> recognise this. I know that I may need to write a middleware class
> that intercepts every URL which I have implemented but I have no idea
> how to specify the URL in my href attribute in my link.
>
> so that it is taken as subdomain1.127.0.0.1: 8000 instead of
> 127.0.0.1:8000/subdomain1 which is incorrect.
>
> FYI
> I am working on a Ubuntu Linux machine and the Django development
> server.
>
> I am sorry if I have misunderstood your answers above but IMHO I do
> not think I need to use the sites framework as this is a fairly simple
> thing.
>
> Thank you.
>
> Yours sincerely,
> Nanda
>
> On Jul 18, 1:47 am, Steve Holden  wrote:
>
>
>
> > On 7/17/2010 12:38 PM, nandu wrote:
>
> > > Dear Folks,
>
> > > After researching the topic of using subdomains with Django I have
> > > found that it is does not seem to be a straight forward thing to do.
>
> > > I have also found many websites showing methods of how to do this, but
> > > there is one aspect that none of them seem to explain. That is how
> > > does one specify the URL for the subdomain in urls.py if I had a
> > > subdomain like "something.example.com".
>
> > > I would also appreciate it if someone could point me in the right
> > > direction in terms of how to use subdomains with django as each
> > > website seems to specify a different method, and I have no idea which
> > > one is the best. The URLs of the websites I have looked at are below:
>
> > >http://uswaretech.com/blog/2008/10/using-subdomains-with-django/
>
> > >http://thingsilearned.com/2009/01/05/using-subdomains-in-django/
>
> > >http://www.nerdydork.com/django-accounts-on-subdomains.html
>
> > >http://djangosnippets.org/snippets/1119/
>
> > > I am also looking for a solution that avoids making many changes to
> > > the web application when it is about to be deployed.
>
> > > Please forgive my ignorance in this matter.
>
> > Servers in different subdomains are different sites, so you may want to
> > read up about Django's sites framework.
>
> >    http://docs.djangoproject.com/en/dev/ref/contrib/sites/
>
> > regards
> >  Steve
> > --
> > Steve Holden           +1 571 484 6266   +1 800 494 3119
> > DjangoCon US September 7-9, 2010    http://djangocon.us/
> > See Python Video!      http://python.mirocommunity.org/
> > Holden Web LLC                http://www.holdenweb.com/
>
> > --
> > Tel/Toll-free:       +1 571 484 6266     +1 800 494 3119
> > DjangoCon US September 7-9, 2010    http://djangocon.us/
> > See Python Video!      http://python.mirocommunity.org/
> > Holden Web LLC                http://www.holdenweb.com/

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

2010-07-15 Thread jaymzcd
There's a few ways to do it. An easy way if your just serving up some
css, images etc is to symlink your admin_media folder in your media
directory to the media folder in your django admin install:

[ja...@293230-app1 ~]$ ls /var/django-projects/udox/public/media/ -l
total 28
lrwxr-xr-x  1 root  root 62 Jun 25 09:34 admin -> /usr/local/
pyvans/lib/python2.6/site-packages/grappelli/media/
drwxr-xr-x  2 jaymz apache 4096 Jul  9 06:12 css
drwxr-xr-x 32 jaymz apache 4096 Jun 14 11:21 galleries

And in settings:
ADMIN_MEDIA_PREFIX = '/media/admin/'

This means anyone can access your admin css/js files etc, it's
unlikely to be an issue for you.

Another way is to set your admin_media_prefix to something like /
admin_media/ and then in your apache conf set an alias for it.

Alias /admin_media/ /usr/local/pyvans/lib/python2.6/site-packages/
grappelli/media/

Both work and are pretty painless. Your paths will be different of
course (i'm using django-grappelli as a backend theme)

jaymz

On Jul 15, 2:04 am, lupuscramus  wrote:
> Hi.
>
> I've made an app (django 1.2) which works fine for tests, on my laptop with
> the django built-in web server.
>
> I want to put in production my app, with Apache and mod_wsgi.
>
> I've verified I've django 1.2 on the production server.
>
> The problem is I've no images. When I connect to the admin site (generated bu
> Django), I can see "Django Administration", the fields "connexion" and
> "password", but there is not the images of the interfaces - it's a simple
> page.
>
> I use a template dir to replace Django Administration by my own title, but
> even I disable the template dir, I have no images.
>
> My server uses Debian, and I've installed Django by aptitude. My files are
> located in /usr/share/pyshared/django.
>
> I can see on the documentation of django about deploying an app with apache
> and wsgi that I should have another web server, or configure apache for the
> media files. It could be the problem  (Images are they media files ?).
>
> In fact, I don't understand really this part of the doc. Are the defaults
> templates of django concerned by this part ?
>
> 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 handle Jaywalking - parsing a comma-delimited value in field and do lookups (1,4,5,6...)

2010-07-14 Thread jaymzcd
One idea that springs to mind is to add a property method to your
model that returns that self.group field as a list. With that list you
could add another property that returned all the actual group items.
Then write a custom admin view for add/change/view of that model which
works with the group instead. That way you can leave the data intact
but provide a management interface on top. Likewise you can in your
front end use your new propertys to work with the groups related to
that user. Whatever you do will probably involve a layer of work on
top.

So in your model I'd add something like:

@property
def group_list(self):
return self.group.split(',')

@property
def real_groups(self):
return Group.objects.all().filter(pk__in=self.group_list)

For writing a custom admin view this is to do with something a little
different but it's pretty comprehensive in terms of writing a
completely custom admin view:

http://elo80ka.wordpress.com/2009/10/28/using-a-formwizard-in-the-django-admin/

jaymz


On Jul 13, 12:10 pm, Snaky Love  wrote:
> Hi,
>
> I have an "interesting" problem here - in a given mysql database
> scheme some sql wizard used comma-separated values in a text-field and
> with that values lookups have to be done. The data itself is simple
> numbers like 1,34,25,66,78,134 and so on. So what I have is something
> like this:
>
> id | username | groups         | more...
> -
> 1 | name        | 1,23,4,55,6  | ...
> 2 | name2      | 3,2,4,5        | ...
>
> The groups string can be very long. there is also a table "groups"
> with "id, name", as expected.
>
> Yes, this is bad design. No, I can not immediately change the design,
> I will try to, but atm I have to handle the situation as it is.
>
> Of course normally this would be solved with an intersection table and
> a many-to-many relation. For anybody interested: there is a book by
> Bill Karwin called "SQL Antipatterns" - he names the described design
> Jaywalking and it is the first antipattern in the book. I was
> surprised to find it in real life
>
> So my question is: how to handle this with django? I really would
> like to use django to build a nice management interface on top of that
> tables, but currently I do not know how to go on with that jaywalking
> antipattern in my way.
>
> My first idea was to create my own intersection table - but the
> process of [re-]converting data does only work in a
> static environment - the data is heavily used and so
> transformations of tabledata would be neccassery on every request to
> mirror the live situation...too slow! So I am looking for a good way
> to
> implement some kind of layer that would translate this field for
> django into an intersaection table so that I can use models - will
> this work?
>
> What do you think? How to handle this?
>
> Thank you very much for your attention!
> Snaky

-- 
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: Comparing DateTimeField to datetime.now()

2010-07-14 Thread jaymzcd
This code works fine for me:

In [1]: from gallery.models import Gallery
In [2]: g = Gallery.objects.all()[0]
In [3]: g.created_at
Out[3]: datetime.datetime(2010, 4, 1, 7, 11, 51)
In [4]: import datetime
In [5]: n = datetime.datetime.now()
In [6]: g.created_at > n
Out[6]: False
In [7]: [g.created_at, n]
Out[7]:
[datetime.datetime(2010, 4, 1, 7, 11, 51),
 datetime.datetime(2010, 7, 14, 8, 53, 22, 960271)]

Are you sure your self.date has been initialized and isn't None?



On Jul 14, 4:43 pm, Chris McComas  wrote:
> This is my model, I'm trying to set it so that if the game is in the
> future, based on the field date, then to return True, if not return
> False.
>
> http://dpaste.com/218111/
>
> I am importing datetime in my models.py but for some reason it's
> giving me nothing. I tried displaying future and nothing shows up?
> What have I done 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: Django Install - Won't Import?

2010-07-14 Thread jaymzcd
Sounds like you're quite new to all this. If I was you I'd install
setuptools for windows, it'll make adding packages a lot easier for
you.
http://thinkhole.org/wp/2007/02/01/howto-install-setuptools-in-windows/

The "setup.py install" command, you should have "python" before that
so it actually executes.

You can of course always just extract the django source code and drop
it in your python packages also. If you execute "python" at the
command line and try "import django" it should work. I haven't tried
installing python etc on windows for a couple of years but my collegue
found this guide useful for setting up his django install on vista:

http://i.justrealized.com/2008/04/08/how-to-install-python-and-django-in-windows-vista/

jaymz

On Jul 14, 1:46 pm, Hayezb  wrote:
> I'm trying to install Django on my laptop but it's not wanting to
> import through the command line. I pointed to the "setup.py install"
> but when I try this notepad comes up with some code and that's it. I
> go and check my Python directory and there are no Django files in
> there.
>
> Any ideas?
>
> 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: Admin Model Validation on ManyToMany Field

2010-07-14 Thread jaymzcd
Hi Heleen,

I think this is because your running the users through an intermediate
model. That changes the way you need to work with the M2M data. You
should be working on the Permission model/objects instead. If you
check out the M2M docs for models via an intermediate:

http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

You'll see the example is pretty much what you have only with Group
instead of Application.

"The only way to create this type of relationship is to create
instances of the intermediate model. Unlike normal many-to-many
fields, you can't use add, create, or assignment (i.e.,
beatles.members = [...]) to create relationships:"

jaymz

On Jul 14, 2:32 pm, Heleen  wrote:
> Thank you for your reply.
>
> Yes I have selected a user and folder.
> I believe ManyToMany fields are always optional (hence many to many).
> So my users and company fields are optional, but my folder field
> isn't.
> When I add a new Application in the Admin I do specify a folder and
> users (if I don't I would at least get a 'Required field' error for
> the folder field).
> I've tested the method above (clean function) with another model that
> has a manytomany field, and it does exactly the same thing, even when
> I really do fill in the data. In fact, if I delibirately throw an
> error and look in the debug info I can see the ManyToMany field data
> being present in the POST data, just like I can when I do the same
> thing with the above models.
>
> Btw, I just noticed a typo in my Folder model description above,
> that's not the issue as it's correct in my original model.
>
> On Jul 14, 2:02 pm, Nuno Maltez  wrote:
>
>
>
> > Hi,
>
> > Just a guess: have you actually selected a user and a folder when
> > submitting the form? I think only valid field are present on the
> > cleaned_data dict, and your users and folder fields are not optional
> > (blank=True, null=True).
>
> > hth,
> > nuno
>
> > On Tue, Jul 13, 2010 at 1:45 PM, Heleen  wrote:
> > > Hello,
>
> > > I have the following classes:
> > > class Application(models.Model):
> > >  users = models.ManyToManyField(User, through='Permission')
> > >  folder = models.ForeignKey(Folder)
>
> > > class Folder(models.Model):
> > >  company = models.ManyToManyField(Compnay)
>
> > > class UserProfile(models.Model):
> > >  user = models.OneToOneField(User, related_name='profile')
> > >  company = models.ManyToManyField(Company)
>
> > > Now when I save application, I would like to check if the users do not
> > > belong to the application's folder's companies.
> > > I have posed this question before and someone came up with the
> > > following sollution:
> > > forms.py:
> > > class ApplicationForm(ModelForm):
> > >    class Meta:
> > >        model = Application
>
> > >    def clean(self):
> > >        cleaned_data = self.cleaned_data
> > >        users = cleaned_data['users']
> > >        folder = cleaned_data['folder']
> > >        if
> > > users.filter(profile__company__in=folder.company.all()).count() > 0:
> > >            raise forms.ValidationError('One of the users of this
> > > Application works in one of the Folder companies!')
> > >        return cleaned_data
>
> > > admin.py
> > > class ApplicationAdmin(ModelAdmin):
> > >    form = ApplicationForm
>
> > > This seems like right the way to go about this. The problem is that
> > > neither the users nor folder fields are in the cleaned_data and I get
> > > a keyerror when it hits the users = cleaned_data['users'] line.
>
> > > I was hoping that someone here could explain to me why these
> > > manytomany fields don't show up in cleaned_data and that someone could
> > > possibly give me a sollution to my problem.
>
> > > Thanks!
> > > Heleen
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

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



Re: Managing static content / basically handling images best practices

2010-07-14 Thread jaymzcd
I typically add a config to apache to ignore my media folder and not
handle it with python so that requests to /media/.* all go straight to
the webserver and don't go via django. I typically have something like
this sitting in my conf's:

   
SetHandler None
Options -Indexes


I'd not bother doing that for the dev environment though unless you've
got your server setup already and its not much hassle.

jaymz

On Jul 14, 3:33 pm, reduxdj  wrote:
> I want to use ImageField for users to upload static content and I need
> a little advice from a some django pros on how to do this in a dev
> enviornment. I notice the disclaimer that django dev server should not
> used to serve static content, or it shouldn't be.  So...
>
> What's the best practice for this then?
> Right now, I love the simplicity of the django dev webserver, should i
> switch the devserver to nginx?
> Does that have the ability to know when i make a change to a python
> file without a server restart necessary?
> Is there anything else I should know.
>
> Thanks so much,
> Patrick

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



google blogger & ooyala video integration (apps)

2010-07-14 Thread jaymzcd
Hi all,

I have been working on a number of projects here at u-dox.com, we're a
very heavy django shop and have been mindful to try and keep as much
of the code generic as possible. A few things which I have written
that might be useful to others are two fairly standalone apps - one
for syncing and using google blogger content via its RSS feeds for any
profile and another to integrate with the Ooyala video hosting
platform.

Both projects are available at github for anyone interested. The
ooyala project can be used without django itself. Both are continuing
works but they are at a point I feel I can share them.

Blogger: http://github.com/jaymzcd/django-blogger
Ooyala: http://github.com/jaymzcd/django-ooyala

More info on both:
http://jaymz.eu/2010/07/integrating-ooyala-in-django-or-in-general/
http://jaymz.eu/2010/06/google-blogger-to-django-integration/

Cheers,
jaymz

-- 
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.



android app for the documentation site

2010-05-28 Thread jaymzcd
Hi All,

I thought some of you with android phones might be interested, I
knocked up a quick app to make browsing the doc site a bit easier for
me. It's in the marketplace for download. It's got some quick links to
topics I tend to lookup a lot. I was thinking of adding in custom
bookmarks and snippets.

http://jaymz.eu/2010/05/django-reference-in-android-market-now/

Any suggestions are welcome,

Cheers,

jaymz

-- 
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 developer position in london

2009-06-30 Thread jaymzcd

Hi all,

I'm a developer at u-dox.com, we run a number of sites such as
spinemagazine.com & crookedtongues.com and have quite a few
development jobs lined up and are now looking for a full time
developer for interview. The job spec is below. If anyone is
interested you can mail either myself (ja...@u-dox.com) or Chris
George (chris.geo...@u-dox.com).

Cheers :)

jaymz

 begin spec 

Web Developer

We are a dynamic, Soho based digital agency looking for a Web
Developer who is comfortable working with Python (Django) and PHP,
particularly as applicable to building robust, scalable E-Commerce
solutions, and has an excellent knowledge of Object Oriented
programming techniques.

The ideal candidate will have great problem solving skills and will be
comfortable working in both the back-end and the front-end (CSS and
JavaScript in addition to Django templates). Additionally a good
understanding of structuring and the maintenance of relational
databases is an advantage.

We work with a varied array of web technologies, so familiarity with
Python, PHP and ASP is a necessity as is a working knowledge of
Actionscript 2and 3 and the ability to build applications that can
integrate seamlessly with Flash.

Responsibilities will include the development and maintenance of
several large Django sites that will be rolled out globally, advising
on technical matters and working with another Django developer.

You will have the opportunity to work on high-traffic sites and build
some cool Web 2.0 features.

SALARY WILL BE IN-LINE WITH EXPERIENCE.

 end spec 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---