Import models from CSV files?

2009-01-05 Thread Victor Hooi

heya,

This question might seem a bit simple, but what's the best way to
instantiate models from .csv files?

Essentially, I have two .csv files. One contains a list of people, and
their access rights (one-to-many). The second .csv file contains a log
of doorway access (just a bunch of sequential lines). I have a simple
python script which imports these two .csv files, does some processing
(the files are quite messy), creates user and access-entry objects,
and produces a reconciliation with a list of exceptions (basically
door entries which aren't in the list of user/access rights). Each
user is just a dictionary, with their username as key, and a tuple of
dictionary objects for their various access rights.

I would like a simple django project to import these logs, instantiate
models, and then basically manage it via the in-built admin interface,
hopefully saving a lot of time =). (will also need to deal with
duplicates). Is there a smart way to go about doing this project, or
any existing addons I can leverage off?

Thanks,
Victor

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



Re: Import models from CSV files?

2009-01-06 Thread Victor Hooi

heya,

Valts, thanks for the reply - that looks interesting, and is similar
in some ways to what I want - definitely going to check out the code.
Basically, I just wanted a simple file-upload form, for the user to
upload the two .CSV files. Then, there's quite a bit of processing to
do on the two files, currently in a small python script.

My question was more along the lines of where should put all of the
logic? Should it be in the model itself, somewhere, and the file-
upload form just passes across the raw data from the .csv files? Where
would the file-handling stuff go? Is it easier to do it via raw SQL,
or via the django models? Any chance of sample code =)?

Cheers,
Victor

On Jan 6, 7:05 pm, "Valts Mazurs"  wrote:
> Hello,
>
> Maybe this app could be helpful for 
> you:http://code.google.com/p/django-batchimport/
>
> If you have to import lots of data I would suggest creating python script
> that reads the files and inserts the data in database either using Django
> ORM or plain SQL. In case of hundreds of thousands of rows I would commit
> the changes to database after number of inserts (e.g., 100) instead of every
> insert.
>
> Best regards,
> --
> Valts
>
> On Tue, Jan 6, 2009 at 07:02, Victor Hooi  wrote:
>
> > heya,
>
> > This question might seem a bit simple, but what's the best way to
> > instantiate models from .csv files?
>
> > Essentially, I have two .csv files. One contains a list of people, and
> > their access rights (one-to-many). The second .csv file contains a log
> > of doorway access (just a bunch of sequential lines). I have a simple
> > python script which imports these two .csv files, does some processing
> > (the files are quite messy), creates user and access-entry objects,
> > and produces a reconciliation with a list of exceptions (basically
> > door entries which aren't in the list of user/access rights). Each
> > user is just a dictionary, with their username as key, and a tuple of
> > dictionary objects for their various access rights.
>
> > I would like a simple django project to import these logs, instantiate
> > models, and then basically manage it via the in-built admin interface,
> > hopefully saving a lot of time =). (will also need to deal with
> > duplicates). Is there a smart way to go about doing this project, or
> > any existing addons I can leverage off?
>
> > Thanks,
> > Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Import models from CSV files?

2009-01-06 Thread Victor Hooi

heya,

Whoops...forgot. I'm also confused on the recommended way to deal with
duplicates? (not duplicate .csv files, but duplicate entries, perhaps
in two different ones.). Just do a plain search for each entry? Or is
there a better way?

On Jan 7, 11:55 am, Victor Hooi  wrote:
> heya,
>
> Valts, thanks for the reply - that looks interesting, and is similar
> in some ways to what I want - definitely going to check out the code.
> Basically, I just wanted a simple file-upload form, for the user to
> upload the two .CSVfiles. Then, there's quite a bit of processing to
> do on the two files, currently in a small python script.
>
> My question was more along the lines of where should put all of the
> logic? Should it be in the model itself, somewhere, and the file-
> upload form just passes across the raw data from the .csvfiles? Where
> would the file-handling stuff go? Is it easier to do it via raw SQL,
> or via the django models? Any chance of sample code =)?
>
> Cheers,
> Victor
>
> On Jan 6, 7:05 pm, "Valts Mazurs"  wrote:
>
> > Hello,
>
> > Maybe this app could be helpful for 
> > you:http://code.google.com/p/django-batchimport/
>
> > If you have toimportlots of data I would suggest creating python script
> > that reads the files and inserts the data in database either using Django
> > ORM or plain SQL. In case of hundreds of thousands of rows I would commit
> > the changes to database after number of inserts (e.g., 100) instead of every
> > insert.
>
> > Best regards,
> > --
> > Valts
>
> > On Tue, Jan 6, 2009 at 07:02, Victor Hooi  wrote:
>
> > > heya,
>
> > > This question might seem a bit simple, but what's the best way to
> > > instantiate models from .csvfiles?
>
> > > Essentially, I have two .csvfiles. One contains a list of people, and
> > > their access rights (one-to-many). The second .csvfile contains a log
> > > of doorway access (just a bunch of sequential lines). I have a simple
> > > python script which imports these two .csvfiles, does some processing
> > > (the files are quite messy), creates user and access-entry objects,
> > > and produces a reconciliation with a list of exceptions (basically
> > > door entries which aren't in the list of user/access rights). Each
> > > user is just a dictionary, with their username as key, and a tuple of
> > > dictionary objects for their various access rights.
>
> > > I would like a simple django project toimportthese logs, instantiate
> > > models, and then basically manage it via the in-built admin interface,
> > > hopefully saving a lot of time =). (will also need to deal with
> > > duplicates). Is there a smart way to go about doing this project, or
> > > any existing addons I can leverage off?
>
> > > Thanks,
> > > Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Import models from CSV files?

2009-01-07 Thread Victor Hooi

heya,

The sample code request was just me being lazy =). Hmm, so you think
the csv parsing code should be in the upload processing? This would
just be a form with two boxes for the user to select the .csv files,
and an upload button. Better putting it here than in the model?

In terms of processing, well, there's only a little bit. One of the
files is a dump from a Lotus Notes view. It looks a little like this

DateRegion  Arrival TimeDurationSites   
For
2008-12-1
Australia
7:30 AM - 1.25 [HR] 
/SYD/225 G  John Smith

/GER/115 A  Nolan Smith
7:30 AM - 1.25 [HR] 
/SYD/225 G  Bob Smith
7:30 AM - 1.25 [HR] 
/SYD/225 G  Joe Smith
NZ
7:30 AM - 1.25 [HR] 
/SYD/225 G  Jane Smith

/SYD/
7:30 AM - 1.0 [HR]  
/SYD/225 G  Mary Smith
7:30 AM - 5.0 [HR]  
/SYD/225 G  Brown Smith
2008-12-2
NZ
7:30 AM - 1.25 [HR] 
/SYD/225 G  Jane Smith

/SYD/
7:30 AM - 1.25 [HR] 
/SYD/225 G  Mary Smith
7:30 AM - 1.25 [HR] 
/SYD/225 G  Brown Smith

Firstly, there were dropdowns (e.g. for Date, and Region) - those date
and regions apply to the rows below them - annoying, but easy to deal
with.

Also, the time is given as a start time and duration - I converted
this into a start_time and end_time.

Finally, the Sites and For columns can each contain multiple entries.
After parsing, I'm storing it as a list of users, each with a list of
access periods granted (containing the start_time, end_time and site -
and a few other things). So you go through, and create entries for
each user, for each of the sites, per line. Not too bad.

Heck, I'll just post the code (I'm halfway through working on it - may
not compile cleanly right now, but you get the idea).

http://dl.getdropbox.com/u/281283/access_requests.py

I guess the important thing is just the users being able to upload
the .csv files themselves, and dealing with weirdness in the input.

Cheers,
Victor

On Jan 8, 2:01 am, Keyton Weissinger  wrote:
> Hey Victor,
>
> I did the django-batchimport mentioned earlier. I think it will
> address your need but is definitely aimed at XLS. However, it does
> already handle duplicates (it will either update them or ignore them
> based on setting). You can also specify a subset of model fields to
> use to determine whether a given row represents a duplicate. This
> allows for "batch update" too.
>
> If you get into it and have any problems, drop me a note.
>
> Keyton
>
> On Jan 6, 12:02 am, Victor Hooi  wrote:
>
> > heya,
>
> > This question might seem a bit simple, but what's the best way to
> > instantiate models from .csv files?
>
> > Essentially, I have two .csv files. One contains a list of people, and
> > their access rights (one-to-many). The second .csv file contains a log
> > of doorway access (just a bunch of sequential lines). I have a simple
> > python script which imports these two .csv files, does some processing
> > (the files are quite messy), creates user and access-entry objects,
> > and produces a reconciliation with a list of exceptions (basically
> > door entries which aren't in the list of user/access rights). Each
> > user is just a dictionary, with their username as key, and a tuple of
> > dictionary objects for their various access rights.
>
> > I would like a simple django project to import these logs, instantiate
> > models, and then basically manage it via the in-built admin interface,
> > hopefully saving a lot of time =). (will also need to deal with
> > duplicates). Is there a smart way to go about doing this project, or
> > any existing addons I can leverage off?
>
> > Thanks,
> > Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



http://jacobian.org/tags/ - Source?

2009-08-17 Thread Victor Hooi

heya,

I was just wondering if anybody knew if the source to the tagging/
bookmarking part of Jacob's site has been made available?

http://jacobian.org/tags/

Or if there's any other django projects that provide something
similar? It seems fairly simple, but it's quite well done, and I was
just hoping to roll out something similar just for myself.

Cheers,
Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: http://jacobian.org/tags/ - Source?

2009-08-22 Thread Victor Hooi

heya,

Yeah, I figured it was leveraging on django-tagging - awesome to hear
they just made a new release as well =). I thought the project had
stagnated or something...lol.

However, I assume there's a bit more to his app - both in the entry
side of things, as well as in the way it's presented/organised on his
site. Just thought there might be existing open source for it floating
around somewhere, or something similar.

Ah well, maybe it'll be fun to build. Anybody else have thoughts?

Cheers,
Victor

On Aug 18, 11:44 am, Joshua Partogi  wrote:
> On Tue, Aug 18, 2009 at 11:41 AM, Victor Hooi  wrote:
>
> > heya,
>
> > I was just wondering if anybody knew if the source to the tagging/
> > bookmarking part of Jacob's site has been made available?
>
> >http://jacobian.org/tags/
>
> > Or if there's any other django projects that provide something
> > similar? It seems fairly simple, but it's quite well done, and I was
> > just hoping to roll out something similar just for myself.
>
> django-tagging [1] is the most popular one.
>
> [1]http://code.google.com/p/django-tagging/
>
> --http://blog.scrum8.comhttp://twitter.com/scrum8
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django ORM and Google Gears (or alternatives?)

2009-08-22 Thread Victor Hooi

heya,

I've got a small project involving an ordering system web application.
One of the requirements is offline functionality (i.e. it will
function without a direct internet connection, at least on a limited
scale - e.g. they can search their previous orders, and submit orders,
with a cached pricelist, maybe even generate printable output, either
print-suitable HTML or PDFs etc.).

Now, I know there was the django-offline project (http://
code.google.com/p/django-offline/). And there was even a question on
django-users asing about what happened ot the project (http://
osdir.com/ml/DjangoUsers/2009-06/msg01790.html).

Are there any similar efforts out there to integrate Google Gears into
Django? Or anybody posting about doing something similar? The Rails
guys have gearsonrails (http://code.google.com/p/gearsonrails/),
however, I do find I'm just more comfortable in Django/Python.

I suppose my question is, is Django really a good fit for what I'm
doing? Primarily, I'm using it for the ORM layer, I guess, so if using
Gears means I can't use the ORM...hmm...suggestions?

Thanks,
Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: NetBeans IDE for Python

2009-04-14 Thread Victor Hooi

heya,

I'm still a bit confused as to how to setup Django to work with
Netbeans.

I'm using Netbeans 6.7 M3 from here:

http://bits.netbeans.org/download/6.7/m3/

I've created a new Django project using django-admin, e.g.:

django-admin.py startproject testproject

and then I'm creating a new "Python Project with Existing Sources",
and pointing it to the "testproject" directory".

In project properties, I've set Main Module to "manage.py", and
Application Arguments to "runserver --noreload" (thanks to
http://esauro.wordpress.com/2008/11/21/django-on-netbeans-65/), so
that takes care of running the server when I click Run.

However, how should I go about setting up autocompletion? It doesn't
seem to recognise Django, and using Ctrl-Space on say,
"django.db.models." just brings up a random list of Python options?
And when I start typing, I don't get a list of models, as people up
above seem to be getting on occasion.

What settings should I change in the project in order to import it
correctly, and get autocomplete and the like working?

Cheers,
Victor

On Feb 26, 6:11 pm, "bruce.hpshare"  wrote:
> It's a good news for the django develpement ...
>
> 2009-02-26
>
> bruce.hpshare
>
> 发件人: पुनित मदान
> 发送时间: 2009-02-26  15:31:41
> 收件人: django-users
> 抄送:
> 主题: Re: NetBeans IDE for Python
>
> u dont need to move django ... but need to configure python path in project 
> properties 
>
> 2009/2/26 Amirouche aka Mouche 
>
> It looks like they plan to give some love to django in the next
> release
>
> http://wiki.netbeans.org/Python70Roadmap
>
> here is the pre-beta nb 7http://bits.netbeans.org/download/6.7/m2/
>
> their is a ruby column but no python ! Hell ! I wonder why ! Is ruby
> that mainstream ?
>
> can't try it myself now, hope it helps !
>
> On Feb 26, 5:38 am, Amirouche aka Mouche
>
>
>
>
>
>  wrote:
> > On Feb 4, 10:54 pm, phillc  wrote:
>
> > > mine wasnt working exactly as you all described it...
>
> > > until i moved my django symlink to someplace else on my python path...
> > > and it suddenly worked its really odd.
>
> > uhh what do you mean ?
>
> > > On Feb 3, 12:49 am, mrsixcount  wrote:
>
> > > > Can't seem to get the auto complete to work when I import
> > > > django.db.models as models.  Shows models when I start typing but
> > > > after the . nothing in the django model section comes up.  Shows the
> > > > master list of python options.  IntegerField isn't in there nor could
> > > > I find any of the other ones.  Oh well hopefully it will be out soon
> > > > with more support for Django
>
> > > > On Jan 17, 3:29 am, Gautam  wrote:
>
> > > > > There is some problem with the parser recognizing package imports in
> > > > > the from ... import ... syntax. What seems to work is if you import
> > > > > packages directly as import ... as 
>
> > > > > So for the django models import as:
>
> > > > > import django.db.models as models
>
> > > > > And voila, completion in Netbeans works!
>
> > > > > On Nov 20 2008, 5:01 pm, lig  wrote:
>
> > > > > > On 19 нояб, 21:22, Delta20  wrote:
>
> > > > > > > NetBeans for Python has been released and based on the NB Python
> > > > > > > roadmap, it looks interesting for those of us working with 
> > > > > > > Django. I
> > > > > > > haven't had much of a chance to play with it yet since it just 
> > > > > > > came
> > > > > > > out today, but here's the info for anyone interested:
>
> > > > > > > NetBeans IDE for 
> > > > > > > Python:http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
>
> > > > > > from django.db import models
>
> > > > > > class Page(models.Model):
> > > > > >     name    = models. # hitting Ctrl+Space here don't show field 
> > > > > > type
> > > > > > suggestions or anything from imported models package
>
> --
> If you spin an oriental man, does he become disoriented?
> (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> is der net süß » ε(●̮̮̃•̃)з
> -PM

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



models.py - __unicode() - Access related object's attributes?

2009-10-27 Thread Victor Hooi

heya,

In my models.py, I've got an "Address", as well as an abstract "Trip"
object, and then a "ToTrip", and "ReturnTrip" object that derive from
that. ToTrip and ReturnTrip both contain references to two Address
objects (models.ForeignKey).

class Address(models.Model):
description = models.CharField(max_length=20, help_text='Helpful
description of this location. Maximum 20 characters.')
...(other fields and methods omitted)

class ToTrip(Trip):
origin = models.ForeignKey(Address)
destination = models.CharField(max_length=20, choices=CAMPUSES)

# Todo: Is there a cleaner way of doing this?
def __unicode__(self):
return str(self.origin) + ' to ' + str(self.destination)


class ReturnTrip(Trip):
origin = models.CharField(max_length=20, choices=CAMPUSES)
destination = models.ForeignKey(Address)

# Todo: Is there a cleaner way of doing this?
def __unicode__(self):
return str(self.origin) + ' to ' + str(self.destination)

In Address, there's a __unicode__() that returns a nicely formatted
string.

My first question is, for ToTrip and ReturnTrip, I wanted to create a
a __unicode__ method that just returned a description field inside of
address. My attempts at using:

return self.origin.description

failed, and I'm guessing that's not the right way to access a field
through a FK relationship? In the above, I'm just using the
__unicode__ method on each address to get it - but I'm sure there's a
cleaner way to get access to the related object's fields themselves?

My second question is a little trivial - is there a way to count the
total number of Trip objects, or objects that are inheritting from it?
At the moment, I'm just counting ReturnTrip and ToTrip objects, and
adding them. No biggie, but I was wondering if there was a way to get
the total number of Trip objects, or at least the number of children?
(I'm guessing the number of actual Trip objects themselves would be
zero?)

Cheers,
Victor
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: models.py - __unicode() - Access related object's attributes?

2009-10-27 Thread Victor Hooi

heya,

Daniel: Thanks for the quick reply.

Hmm, ok, I made the correction to the code you recommended (changing
str() to string interpolation). Do you know any good references on
this, so I can get a better understanding of how these things are
meant to work?

For accessing the field, I found out my error. I was a bit silly, I
think I tried to access the "description" field of both. However, one
of those is a CharField, hence the fail...lol.

Finally, for Trip, yeah, Trip is abstract, hence there aren't really
any actual instances of it, I suppose. For the case here, do you think
there's any advantages to moving from Abstract to Multi-Table
Inheritance? Essentially, we have students, who each have addresses,
and who have ToTrips and ReturnTrips between each other (and those
addresses). The main operations we'll be doing is searching for and
editing trips.

Cheers,
Victor

On Oct 28, 3:11 am, Daniel Roseman  wrote:
> On Oct 27, 2:49 pm, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > In my models.py, I've got an "Address", as well as an abstract "Trip"
> > object, and then a "ToTrip", and "ReturnTrip" object that derive from
> > that. ToTrip and ReturnTrip both contain references to two Address
> > objects (models.ForeignKey).
>
> > class Address(models.Model):
> >     description = models.CharField(max_length=20, help_text='Helpful
> > description of this location. Maximum 20 characters.')
> >     ...(other fields and methods omitted)
>
> > class ToTrip(Trip):
> >     origin = models.ForeignKey(Address)
> >     destination = models.CharField(max_length=20, choices=CAMPUSES)
>
> >     # Todo: Is there a cleaner way of doing this?
> >     def __unicode__(self):
> >         return str(self.origin) + ' to ' + str(self.destination)
>
> > class ReturnTrip(Trip):
> >     origin = models.CharField(max_length=20, choices=CAMPUSES)
> >     destination = models.ForeignKey(Address)
>
> >     # Todo: Is there a cleaner way of doing this?
> >     def __unicode__(self):
> >         return str(self.origin) + ' to ' + str(self.destination)
>
> > In Address, there's a __unicode__() that returns a nicely formatted
> > string.
>
> > My first question is, for ToTrip and ReturnTrip, I wanted to create a
> > a __unicode__ method that just returned a description field inside of
> > address. My attempts at using:
>
> >     return self.origin.description
>
> > failed, and I'm guessing that's not the right way to access a field
> > through a FK relationship? In the above, I'm just using the
> > __unicode__ method on each address to get it - but I'm sure there's a
> > cleaner way to get access to the related object's fields themselves?
>
> > My second question is a little trivial - is there a way to count the
> > total number of Trip objects, or objects that are inheritting from it?
> > At the moment, I'm just counting ReturnTrip and ToTrip objects, and
> > adding them. No biggie, but I was wondering if there was a way to get
> > the total number of Trip objects, or at least the number of children?
> > (I'm guessing the number of actual Trip objects themselves would be
> > zero?)
>
> > Cheers,
> > Victor
>
> OK, firstly, you are returning bytestrings from the unicode methods,
> instead of (obviously) unicode strings. This will eventually bite you:
> if there's ever a value that contains a non-ASCII character (eg a
> foreign address), it will die horribly. You should not be using str()
> in your unicode methods.
>
> So, for example, in ToTrip, the method should look like this:
>
>     def __unicode__(self):
>         return u'%s to %s' % (self.origin, self.destination)
>
> Now, in terms of your actual question, there's certainly nothing wrong
> with doing 'return self.origin.description' - that certainly is the
> way to access related fields. What happens when you try? Can you post
> the exact traceback?
>
> Of course this will fail when the object does not have the foreign key
> field set - eg when it's newly created. Perhaps this is the problem
> you're experiencing. You should catch that possibility and return a
> sensible default.
>
> On your second question, this depends on whether Trip is an abstract
> class or not. If so, there are indeed no Trip objects to count. If
> not, ie you are using multi-table inheritance, you can use
> Trip.objects.count() to get the total number.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Using SOAP-API as Model?

2009-12-03 Thread Victor Hooi
heya,

We need to make a web-frontend for listing and adding items to a YSM
(Yahoo Search Marketing) account. These would include things like new
sub-accounts, new campaigns, keywords etc. You can check/edit these
items through a SOAP API. At the moment, I'm using the SUDS library to
manage these (https://fedorahosted.org/suds/)

I was going to use Django simply for the URL-routing and templating
system (that and I'm more comfortable in Python than say, PHP), and
eschew the model layer. So it's just be a series of views/forms that
listed/manipulated SOAP calls.

However, I was wondering, is it still possible to use the model layer,
since the "model" is something accessed through SOAP queries, rather
than something on a local database. I guess there's a lot of issues,
I'm not sure if any of Django's introspection or model code would
work, performance/latency etc., although I haven't really thought
about it a lot.

Is there any way to get it to work? Or would it be suitable to do a
periodic dump from the SOAP api into a database, and use that as the
model? I suppose then there might be issues of it getting out of sync,
or other people editing the YSM account. Suggestions?

Cheers,
Victor

--

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.




UserProfile and Admin interface

2009-12-08 Thread Victor Hooi
heya,

I'm having issues extending Django's user model via UserProfile, and
then editing this through the admin interface. Essentially, what I
want is to add some extra fields to the User model (I've called this
model "Person"), and be able to edit these along with the normal User
attributes inline all from a single page.

In models.py:

from django.db import models
from django.contrib.auth.models import User
...
class Person(models.Model):
user = models.ForeignKey(User, unique=True)
has_paid = models.BooleanField()

In admin.py:

from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from people.models import Person, Department

class PersonInline(admin.StackedInline):
model = Person

class UserAdmin(admin.UserAdmin):
inlines = [PersonInline]

class DepartmentAdmin(admin.ModelAdmin):
pass

admin.site.register(Department, DepartmentAdmin)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

I've also added this to settings.py:

AUTH_PROFILE_MODULE = 'people.Person'

Sometimes, it seemed to come up with error message "AttributeError at /
admin/auth/user/1/
'module' object has no attribute 'UserAdmin'". The weird thing was,
this seemed to be intermittent, and a refresh of the page loaded up
the admin interface normally. However, when that did load, the editing
links for Department and Person didn't appear in admin, and nor was
there anything about the extra fields under User. There was just the
"Auth" and "Sites" section.

Anyhow, what's the best way of achieve what I want (basically
seamlessly combining User/Person, so it'd appear as if User just had
some extra fields).

Cheers,
Victor

PS: I've read a tonne of sites, some of which seem to say slightly
different things:

One page (http://sam.bluwiki.com/blog/2008/05/extending-user-model-
profiles-in-django.php), recommended using something like:

user = models.ForeignKey(User, unique=True,
edit_inline=models.TABULAR, num_in_admin=1,min_num_in_admin=1,
max_num_in_admin=1,num_extra_on_change=0)

However, this caused an error at models.TABULAR on my end.

Other sites:

http://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-enable-new-fields-in-newforms-admin/
http://www.thenestedfloat.com/articles/displaying-custom-user-profile-fields-in-djangos-admin
http://www.amitu.com/blog/2007/july/django-extending-user-model/
http://www.codekoala.com/blog/2009/quick-django-tip-user-profiles/
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
http://shityoucantremember.wordpress.com/2009/02/14/unriddling-the-django-user-profile/

--

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: UserProfile and Admin interface

2009-12-08 Thread Victor Hooi
heya,

Well, now that was a bit silly of me.

I just noticed that I was importing with "from
django.contrib.auth.admin import UserAdmin", but then I was calling
"admin.UserAdmin" below, rather than "UserAdmin". I've fixed that now,
and the "People" app is now appearing in the admin interface. I'm
still a bit confused as to why it sometimes seemed to load before, and
sometimes gave the unable to find UserAdmin error before.

Anyhow, on the User editing form, it does indeed have the extra
"Person" attributes at the bottom (in this case, just "has_paid").

However, each Department has a Head, which is a FK to a Person/User in
the database. Initially, the drop-down list to select a Head is empty
(I guess we have no Person objects). However, if I edit a user, and
toggle the has_paid field, it will create the Person object associated
with that user. Then, if I go into Department, the drop down now has
"Person object" in it. I suppose I can edit the __unicode__ method for
Person to spit out something a little friendlier (that's the best
thing to do, right?)

Either way, is there a friendlier way of auto-creating those Person
objects, whenever a user is added? Or more tightly binding those two
objects, User/Person together? All I really want is to add some extra
fields to User - and I know that Bennett's blog post lists several
reasons why a user-profile is better than sub-classing User, so I
guess profiles is the way to go, but I'm trying to find a more
intuitive way to deal with it all.

Cheers,
Victor

On Dec 9, 2:53 pm, Victor Hooi  wrote:
> heya,
>
> I'm having issues extending Django's user model via UserProfile, and
> then editing this through the admin interface. Essentially, what I
> want is to add some extra fields to the User model (I've called this
> model "Person"), and be able to edit these along with the normal User
> attributes inline all from a single page.
>
> In models.py:
>
> from django.db import models
> from django.contrib.auth.models import User
> ...
> class Person(models.Model):
>     user = models.ForeignKey(User, unique=True)
>     has_paid = models.BooleanField()
>
> In admin.py:
>
> from django.contrib import admin
> from django.contrib.auth.models import User
> from django.contrib.auth.admin import UserAdmin
> from people.models import Person, Department
>
> class PersonInline(admin.StackedInline):
>     model = Person
>
> class UserAdmin(admin.UserAdmin):
>     inlines = [PersonInline]
>
> class DepartmentAdmin(admin.ModelAdmin):
>     pass
>
> admin.site.register(Department, DepartmentAdmin)
> admin.site.unregister(User)
> admin.site.register(User, UserAdmin)
>
> I've also added this to settings.py:
>
> AUTH_PROFILE_MODULE = 'people.Person'
>
> Sometimes, it seemed to come up with error message "AttributeError at /
> admin/auth/user/1/
> 'module' object has no attribute 'UserAdmin'". The weird thing was,
> this seemed to be intermittent, and a refresh of the page loaded up
> the admin interface normally. However, when that did load, the editing
> links for Department and Person didn't appear in admin, and nor was
> there anything about the extra fields under User. There was just the
> "Auth" and "Sites" section.
>
> Anyhow, what's the best way of achieve what I want (basically
> seamlessly combining User/Person, so it'd appear as if User just had
> some extra fields).
>
> Cheers,
> Victor
>
> PS: I've read a tonne of sites, some of which seem to say slightly
> different things:
>
> One page (http://sam.bluwiki.com/blog/2008/05/extending-user-model-
> profiles-in-django.php), recommended using something like:
>
>     user = models.ForeignKey(User, unique=True,
> edit_inline=models.TABULAR, num_in_admin=1,min_num_in_admin=1,
> max_num_in_admin=1,num_extra_on_change=0)
>
> However, this caused an error at models.TABULAR on my end.
>
> Other sites:
>
> http://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-ena...http://www.thenestedfloat.com/articles/displaying-custom-user-profile...http://www.amitu.com/blog/2007/july/django-extending-user-model/http://www.codekoala.com/blog/2009/quick-django-tip-user-profiles/http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...http://shityoucantremember.wordpress.com/2009/02/14/unriddling-the-dj...

--

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: UserProfile and Admin interface

2009-12-08 Thread Victor Hooi
heya,

I should probably add an example - we want to add a Title field to the
user form. Ideally, this would appear seamlessly as part of the User
form, next to the name fields, rather than it's own separate sub-
section below. What would be a Django-esque way of achieving that?

Cheers,
Victor

On Dec 9, 3:24 pm, Victor Hooi  wrote:
> heya,
>
> Well, now that was a bit silly of me.
>
> I just noticed that I was importing with "from
> django.contrib.auth.admin import UserAdmin", but then I was calling
> "admin.UserAdmin" below, rather than "UserAdmin". I've fixed that now,
> and the "People" app is now appearing in the admin interface. I'm
> still a bit confused as to why it sometimes seemed to load before, and
> sometimes gave the unable to find UserAdmin error before.
>
> Anyhow, on the User editing form, it does indeed have the extra
> "Person" attributes at the bottom (in this case, just "has_paid").
>
> However, each Department has a Head, which is a FK to a Person/User in
> the database. Initially, the drop-down list to select a Head is empty
> (I guess we have no Person objects). However, if I edit a user, and
> toggle the has_paid field, it will create the Person object associated
> with that user. Then, if I go into Department, the drop down now has
> "Person object" in it. I suppose I can edit the __unicode__ method for
> Person to spit out something a little friendlier (that's the best
> thing to do, right?)
>
> Either way, is there a friendlier way of auto-creating those Person
> objects, whenever a user is added? Or more tightly binding those two
> objects, User/Person together? All I really want is to add some extra
> fields to User - and I know that Bennett's blog post lists several
> reasons why a user-profile is better than sub-classing User, so I
> guess profiles is the way to go, but I'm trying to find a more
> intuitive way to deal with it all.
>
> Cheers,
> Victor
>
> On Dec 9, 2:53 pm, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > I'm having issues extending Django's user model via UserProfile, and
> > then editing this through the admin interface. Essentially, what I
> > want is to add some extra fields to the User model (I've called this
> > model "Person"), and be able to edit these along with the normal User
> > attributes inline all from a single page.
>
> > In models.py:
>
> > from django.db import models
> > from django.contrib.auth.models import User
> > ...
> > class Person(models.Model):
> >     user = models.ForeignKey(User, unique=True)
> >     has_paid = models.BooleanField()
>
> > In admin.py:
>
> > from django.contrib import admin
> > from django.contrib.auth.models import User
> > from django.contrib.auth.admin import UserAdmin
> > from people.models import Person, Department
>
> > class PersonInline(admin.StackedInline):
> >     model = Person
>
> > class UserAdmin(admin.UserAdmin):
> >     inlines = [PersonInline]
>
> > class DepartmentAdmin(admin.ModelAdmin):
> >     pass
>
> > admin.site.register(Department, DepartmentAdmin)
> > admin.site.unregister(User)
> > admin.site.register(User, UserAdmin)
>
> > I've also added this to settings.py:
>
> > AUTH_PROFILE_MODULE = 'people.Person'
>
> > Sometimes, it seemed to come up with error message "AttributeError at /
> > admin/auth/user/1/
> > 'module' object has no attribute 'UserAdmin'". The weird thing was,
> > this seemed to be intermittent, and a refresh of the page loaded up
> > the admin interface normally. However, when that did load, the editing
> > links for Department and Person didn't appear in admin, and nor was
> > there anything about the extra fields under User. There was just the
> > "Auth" and "Sites" section.
>
> > Anyhow, what's the best way of achieve what I want (basically
> > seamlessly combining User/Person, so it'd appear as if User just had
> > some extra fields).
>
> > Cheers,
> > Victor
>
> > PS: I've read a tonne of sites, some of which seem to say slightly
> > different things:
>
> > One page (http://sam.bluwiki.com/blog/2008/05/extending-user-model-
> > profiles-in-django.php), recommended using something like:
>
> >     user = models.ForeignKey(User, unique=True,
> > edit_inline=models.TABULAR, num_in_admin=1,min_num_in_admin=1,
> > max_num_in_admin=1,num_extra_on_change=0)
>
> > However, this caused an error at models.TABULAR on my end.
>
> > Other sites:
>
> >http://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-ena..

--

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.




FK to an Abstract class? Alternative?

2009-12-15 Thread Victor Hooi
heya,

We have a small project where we need to store a series of exam
results for students.

Some exams receive a grade out of 100, others are simply a pass/fail,
while others are given a one-word grade (e.g. pass, fail, credit,
distinction).

In a sense, they all do map to a 0 to 100 scale (e.g. for the pass/
fail, you can make it 0 and 100, while the pass/fail/credit/
distinction can be mapped to other numbers. However apparently the
users don't want to store it that way, and want them each
differentiated. Also, I suppose you'd need to store somehow which type
of mark it was anyway, for when you need to represent it to the user.

I was thinking of setting up abstract models to handle this, something
like:

class AssessmentTask(models.Model):
name = models.CharField(max_length=20)
paper = models.FileField(upload_to='forms/examination')
date = models.DateField()

class Meta:
abstract = True

class GradedAssessmentTask(AssessmentTask):
mark = models.CharField(max_length=1,
choices=ASSESSMENT_GRADE_CHOICES)

class PassFailAssessmentTask(AssessmentTask):
mark = models.BooleanField()

class NumericalMarkAssessmentTask(AssessmentTask):
mark = models.PositiveIntegerField()

class ExaminationRecord(models.Model):
assessment = models.OneToOneField(AssessmentTask)

You could then create overridden methods to handle pass/fail checking
for each of those. The ExaminationRecord object contains a list of
assessments, each of which is of type AssessmentTask.

However, Django complains with:

AssertionError: OneToOneField cannot define a relation with
abstract class AssessmentTask

So obviously that's not the right way to handle this. What is the
right way within Django to handle something like this?

Cheers,
Victor

--

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.




Generic Inlines in Admin - Causes Parent model to disappear in Admin

2009-12-22 Thread Victor Hooi
heya,

I have an address object, which is setup as a generic relation.

class Address(models.Model):
street_address = models.CharField(max_length=50)
... (etc.)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()

It's used in a few places, such as by UserProfile, in a Department
object, and elsewhere. Each of those has a GenericRelation back to
Address.

In the admin.py, I've tried to setup Generic Inlines, to edit the
Address for each Department.

from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from people.models import UserProfile, Department, Address
from django.contrib.contenttypes import generic

class UserProfileInline(admin.StackedInline):
model = UserProfile

class UserAdmin(UserAdmin):
inlines = [UserProfileInline]

class AddressInline(generic.GenericTabularInline):
models = Address

class DepartmentAdmin(admin.ModelAdmin):
inlines = [
AddressInline
]

However, when I add in the inline code for Addresses, I get an error
message such as this:

AttributeError at /admin/
type object 'AddressInline' has no attribute 'date_hierarchy'

or:

ImproperlyConfigured at /admin/
'model' is a required attribute of 'DepartmentAdmin.inlines[0]'.

But then, if I hit refresh in the browser, the Admin interface
displays, albeit with the Department and Address sections missing.
There aren't any error messages on the console.

What's the proper way to setup generic inlines in the admin? Am I
doing something wrong in the above?

Also, I noticed that when I add a Department, next to a field that has
a FK to a user, there's a little green cross to add a new user. Is it
possible to have something setup for other FK fields, including
generic ones?

Cheers,
Victor

--

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: Generic Inlines in Admin - Causes Parent model to disappear in Admin

2009-12-23 Thread Victor Hooi
heya,

Yeah, that was actually it...lol...how silly. Changed 'models' to
'model', works now =).

Thanks heaps for that.

Otherwise, is this the right way of setting up these relationships,
the way I'm doing it? And the right way to use the admin?

Cheers,
Victor

On Dec 23, 10:16 pm, Daniel Roseman  wrote:
> On Dec 23, 5:41 am, Victor Hooi  wrote:
>
> >     class AddressInline(generic.GenericTabularInline):
> >         models = Address
>
> Is that just a typo here, or do you actually have it as 'models' in
> your code? It should be 'model'. Change that and see if it fixes your
> problem.
> --
> DR.

--

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




Re: Inline and ForeignKeys - Weird ordering?

2010-04-15 Thread Victor Hooi
Karen,

Thanks for the reply =).

Yeah, you're right in that it doesn't make sense for a normal inline.
I was hoping for some sort of "reverse" inline? (Is that the right
word?).

I guess I just wanted some AJAX-y way to create new categories (FK
parents) without having to popup a new window. Anyhow, I suppose when
I create custom forms or extend the admin, I could do that, but
otherwise it's not that big a deal.

Cheers,
Victor

On Apr 15, 9:23 pm, Karen Tracey  wrote:
> On Thu, Apr 15, 2010 at 3:24 AM, Victor Hooi  wrote:
> > However, I still wanted some way of creating categories on the "Add
> > Article" page - is there a way of doing inlines here, and having the
> > "Add Firm" embedded on that page (without having to open a new
> > window), or should I reverse the way my FK is?
>
> The standard select widget in admin for the Category foreign key will have a
> green plus icon next to it that, when clicked, will open a popup window that
> allows you to create a new Category.
>
> 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.



Django Admin - m2m widget with blank=true, null=true - How to unselect all FKs?

2010-04-18 Thread Victor Hooi
Hi,

I have a field in a model which is set to null/blank = True

firm = models.ManyToManyField(Firm, null=True, blank=True)

I tried using the default m2m filter, however, I wasn't sure how to
unselect an entry.

I also tried using filter_horizontal, and this was much more intuitive/
niftier. And I was able to unselect here.

However, I'm still not sure how to clear all selected FKs in the
default m2m widget. Clicking on any single item seems to replace the
current selection with that one, click directly on a selected item
doesn't seem to unselect it. Clicking out of the widget simply seems
to unfocus the widget, but the selected items still seem selected.

Also, I noticed in the filter_horizontal widget, that the unselect
(left arrow) is always grey, I guess that's intended. However, my
initial thought was that it would be grey when there were no FKs
chosen, but then would turn blue once there was something to remove.
Guess it's just different tastes.

Cheers,
Victor

-- 
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 Admin - m2m widget with blank=true, null=true - How to unselect all FKs?

2010-04-18 Thread Victor Hooi
Jani,

Aha, that worked, thanks =).

Don't know why I didn't think about using Ctrl...lol.

However, do you think it'd be obvious to new users, to use ctrl?

Cheers,
Victor

On Apr 19, 2:46 pm, Jani Tiainen  wrote:
> On 04/19/2010 06:58 AM, Victor Hooi wrote:
>
>
>
>
>
> > Hi,
>
> > I have a field in a model which is set to null/blank = True
>
> >      firm = models.ManyToManyField(Firm, null=True, blank=True)
>
> > I tried using the default m2m filter, however, I wasn't sure how to
> > unselect an entry.
>
> > I also tried using filter_horizontal, and this was much more intuitive/
> > niftier. And I was able to unselect here.
>
> > However, I'm still not sure how to clear all selected FKs in the
> > default m2m widget. Clicking on any single item seems to replace the
> > current selection with that one, click directly on a selected item
> > doesn't seem to unselect it. Clicking out of the widget simply seems
> > to unfocus the widget, but the selected items still seem selected.
>
> Click one item, then (at most os/computers/browsers) press CTRL down and
> click selected entry. It should clear selection.
>
> --
>
> Jani Tiainen
>
> --
> 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.



Where to set proxy settings for Django?

2010-04-18 Thread Victor Hooi
heya,

This is a fairly trivial thing, but anyhow:

We're working on a Django app behind a corporate proxy/firewall.

We have a model with URLField, and by default, verify_true is false.
So of course, Django wants to punch out to the web to check if the URL
exists. Now if I define "http_proxy" before running ./manage.py
runserver, all is good.

Also, I assume when we move to a real webserver, we'll also need to
set the proxy settings again, since when we deploy, we'll probably
still be behind the corproate proxy.

However, what's the better way to set this? Should I be setting it in
settings.py? Or is there a better place?

Cheers,
Victor

-- 
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 Admin - m2m widget with blank=true, null=true - How to unselect all FKs?

2010-04-19 Thread Victor Hooi
heya,

Yeah, that is an option, just add a clear all button. Shouldn't be too
hard.

I find the filter_horizontal widget much nicer though, might just use
that =). Thanks for your help.

Cheers,
Victor

On Apr 19, 6:26 pm, Jani Tiainen  wrote:
> No, it's definitely not obvious but there is no simple way to otherwise
> to do it.
>
> We've sometimes added button with piece of javascript to clear all
> selections. But that only works if user has js enabled of course.
>
> It's just how browsers and operating systems show that particular
> component and there is quite little you can do about it.
>
> --
>
> Jani Tiainen
>
> On 04/19/2010 08:45 AM, Victor Hooi wrote:
>
>
>
>
>
> > Jani,
>
> > Aha, that worked, thanks =).
>
> > Don't know why I didn't think about using Ctrl...lol.
>
> > However, do you think it'd be obvious to new users, to use ctrl?
>
> > Cheers,
> > Victor
>
> > On Apr 19, 2:46 pm, Jani Tiainen  wrote:
> >> On 04/19/2010 06:58 AM, Victor Hooi wrote:
>
> >>> Hi,
>
> >>> I have a field in a model which is set to null/blank = True
>
> >>>       firm = models.ManyToManyField(Firm, null=True, blank=True)
>
> >>> I tried using the default m2m filter, however, I wasn't sure how to
> >>> unselect an entry.
>
> >>> I also tried using filter_horizontal, and this was much more intuitive/
> >>> niftier. And I was able to unselect here.
>
> >>> However, I'm still not sure how to clear all selected FKs in the
> >>> default m2m widget. Clicking on any single item seems to replace the
> >>> current selection with that one, click directly on a selected item
> >>> doesn't seem to unselect it. Clicking out of the widget simply seems
> >>> to unfocus the widget, but the selected items still seem selected.
>
> >> Click one item, then (at most os/computers/browsers) press CTRL down and
> >> click selected entry. It should clear selection.
>
> >> --
>
> >> Jani Tiainen
>
> >> --
> >> 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 
> 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.



M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-05-13 Thread Victor Hooi
heya,

I have a Django app that keeps track of newspapers articles, and the
companies mentioned in them (this is slightly simplified, but it'

Each article has a m2m relationship with firm. Originally, this was
just a direct m2m, however, I found I needed to add a "rating" to each
firm that's mentioned in an article, hence I created an intermediary
model (FirmRating), which then links Article to Firm.

The relevant models:

class Article(models.Model):
title = models.CharField(max_length=100)
publication_date = models.DateField()
abstract = models.TextField() # Can we restrict this to 450
characters?
category = models.ForeignKey(Category)
subject = models.ForeignKey(Subject)
source_publication = models.ForeignKey(Publication)
page_number = models.CharField(max_length=30)
article_softcopy = models.FileField(upload_to='article_scans',
null=True, blank=True, help_text='Optionally upload a soft-copy (scan)
of the article.')
url = models.URLField(null=True, blank=True, help_text =
'Enter a URL for the article. Include the protocl (e.g. http)')
firm = models.ManyToManyField(Firm, null=True, blank=True,
through='FirmRating')
#firm = models.ForeignKey(Firm)
spokesperson = models.ManyToManyField(Spokeperson, null=True,
blank=True)
#spokesperson = models.ForeignKey(Spokeperson)

def __unicode__(self):
return self.title

class FirmRating(models.Model):
firm = models.ForeignKey(Firm)
article = models.ForeignKey(Article)
rating = models.IntegerField()

class Firm(models.Model):
name = models.CharField(max_length=50, unique=True)
homepage = models.URLField(verify_exists=False,
help_text='Enter the homepage of the firm. Include the protocl (e.g.
http)')

def __unicode__(self):
return self.name

class Meta:
ordering = ['name']

And my admin.py:

class FirmRatingInline(admin.TabularInline):
model = FirmRating
extra = 1

class FirmAdmin(admin.ModelAdmin):
list_display = ('name', 'homepage')
list_editable = ('homepage',)
search_fields = ('name', 'homepage')
inlines = (FirmRatingInline,)

class ArticleAdmin(admin.ModelAdmin):
#inlines = [
#CategoryInline,
#]
date_hierarchy = 'publication_date'
filter_horizontal = ('firm', 'spokesperson')
list_display = ('title', 'publication_date', 'category',
'subject', 'source_publication', 'page_number')
list_editable = ('publication_date', 'category', 'subject',
'source_publication', 'page_number')
list_filter = ('publication_date', 'category', 'subject',
'source_publication')
search_fields = ('title', 'publication_date', 'abstract',
'category__name', 'subject__name', 'source_publication__name',
'page_number', 'url')
inlines = (FirmRatingInline,)

I also read:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models

which provided some info on getting Django admin to play nicely with
intermediary models.

However, I can't seem to get this working on here, I suspect there's
something wrong in the above code

Before, when I was editing articles in the admin (with just a straight
m2m), it offered adding firms to each article in a nice
filter_horizontal widget. However, now, with the intermediary model,
it's like Firm doesn't even exist to Articles anymore, there's no
mention of it on the Article editing page.

There's nothing relevant in the Apache error logs either. I'm a bit
stumped. Any ideas?

Thanks,
Victor

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



PostgreSQL backend - Ident authentication failed?

2010-06-20 Thread Victor Hooi
Hi,

We have a Django application that we just moved from a Ubuntu 9.04
server to 10.04. We're running Apache 2.2/WSGI, with PostgreSQL as the
backend.

My settings.py file:

'DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add
'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mediatracking',  # Or path to
database file if using sqlite3.
#os.path.join(PROJECT_PATH, "templates"),
'USER': 'victorhooi',  # Not used with
sqlite3.
'PASSWORD': 'ourpassword',  # Not used
with sqlite3.
'HOST': '',  # Set to empty string for
localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for
default. Not used with sqlite3.
}
}

I created a blank PostgreSQL database as myself ("victorhooi").

I ran ./manage.py syncdb, and this seemed to authenticate fine, and
create all the required tables.

When I try to go to http://site.com/admin though, I get an error:

OperationalError at /admin/
FATAL:  Ident authentication failed for user "victorhooi"

I've read elsewhere that you need to do some tom-foolery to disable
ident authentication in PostgreSQL, or something. However, I'm
confused, because:

1. This exact same configuration seemed to work fine on our old
server.
2. The syncdb command works, but actually serving the web page
doesn't.
3. In the error message, it says ident authentication failed for user
"victorhooi", but that's the righ username to authenticate with, isn't
it?

I did notice further down in the error page, under settings:

CSRF_FAILURE_VIEW   'django.views.csrf.csrf_failure'
DATABASES   {'default': 'ENGINE':
'django.db.backends.postgresql_psycopg2', 'HOST': '', 'NAME':
'mediatracking', 'OPTIONS': {}, 'PASSWORD': '',
'PORT': '', 'TEST_CHARSET': None, 'TEST_COLLATION': None,
'TEST_MIRROR': None, 'TEST_NAME': None, 'TIME_ZONE': 'Australia/
Sydney', 'USER': 'victorhooi'}}
DATABASE_ENGINE  ''
DATABASE_HOST   ''
DATABASE_NAME   ''
DATABASE_OPTIONS{}
DATABASE_PASSWORD   ''
DATABASE_PORT   ''
DATABASE_ROUTERS[]
DATABASE_USER   ''
DATETIME_FORMAT 'N j, Y, P'
DATETIME_INPUT_FORMATS  ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M'

Any suggestions?

Cheers,
Victor

-- 
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: PostgreSQL backend - Ident authentication failed?

2010-06-20 Thread Victor Hooi
heya,

Thanks for the tip. It does work now, following your advice =).

I created a new PostgreSQL user named "www-data". I then changed my
settings.py file:

'USER': 'www-data',  # Not used with
sqlite3.
'PASSWORD': 'ourpassword',  # Not used
with sqlite3.
'HOST': '',  # Set to empty string for
localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for
default. Not used with sqlite3.
}

However, I'm still curious as to what changed, as I'm fairly sure this
setup worked on the old Ubuntu 9.04 server? And I'm definitely sure
that the database username was set to "victorhooi" on that old system
- I copied the settings.py file over using verbatim (rsync).

Also, is this recommended practice, to use "www-data" as the backend
database username?

Cheers,
Victor

On Jun 21, 3:54 pm, Torsten Bronger 
wrote:
> Hall chen!
>
> Victor Hooi writes:
> > [...]
>
> > I created a blank PostgreSQL database as myself ("victorhooi").
>
> > I ran ./manage.py syncdb, and this seemed to authenticate fine,
> > and create all the required tables.
>
> > When I try to go tohttp://site.com/adminthough, I get an error:
>
> >     OperationalError at /admin/
> >     FATAL:  Ident authentication failed for user "victorhooi"
>
> Does the webserver also run as victorhooi?  Maybe it runs as
> www-data for example.
>
> Tsch ,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>                    Jabber ID: torsten.bron...@jabber.rwth-aachen.de
>                                   orhttp://bronger-jmp.appspot.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: PostgreSQL backend - Ident authentication failed?

2010-06-21 Thread Victor Hooi
heya,

Using "www-data" as the backend database username in settings.py
doesn't quite work. If you try to run a ./manage.py syncdb, it spits
out:

Traceback (most recent call last):
  File "./manage.py", line 11, in 
execute_manager(settings)
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/__init__.py", line 438, in execute_manager
utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/base.py", line 220, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/base.py", line 351, in handle
return self.handle_noargs(**options)
  File "/usr/local/lib/python2.6/dist-packages/django/core/
management/commands/syncdb.py", line 52, in handle_noargs
cursor = connection.cursor()
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
__init__.py", line 75, in cursor
cursor = self._cursor()
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
postgresql_psycopg2/base.py", line 136, in _cursor
self.connection = Database.connect(**conn_params)
psycopg2.OperationalError: FATAL:  Ident authentication failed for
user "www-data"

I've changed the authentication in my pg_hba.conf from "ident" to
"password", and it now works with "victorhooi" as the backend database
username =). So there's no need to use a PostgreSQL www-data account.

I'm still curious what changed? Perhaps Ubuntu's default pg_hba.conf
file changed from 9.04 to 10.04? AFAIK, there wasn't any such change,
although I don't have a 9.04 system around to verify.

Anyhow, is this the recommended configuration, what I have now? Just
want to know the right way of doing things?

Cheers,
Victor

On Jun 21, 4:54 pm, Torsten Bronger 
wrote:
> Hall chen!
>
> Victor Hooi writes:
> > [...]
>
> > However, I'm still curious as to what changed, as I'm fairly sure
> > this setup worked on the old Ubuntu 9.04 server? And I'm
> > definitely sure that the database username was set to "victorhooi"
> > on that old system - I copied the settings.py file over using
> > verbatim (rsync).
>
> Maybe pg_hba.conf has changed.
>
> > Also, is this recommended practice, to use "www-data" as the
> > backend database username?
>
> No, not recommended, but not forbidden either.  We didn't use
> "ident" but "password" in pg_hba.conf.  This way, you are not bound
> to user accounts of the underlying operating system.
>
> But possibly we switch to "ident" for local connections
> (i.e. command line) and "password" for TCP/IP connections.  The
> reason is that passwords make command line scripting harder.
>
> Tsch ,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>                    Jabber ID: torsten.bron...@jabber.rwth-aachen.de
>                                   orhttp://bronger-jmp.appspot.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.



Apache + Gunicorn + Django? Sample Configs?

2010-06-21 Thread Victor Hooi
Hi,

I'm currently deploying Django on Apache with WSGI.

Anyhow, I've heard really good things about the Gunicorn (http://
gunicorn.org/) WSGI server, so I was hoping to try it out.

I'm running Ubuntu 10.04, so I've installed the packages from the
official PPA (https://launchpad.net/~bchesneau/+archive/gunicorn)

However, I'm having trouble finding detailed instructions for Gunicorn
+ Django in English. E.g.:

http://blog.exirel.me/technique/apache-proxy-gunicorn-runit-django
http://blog.sietch-tabr.com/index.php/post/2010/04/04/Heberger-des-projets-Django-avec-Nginx-et-Gunicorn

Nor can I seem to find anything on how to deploy Apache + Django +
Gunicorn in English either.

Has anybody had success with getting it properly setup in production
with Django, and if so, would it be possible to post up your sample
config scripts?

Many of the guides refer to using Nginx - however, I need Apache
running on this server (other sites), and I only have a single IP
address on this system. And I'm not aware of any way of passing only
specific virtual-hosts through to Nginx, to then pass onto Gunicorn.
But if there's an easy way of doing that, I'm open to using Nginx +
Django + Gunicorn as an alternative.

Cheers,
Victor

-- 
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: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-06-24 Thread Victor Hooi
heya,

Nuno: Thanks for the advice.

I know how to add normal inlines to the home page for a model, via the
"inlines" list in admin.py. However, how exactly do I add an inline
formset to the Add Article page?

I can override the template for the Add Article page, however, I don't
think that's what needs to be done here.

Is there a clean way of using the existing "Add Article" page, but
just swapping in an inline for the intermediary? Also, I'd like to
leverage off the exisiting "filter_horizontal" widget, if possible.
Basically, I just want it exactly as it was, without the intermediary,
with a filter_horizontal for settings the m2m relationship, but then
with just an additional widget for setting the intermediary "rating"
field.

(I found this write-up http://www.fictitiousnonsense.com/archives/22
however, it seems geared towards replacing a single field on a single
model, not sure how it'd handle the intermediary model here. Also is
this method still valid/best practice?).

Cheers,
Victor

On May 15, 2:29 am, Nuno Maltez  wrote:
> Hmmm ... you should have an inline formset at the bottom to add firms
> to your Article, with an associated input box forthe rating.
>
> If I understand correctly, each relation Article-Firm now needs a
> rating (mandatory), sou you can't just select Firms from a
> filter_horizontal widget - you need a way to input the rating as well.
>
> Nuno
>
> --
> 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.



m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

NB: This is a followup to this:

http://groups.google.com/group/django-users/browse_thread/thread/0fdc1dfb1fddb97b/6b559dc4abf5d4ea

but I thought I'd also ask about the model design.

To provide some background, we have a Django app that contains a list
of journal articles.

Each "Article" also has a m2m relationship to "Firm" as well as
"Spokesperson"

class Article(models.Model):
title = models.CharField(max_length=100)
publication_date = models.DateField()
abstract = models.TextField() # Can we restrict this to 450
characters?
...fields ommited for brevity...
firm = models.ManyToManyField(Firm, null=True, blank=True,
through='FirmRating')
spokesperson = models.ManyToManyField(Spokeperson, null=True,
blank=True, through='SpokespersonRating')

The intermediary models, FirmRating and SpokespersonRating look like
this:

class FirmRating(models.Model):
firm = models.ForeignKey(Firm)
article = models.ForeignKey(Article)
rating = models.IntegerField()

Basically, we use it to store the m2m link, as well as a "rating"
assigned to each relationship.

The issue is, as soon as I change it from a normal m2m relationship to
one with a "through" attribute, it seems to completely disappear in
the Django Admin from the "Add Article" page. Before, I had a nice
little filter_horizontal widget to create the relationships. No,
zippo...that's not a bug, is it?

Anyhow, Firstly, am I doing this the right way? Or is there another
way to create an Article, have it m2m with Firms/Spokesperson, and
assign an individual rating to each relationship?

Secondly, is there some way of making a m2m with intermediary visibile
in the admin - is it intended behaviour for it to disappear? In an
ideal world, I'd like to have the filter_horizontal, as well as an
inline widget to set the rating, all on the "Add Article" page.
However, I'm prepared to have just the filter_horizontal for the m2m,
and set the rating separately, on a separate page just for FirmRating/
SpokespersonRating (it obviously breaks the workflow a bit there).

How do people normally deal with editing m2m intermediary models in
Django?

Cheers,
Victor

-- 
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: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

Also, I should add I did try using the inlines as described in the
docs

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models

In my admin.py, I've imported "FirmRating" at the top.

I've then created an inline for it:

class FirmRatingInline(admin.TabularInline):
model = FirmRating
extra = 1

then used this in ArticleAdmin:

class ArticleAdmin(admin.ModelAdmin):
#inlines = [
#CategoryInline,
#]
date_hierarchy = 'publication_date'
filter_horizontal = ('firm', 'spokesperson')
list_display = ('title', 'publication_date', 'entry_date',
'category', 'subject', 'source_publication', 'weekly_summary')
list_editable = ('publication_date', 'category', 'subject',
'source_publication')
list_filter = ('publication_date', 'entry_date', 'category',
'subject', 'source_publication')
search_fields = ('title', 'publication_date', 'abstract',
'category__name', 'subject__name', 'source_publication__name',
'page_number', 'url')

However, there's still no visible widget for "FirmRating" on the "Add
Article" page.

I can't tell just from the docs, but is this inline only for use on
the main Article list page, but not on the Add Article page? Or is the
above admin code meant to make the widget visible on the "Add Article"
page as well?

Cheers,
Victor

On Jun 25, 10:01 am, Victor Hooi  wrote:
> heya,
>
> NB: This is a followup to this:
>
> http://groups.google.com/group/django-users/browse_thread/thread/0fdc...
>
> but I thought I'd also ask about the model design.
>
> To provide some background, we have a Django app that contains a list
> of journal articles.
>
> Each "Article" also has a m2m relationship to "Firm" as well as
> "Spokesperson"
>
> class Article(models.Model):
>     title = models.CharField(max_length=100)
>     publication_date = models.DateField()
>     abstract = models.TextField() # Can we restrict this to 450
> characters?
>     ...fields ommited for brevity...
>     firm = models.ManyToManyField(Firm, null=True, blank=True,
> through='FirmRating')
>     spokesperson = models.ManyToManyField(Spokeperson, null=True,
> blank=True, through='SpokespersonRating')
>
> The intermediary models, FirmRating and SpokespersonRating look like
> this:
>
> class FirmRating(models.Model):
>     firm = models.ForeignKey(Firm)
>     article = models.ForeignKey(Article)
>     rating = models.IntegerField()
>
> Basically, we use it to store the m2m link, as well as a "rating"
> assigned to each relationship.
>
> The issue is, as soon as I change it from a normal m2m relationship to
> one with a "through" attribute, it seems to completely disappear in
> the Django Admin from the "Add Article" page. Before, I had a nice
> little filter_horizontal widget to create the relationships. No,
> zippo...that's not a bug, is it?
>
> Anyhow, Firstly, am I doing this the right way? Or is there another
> way to create an Article, have it m2m with Firms/Spokesperson, and
> assign an individual rating to each relationship?
>
> Secondly, is there some way of making a m2m with intermediary visibile
> in the admin - is it intended behaviour for it to disappear? In an
> ideal world, I'd like to have the filter_horizontal, as well as an
> inline widget to set the rating, all on the "Add Article" page.
> However, I'm prepared to have just the filter_horizontal for the m2m,
> and set the rating separately, on a separate page just for FirmRating/
> SpokespersonRating (it obviously breaks the workflow a bit there).
>
> How do people normally deal with editing m2m intermediary models in
> Django?
>
> Cheers,
> Victor

-- 
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: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

Ok, scratch all that, I'm an idiot.

A simple restart of my Apache process, and the m2m intermediary inline
works *grins*.

Thanks anyhow to the awesome Django community for an awesome tool =).

I do have a final question though. I can now edit "Firms" as inlines
from the "Article" page, which is good.

However, to be honest, the filter_horizontal widget was a much better
interface. I suppose there's no way to somehow use the
filter_horizontal widget within the inline, and then tack on a
"Rating" field as part of the inline?

Also, I notice that in my inline, it says "FirmRating object" right
above the select box:'

http://twitpic.com/1zo4im/full

Any way to hide/tweak that text?

Cheers,
Victor

On Jun 25, 10:09 am, Victor Hooi  wrote:
> heya,
>
> Also, I should add I did try using the inlines as described in the
> docs
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>
> In my admin.py, I've imported "FirmRating" at the top.
>
> I've then created an inline for it:
>
> class FirmRatingInline(admin.TabularInline):
>     model = FirmRating
>     extra = 1
>
> then used this in ArticleAdmin:
>
> class ArticleAdmin(admin.ModelAdmin):
>     #inlines = [
>     #    CategoryInline,
>     #]
>     date_hierarchy = 'publication_date'
>     filter_horizontal = ('firm', 'spokesperson')
>     list_display = ('title', 'publication_date', 'entry_date',
> 'category', 'subject', 'source_publication', 'weekly_summary')
>     list_editable = ('publication_date', 'category', 'subject',
> 'source_publication')
>     list_filter = ('publication_date', 'entry_date', 'category',
> 'subject', 'source_publication')
>     search_fields = ('title', 'publication_date', 'abstract',
> 'category__name', 'subject__name', 'source_publication__name',
> 'page_number', 'url')
>
> However, there's still no visible widget for "FirmRating" on the "Add
> Article" page.
>
> I can't tell just from the docs, but is this inline only for use on
> the main Article list page, but not on the Add Article page? Or is the
> above admin code meant to make the widget visible on the "Add Article"
> page as well?
>
> Cheers,
> Victor
>
> On Jun 25, 10:01 am, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > NB: This is a followup to this:
>
> >http://groups.google.com/group/django-users/browse_thread/thread/0fdc...
>
> > but I thought I'd also ask about the model design.
>
> > To provide some background, we have a Django app that contains a list
> > of journal articles.
>
> > Each "Article" also has a m2m relationship to "Firm" as well as
> > "Spokesperson"
>
> > class Article(models.Model):
> >     title = models.CharField(max_length=100)
> >     publication_date = models.DateField()
> >     abstract = models.TextField() # Can we restrict this to 450
> > characters?
> >     ...fields ommited for brevity...
> >     firm = models.ManyToManyField(Firm, null=True, blank=True,
> > through='FirmRating')
> >     spokesperson = models.ManyToManyField(Spokeperson, null=True,
> > blank=True, through='SpokespersonRating')
>
> > The intermediary models, FirmRating and SpokespersonRating look like
> > this:
>
> > class FirmRating(models.Model):
> >     firm = models.ForeignKey(Firm)
> >     article = models.ForeignKey(Article)
> >     rating = models.IntegerField()
>
> > Basically, we use it to store the m2m link, as well as a "rating"
> > assigned to each relationship.
>
> > The issue is, as soon as I change it from a normal m2m relationship to
> > one with a "through" attribute, it seems to completely disappear in
> > the Django Admin from the "Add Article" page. Before, I had a nice
> > little filter_horizontal widget to create the relationships. No,
> > zippo...that's not a bug, is it?
>
> > Anyhow, Firstly, am I doing this the right way? Or is there another
> > way to create an Article, have it m2m with Firms/Spokesperson, and
> > assign an individual rating to each relationship?
>
> > Secondly, is there some way of making a m2m with intermediary visibile
> > in the admin - is it intended behaviour for it to disappear? In an
> > ideal world, I'd like to have the filter_horizontal, as well as an
> > inline widget to set the rating, all on the "Add Article" page.
> > However, I'm prepared to have just the filter_horizontal for the m2m,
> > and set the rating separately, on a separate page just for FirmRating/
> > SpokespersonRating (it obviously breaks the workflow a bit there).
>
> > How do people normally deal with editing m2m intermediary models in
> > Django?
>
> > Cheers,
> > Victor- Hide quoted text -
>
> - Show quoted text -

-- 
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: m2m with intermediary - model design? Disappears from Django-Admin?

2010-06-24 Thread Victor Hooi
heya,

Brenton: Thanks for the reply =).

Hmm, I was hoping to use the filter_horizontal widget to set the
relationship, and just have a box below that for setting the rating.
But you're right, we'd need a table for each rating for each
relationship, and there's a room issue.

I might look into extending the widget - is there any good
documentation on extending Django admin widgets? I saw this article:

http://www.fictitiousnonsense.com/archives/22

but I'm not sure if that's still up-to-date, and I was hoping for more
details/examples to learn how to do it well. Any good reading
recommendations on this topic?

Also, it's not so much an issue with the inlines taking up space, as
that the filter_horizontal widget, with the in-built search box, the
"choose all" and "clear all" links is just a good UI, and looks quite
nice, to boot. I'd really like to integrate it in somehow to the
inline if possible...lol.

Anyhow, finally, thanks for the tip about __self__, completely didn't
think about that. Will set that now.

Cheers,
Victor

On Jun 25, 11:03 am, iliveinapark 
wrote:
> Gday Victor,
>
> Glad you found the inline admin method for attaching your m2m's with
> throughs. It isn't possible to to use the filter_horizontal widget for
> through m2m, because, as you noted, there's no space for the extra
> fields to be input. You could always try to extend the widget, but
> this is more trouble than it's worth, and I haven't seen it done
> acceptably. If you don't like all the space taken up by the inline,
> try making them collapsible with js, maybe (you can define js in the
> ModelAdmin inner class 
> Media:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-me...).
>
> As for the name "FirmRating object", define a unicode method on your
> class, eg:
>
> def __unicode__(self):
>     return "%s - %s: %s) % (self.article, self.firm, self.rating)
>
> Cheers,
> Brenton
>
> On Jun 25, 10:24 am, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > Ok, scratch all that, I'm an idiot.
>
> > A simple restart of my Apache process, and the m2m intermediary inline
> > works *grins*.
>
> > Thanks anyhow to the awesome Django community for an awesome tool =).
>
> > I do have a final question though. I can now edit "Firms" as inlines
> > from the "Article" page, which is good.
>
> > However, to be honest, the filter_horizontal widget was a much better
> > interface. I suppose there's no way to somehow use the
> > filter_horizontal widget within the inline, and then tack on a
> > "Rating" field as part of the inline?
>
> > Also, I notice that in my inline, it says "FirmRating object" right
> > above the select box:'
>
> >http://twitpic.com/1zo4im/full
>
> > Any way to hide/tweak that text?
>
> > Cheers,
> > Victor
>
> > On Jun 25, 10:09 am, Victor Hooi  wrote:
>
> > > heya,
>
> > > Also, I should add I did try using the inlines as described in the
> > > docs
>
> > >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>
> > > In my admin.py, I've imported "FirmRating" at the top.
>
> > > I've then created an inline for it:
>
> > > class FirmRatingInline(admin.TabularInline):
> > >     model = FirmRating
> > >     extra = 1
>
> > > then used this in ArticleAdmin:
>
> > > class ArticleAdmin(admin.ModelAdmin):
> > >     #inlines = [
> > >     #    CategoryInline,
> > >     #]
> > >     date_hierarchy = 'publication_date'
> > >     filter_horizontal = ('firm', 'spokesperson')
> > >     list_display = ('title', 'publication_date', 'entry_date',
> > > 'category', 'subject', 'source_publication', 'weekly_summary')
> > >     list_editable = ('publication_date', 'category', 'subject',
> > > 'source_publication')
> > >     list_filter = ('publication_date', 'entry_date', 'category',
> > > 'subject', 'source_publication')
> > >     search_fields = ('title', 'publication_date', 'abstract',
> > > 'category__name', 'subject__name', 'source_publication__name',
> > > 'page_number', 'url')
>
> > > However, there's still no visible widget for "FirmRating" on the "Add
> > > Article&qu

Django-Admin - radio_fields with add/change pages, but not list_display page?

2010-06-29 Thread Victor Hooi
Hi,

I have a Django application with an "Article" model. I'm using the
radio_fields in django-admin with two of the ForeignKey fields that
are linked to Article.

Currently the related tables have five and twenty entries each, so
this UI works quite well on the Add/Change pages.

However, I'm also using list_display with this model - and in the
list_display, it also displays radio boxes, which look quite ugly -
the HTML select box worked much better on list_display. In fact, I
can't really think of many cases, unless the number of possible
entries was quite small, where a radio_box would work well with
list_display.

Anyhow, is there any way to use radio_fields on the Add/Change field,
but not with the list_display page?

Cheers,
Victor

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



Newbie Question - django-jython - how to "run" the app?

2010-07-01 Thread Victor Hooi
heya,

I've trying to get my Django app to run on a Tomcat 5.x server, using
django-jython. I'm a bit of a newbie in the Java/Tomcat world though.

Firstly, I'm currently using PostgreSQL. However, to make things
easier on the target server, I was just going to use SQLite3 - the app
will only be used by two users, and getting a database in this
deployment environment is a bit tricky. However, I read on the django-
jython pages that SQlite3 support is experimental and considered
risky:

http://packages.python.org/django-jython/database-backends.html

Is that still true? Should I try and push hard to get a database setup
for me? The only one they offer is MySQL, there's a few hoops to get
that though.

Secondly, apparently this Tomcat server doesn't take WAR archives
files, you need to explode them first. Anyhow, I've unzipped the WAR
archive to the directory, now I'm not exactly sure how to get it to
actually run.

Under my app context directory, my structure looks like (where
application is called chair, just for example's sake)

\chair
 - application.py
 - application$py.class
 \WEB-INF
   web.xml
   \lib
- jruby-extras-fileservlet.jar
- jython.jar
   \lib-python
 - Lib.pth
 - README
 \chair
 \django
 \doj
 \Lib

etc.

Is this right, or am I missing any files/directories in the WAR
creation?

Apart from setting up the context, what exactly do I need to do (or
get the web server administrator) to do to get the application to run?
Do I need to get them to import the web.xml file? I had a look in
there, didn't seem to find anything that seems to "run" my app, or
point to anything to get it to run?

Cheers,
Victor

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



Error in Admin - can't seem to chain __unicode__'s for ForeignKeys

2010-07-08 Thread Victor Hooi
heya,

I have a small Django app that contains a list of Df (disk-free)
reports.

"DfReport" has a ForeignKey to "Filesystem" model, which has a
ForeignKey to "Device". (i.e. Devices has filesystems, each filesystem
has a DfReport).

I'm getting an error in the admin when I attempt to display the
list_display page for a "DfReport" model.

TemplateSyntaxError at /admin/report/dfreport/add/
Caught TypeError while rendering: coercing to Unicode: need string
or buffer, Device found

I've traced the error to the __unicode__ method for one of the
ForeignKey fields on DfReport being displayed.

The issue is, Filesystem has __unicode__ set to print the server on
which it's reporting. Using the following causes the
TemplateSyntaxError:

class Filesystem(models.Model):
name = models.CharField(max_length=50)
#description = models.CharField(max_length=100)
description = models.TextField()
server = models.ForeignKey(Device)

def __unicode__(self):
return self.name + ' on device ' + self.server

However, if I change self.server to "self.server.name", it works. The
weird thing is - Device (which server points to), has a __unicode__
method defined as well. Shouldn't calling self.server just use the
__unicode__ method on Device, instead of needing me to explicitly call
self.server.name?

class Device(models.Model):
name = models.CharField(max_length=50)
#description = models.CharField(max_length=100)
description = models.TextField()
location = models.ForeignKey(Location)

def __unicode__(self):
return self.name

class Meta:
ordering = ['name']

Or have I got a wrong understanding of how this works?

Cheers,
Victor

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



Model Validation - Prevent Datetimefield overlaps?

2010-08-30 Thread Victor Hooi
heya,

I have a model that contains a whole bunch of bytes in/out for
datetime ranges. I.e.:

class BandwidthUsageEntry(models.Model):
start_of_usage_block = models.DateTimeField()
end_of_usage_block = models.DateTimeField()
bytes_in = models.IntegerField()
bytes_out = models.IntegerField()

I need to ensure that each entry doesn't overlap with any others
entries.

Just playing around - I noticed that setting "unique=True" on a
DateTimeField() doesn't seem to work? As in, I was able to do
something like:

b1 =
BandwidthUsageEntry(start_of_usage_block=datetime.datetime(2007,05,05,12,05),
end_of_usage_block=datetime.datetime(2007,05,12,12,10),bytes_in=10,bytes_out=10)
b1.save()
b2 =
BandwidthUsageEntry(start_of_usage_block=datetime.datetime(2007,05,05,12,05),
end_of_usage_block=datetime.datetime(2007,05,12,12,10),bytes_in=20,bytes_out=20)
b2.save()

Is this expected behaviour, or do I have something wrong with my
setup?

Anyhow, in terms of how to actually prevent overlaps, I assume that
the best way is to use a custom model validator, and check each start/
end against a query against all the entries?

(I saw this 
http://stackoverflow.com/questions/2243490/django-unique-time-interval-for-the-admin-panel,
but it seems to be going a different way that I don't follow).

How would I go about structuring this? Any particular tips here, or
any algorithms that could work well?

Cheers,
Victor

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



Using localflavor with admin?

2010-10-27 Thread Victor Hooi
Hi,

Is there any way to combine the localflavor module (http://
docs.djangoproject.com/en/dev/ref/contrib/localflavor/) with Django's
in-built admin module?

For example, I'd like to create a model with say, a Postcode and phone-
number field, and have these validated in the admin, as per the rules
setup in localflavor?

Cheers,
Victor

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



Converting Django to Desktop App? (Multiple Instances)

2010-10-29 Thread Victor Hooi
Hi,

This is a bit of a strange scenario.

We have a simple Django application used to maintain a database of
newspaper/journal articles. We're extensively using the django-admin
as part of this app.

Currently, we're having issues getting a production environment with
Python provisioned (corporate environment, locked technology roadmap
etc.), however, we will have access to a Oracle database instance.

One possibility raised was that for each of the clients (fairly small,
under 5), we install a local instance of Django and Apache, which they
access with their browser, and each of these instances communicates
with a single Oracle DB instance.

I know on the Rails side, there was a product by Joyent called
Slingshot (http://joyeur.com/2007/03/22/joyent-slingshot/), which
allegedly did something similar (packaged up a RoR app into a desktop
application).

Are there any particular issues we need to be aware of if we decided
to go down this path?

In particular, I wasn't sure how multiple instances of Django would
handle concurrency if they were communicating with a single database.
Any advice there?

Any other possible drawbacks/roadblocks?

Cheers,
Victor

-- 
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: Using localflavor with admin?

2010-11-01 Thread Victor Hooi
heya,

Hmm, I'm actually trying this Australian localisation.

However, the weird thing is, there's a US models.py:

http://code.djangoproject.com/browser/django/trunk/django/contrib/localflavor/us/models.py

But there's no such models.py for other countries. E.g., for
Australia:

http://code.djangoproject.com/browser/django/trunk/django/contrib/localflavor/au

Is there a particular reason for this? Or any way of achieving the
same effect?

Cheers,
Victor

On Oct 29, 5:48 am, Frank Wiles  wrote:
> On Thu, Oct 28, 2010 at 12:23 AM, Victor Hooi  wrote:
> > Hi,
>
> > Is there any way to combine the localflavor module (http://
> > docs.djangoproject.com/en/dev/ref/contrib/localflavor/) with Django's
> > in-built admin module?
>
> > For example, I'd like to create a model with say, a Postcode and phone-
> > number field, and have these validated in the admin, as per the rules
> > setup in localflavor?
>
> Hi Victor,
>
> You just need to use the the model fields to achieve this.  So for
> example, if I was going to do a US Phone Number field I would do:
>
> from django.db import models
> from django.contrib.localflavor.us.models import PhoneNumberField
>
> class Test(models.Model):
>     phone = PhoneNumberField()
>
> You'd obviously need to reference the exact field you're looking for,
> but then it just automagically works in the admin.
>
> --
> Frank Wiles
> Revolution Systems |http://www.revsys.com/
> fr...@revsys.com   | (800) 647-6298

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



Reverse Query Name Clash?

2010-11-01 Thread Victor Hooi
Hi,

I'm getting a error about reverse query name clashes with my models.

We have a Django app to manage conferences and conference attendees.

In our models.py, two of the models we have are:

1. Person, representing people attending people attending a
conference. Each person also has a "church" field, which represents
the main church they attend.

class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
gender = models.CharField(max_length=1,
choices=GENDER_CHOICES)
spouse = models.ForeignKey('self', null=True, blank=True)
date_of_birth = models.DateField()
church = models.ForeignKey('Church')
...

The "church" FK is in quotation marks, since the Church object is
defined below Person.

2. "Church", which defines a church, and includes an optional field
for the main minister at that church. The minister field is a FK to a
Person.

class Church(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=50)
suburb = models.CharField(max_length=30)
postcode = models.IntegerField()
state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES)
minister = models.ForeignKey(Person, null=True, blank=True)

So a person has a church, and a church also has a minister (in most
cases the two will be different, except for the case where the
minister themselves is attending a conference, which should of course
be valid).

The issue here is that the model doesn't validate:

Error: One or more models did not validate:
conferences.church: Reverse query name for field 'minister'
clashes with field 'Person.church'. Add a related_name argument to the
definition for 'minister'.

Now, if I change the name of the "church" field under Person, it will
validate - however, I'm still curious as to why this doesn't work? Any
way to fix it? (I assume I could add a related_name argument, I'm just
trying to figure out what's going on, and gain more understanding for
Django).

Cheers,
Victor

-- 
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: Using localflavor with admin?

2010-11-01 Thread Victor Hooi
heya,

Thanks for your answer - I posted a reply (doesn't seem to work for
non-US), however, it doesn't seem to have appeared on the web-version
of Groups, so I thought I'd email you directly, just in case you
missed it and happened to know.

Thanks,
Victor

Hmm, I'm actually trying this Australian localisation.
However, the weird thing is, there's a US models.py:
http://code.djangoproject.com/browser/django/trunk/django/contrib/localflavor/us/models.py
But there's no such models.py for other countries. E.g., for
Australia:
http://code.djangoproject.com/browser/django/trunk/django/contrib/localflavor/au
Is there a particular reason for this? Or any way of achieving the
same effect?

On Oct 29, 5:48 am, Frank Wiles  wrote:
> On Thu, Oct 28, 2010 at 12:23 AM, Victor Hooi  wrote:
> > Hi,
>
> > Is there any way to combine the localflavor module (http://
> > docs.djangoproject.com/en/dev/ref/contrib/localflavor/) with Django's
> > in-built admin module?
>
> > For example, I'd like to create a model with say, a Postcode and phone-
> > number field, and have these validated in the admin, as per the rules
> > setup in localflavor?
>
> Hi Victor,
>
> You just need to use the the model fields to achieve this.  So for
> example, if I was going to do a US Phone Number field I would do:
>
> from django.db import models
> from django.contrib.localflavor.us.models import PhoneNumberField
>
> class Test(models.Model):
>     phone = PhoneNumberField()
>
> You'd obviously need to reference the exact field you're looking for,
> but then it just automagically works in the admin.
>
> --
> Frank Wiles
> Revolution Systems |http://www.revsys.com/
> fr...@revsys.com   | (800) 647-6298

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



ReportLab and Django - templates? ; FK object has no attribute split

2010-11-17 Thread Victor Hooi
Hi,

I'm trying to use ReportLab to produce a PDF output for one of my
views.

My first question is - at the moment, I'm building up the PDF inside
my view. Is this really the recommended way of doing it? It's like
I've got presentation code inside my view (controller). Isn't there a
cleaner way of doing it, or going from a template to PDF somehow? (I
know ReportLab offers a commercial package using RML templates,
however I was hoping for an opensource/free method).

Second question, I have a model with several FK fields. E.g.

class Article(models.Model):
category = models.ForeignKey(Category)
subject = models.ForeignKey(Subject)

Both the category and subject classes have fields called "name", and
__unicode__ methods defined which return name.

I'm trying to refer to these fields in my PDF output. I have a list of
items in article_list (i.e. queryset):

for item in article_list:
text = item.category
category = Paragraph(text, styles['Heading2'])
story.append(category)

text = '%s' % item.subject
subject = Paragraph(text, styles['Heading3'])
story.append(subject)

When I try to run this code, I get:

'Category' object has no attribute 'split'

and the same error with subject, obviously, once it gets to that bit
of the code.

Any idea why this might be, or how to fix it? Any help is much
appreciated.

Cheers,
Victor

-- 
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: ReportLab and Django - templates? ; FK object has no attribute split

2010-11-18 Thread Victor Hooi
Hi:

natebeacham: Yup, using item.category.name works fine =).

Using string interpolation on item.category also works - I was silly,
forgot to restart the gunicorn process (I suppose you have to restart
it after any changes to views.py, right? Or does it pick it up
automatically after a while?).

So between the two approaches, using item.category.name, and using
string interpolation is one preferable to the other?

Jikra: Thanks for the tip =). I did try Pisa for a bit, but for some
reason, it was just timing out when I tried to integrate it into
Django.

The reason I didn't push harder to investigate the issue was that
firstly, the command-line utility seemed to have pretty poor
performance anyway.

And secondly, Pisa itself seems to have been discontinued:

http://groups.google.com/group/xhtml2pdf/browse_thread/thread/32dcee769245fc8f

Finally, Pisa (and other approaches wkhtmltopdf) seem to require a lot
more dependencies installed/setup - reportlab is just a single package
to compile.

But  yeah, I'd still love if there was a separate template I could use
to generate the PDF. It just feels very weird building up the PDF line
by line in views.py.

Cheers,
Victor

On Nov 18, 8:14 pm, Jirka Vejrazka  wrote:
> Hi Victor,
>
>   It really depends on complexity of your PDF. I needed to do
> something similar some time ago and used ReportLab addon called "pisa"
> and used standard Django template language to define the PDF contents.
>
>   You might want to take a look, it worked well enough for simple PDF pages.
>
>   Cheers
>
>     Jirka
>
> On 18/11/2010, Victor Hooi  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm trying to use ReportLab to produce a PDF output for one of my
> > views.
>
> > My first question is - at the moment, I'm building up the PDF inside
> > my view. Is this really the recommended way of doing it? It's like
> > I've got presentation code inside my view (controller). Isn't there a
> > cleaner way of doing it, or going from a template to PDF somehow? (I
> > know ReportLab offers a commercial package using RML templates,
> > however I was hoping for an opensource/free method).
>
> > Second question, I have a model with several FK fields. E.g.
>
> >     class Article(models.Model):
> >         category = models.ForeignKey(Category)
> >         subject = models.ForeignKey(Subject)
>
> > Both the category and subject classes have fields called "name", and
> > __unicode__ methods defined which return name.
>
> > I'm trying to refer to these fields in my PDF output. I have a list of
> > items in article_list (i.e. queryset):
>
> >     for item in article_list:
> >         text = item.category
> >         category = Paragraph(text, styles['Heading2'])
> >         story.append(category)
>
> >         text = '%s' % item.subject
> >         subject = Paragraph(text, styles['Heading3'])
> >         story.append(subject)
>
> > When I try to run this code, I get:
>
> >     'Category' object has no attribute 'split'
>
> > and the same error with subject, obviously, once it gets to that bit
> > of the code.
>
> > Any idea why this might be, or how to fix it? Any help is much
> > appreciated.
>
> > Cheers,
> > Victor
>
> > --
> > 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.



Serve different page to IE7/8?

2010-11-21 Thread Victor Hooi
Hi,

We're currently development a small Django webapp for use internally.

The page renders fine on Firefox and Webkit-based browsers.

However, many of our users are still on Internet Explorer 7, and the
CSS/HTML we're using seems to bork really badly on that. I'm
definitely not a web-designer by trade, and I'm not really not on top
of all the quirks of the different browser.

I know this is a bit of a hack, but what's the best way to serve up a
different template to those IE7 users? Hopefully it'll be less of an
issue when IE9 eventually rolls out (although I suspect it'll still be
an issue), but something like this would be a good stopgap for us, and
the site/templates itself it fairly simple.

What's the most Django-ish way of doing it?

We'd probably actually like something similar for our BlackBerry users
as well - same view code, but serving up a different template, based
on user-agent - recommended way?

Cheers,
Victor

-- 
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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
Hi,

I'm wondering what the community's stance on using NULL in Django is?

Say for example you have:

class Person(models.Model):
street_address = models.CharField(max_length=50, blank=True)
suburb = models.CharField(max_length=30)
postcode = models.IntegerField()
state = models.CharField(max_length=3)
email = models.EmailField()
mobile_phone_number = models.IntegerField(max_length=12)
home_phone_number = models.IntegerField(max_length=10,
null=True, blank=True)
work_phone_number = models.IntegerField(max_length=8,
null=True, blank=True)

   spouse = models.ForeignKey('self', null=True, blank=True)
   children = models.ManyToManyField('self', null=True,
blank=True)

For string fields like street_address, I can make these "blank=True",
and Django will store an empty string if the user leaves it blank.

However, for integer fields like home_phone_number and
work_phone_number, I've had to make these "null=True" for the case
where somebody doesn't supply them (i.e. they're meant to be optional,
mobile is required).

However, is there a better way of handling this case? (assuming I want
to keep these fields as integers).

What about in the case of optional foreign keys (spouse and children)
- is there a better way of handling these, without using NULLs?

Cheers,
Victor

-- 
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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
heya,

Phone Number - Yup, you're both right, I'll be using CharField now,
and model validation to make sure they're digits.

Spouse/Children:

With children, a M2M field, there's a link table, and if you don't
have a spouse, then there won't be any lines in that table. So no need
for NULLs there. I've just tested it with just blank=True, and no
null=True - seems to do what I want (optional children).

With ForeignKeyField though, I thought this was simply an FK field,
with the ID number of the object we're relating/pointing stored in
that field? Isn't that how it works in a normal DB? Why is there a
separate Person_spouse table?

Is there any way to make this optional without using NULLs, or should
I make it a m2m field? (I suppose in theory you can have multiple
spouses...well, not under my jurisdiction, I guess...lol).

Cheers,
Victor

On Nov 30, 3:11 pm, Lachlan Musicman  wrote:
> On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> > Hi,
>
> > I'm wondering what the community's stance on using NULL in Django is?
>
> > Say for example you have:
>
> >    class Person(models.Model):
> >        street_address = models.CharField(max_length=50, blank=True)
> >        suburb = models.CharField(max_length=30)
> >        postcode = models.IntegerField()
> >        state = models.CharField(max_length=3)
> >        email = models.EmailField()
> >        mobile_phone_number = models.IntegerField(max_length=12)
> >        home_phone_number = models.IntegerField(max_length=10,
> > null=True, blank=True)
> >        work_phone_number = models.IntegerField(max_length=8,
> > null=True, blank=True)
>
> >       spouse = models.ForeignKey('self', null=True, blank=True)
> >       children = models.ManyToManyField('self', null=True,
> > blank=True)
>
> > For string fields like street_address, I can make these "blank=True",
> > and Django will store an empty string if the user leaves it blank.
>
> > However, for integer fields like home_phone_number and
> > work_phone_number, I've had to make these "null=True" for the case
> > where somebody doesn't supply them (i.e. they're meant to be optional,
> > mobile is required).
>
> > However, is there a better way of handling this case? (assuming I want
> > to keep these fields as integers).
>
> Is it possible to know why you would want to keep them as integers?
> Given that there are no mathematical functions that you would want to
> apply to them
>
> > What about in the case of optional foreign keys (spouse and children)
> > - is there a better way of handling these, without using NULLs?
>
> As I understand it, foreign keys are kept in the db as follows:
>
> 1. table_Person
> 2. table_Person_children
> 3. table_Person_spouse
>
> table 2 has three columns: id, Person, Children
> table 3 has three columns: id, Person, Spouse
>
> or something to that effect.
>
> Therefore, if there is no Spouse or Child, there is no entry for
> Person in tables 2 or 3.
>
>
>
>
>
>
>
> > Cheers,
> > Victor
>
> > --
> > 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.



Issues importing models in between apps

2010-11-29 Thread Victor Hooi
Hi,

I had an application with a fairly large models.py file, which I split
up into separate apps to make it easier to manage.

Two of the apps are called "conferences" and "people", each with their
own models.py.

These two are fairly tightly entwined, they each refer to each other.

At the top of project_name/conferences/models.py, I have:

from django.db import models
from nextgen.people.models import Person

At the top of project_name/people/models.py, I have:

from django.db import models
from project_name.conferences.models import Conference

However, when I try to run ./manage.py validate, it gives me an error:

  File "/sites/.virtualenvs/project_name/src/django/django/utils/
importlib.py", line 35, in import_module
__import__(name)
  File "/home/victorhooi/djangoProjects/project_name/../
project_name/conferences/models.py", line 2, in 
from project_name.people.models import Person
  File "/home/victorhooi/djangoProjects/project_name/../
project_name/people/models.py", line 3, in 
from project_name.conferences.models import Conference
ImportError: cannot import name Conference

I'm not sure why this is happening - from the looks of it, it's
opening up conferences/models.py, then importing people.models.Person
from there, which inside of that tries to import Conference - is it
somehow clashing?

Or is there a better way of creating multiple apps that all share
models? The main reason I split it up was for logically separating all
the different models, they still all need to import/relate to each
other.

Cheers,
Victor

-- 
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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
Mike,

Hmm, I'm currently using a recursive ('self') Many2Many and ForeignKey
for Children and Spouse, respectively (see source in the first post).

Is that what you meant?

Or perhaps I'm not quite getting what you mean - any chance you could
paste a models.py example so I can make sure I'm on the same page?

Cheers,
Victor

On Nov 30, 5:02 pm, Mike Dewhirst  wrote:
> On 30/11/2010 4:26pm, Victor Hooi wrote:
>
> > heya,
>
> > Phone Number - Yup, you're both right, I'll be using CharField now,
> > and model validation to make sure they're digits.
>
> > Spouse/Children:
>
> Victor
>
> I'm coming in late on this and don't have the context for your design
> but I think there might be a better (perhaps more flexible) way to
> handle spouses and children without worrying about NULLs.
>
> I really like a single table for everyone. After all spouses and
> children are persons too. You can use a separate table to hold named
> many-to-many relationships between the person table and itself.
>
> If the relationship is "Spouse" then that relationship speaks for
> itself. Children can simultaneously have relationships with "Father",
> "Mother", "Step-mother" etc. Other persons can have "Ex-spouse"
> relationships when divorced etc.
>
> If you can find any person then you can navigate through all the
> relationships to find all connected persons.
>
> Finally, if someone has multiple spouses then they probably need
> counselling but at least you can represent it with multiple relationship
> records :)
>
> Mike
>
>
>
>
>
>
>
>
>
> > With children, a M2M field, there's a link table, and if you don't
> > have a spouse, then there won't be any lines in that table. So no need
> > for NULLs there. I've just tested it with just blank=True, and no
> > null=True - seems to do what I want (optional children).
>
> > With ForeignKeyField though, I thought this was simply an FK field,
> > with the ID number of the object we're relating/pointing stored in
> > that field? Isn't that how it works in a normal DB? Why is there a
> > separate Person_spouse table?
>
> > Is there any way to make this optional without using NULLs, or should
> > I make it a m2m field? (I suppose in theory you can have multiple
> > spouses...well, not under my jurisdiction, I guess...lol).
>
> > Cheers,
> > Victor
>
> > On Nov 30, 3:11 pm, Lachlan Musicman  wrote:
> >> On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> >>> Hi,
>
> >>> I'm wondering what the community's stance on using NULL in Django is?
>
> >>> Say for example you have:
>
> >>>     class Person(models.Model):
> >>>         street_address = models.CharField(max_length=50, blank=True)
> >>>         suburb = models.CharField(max_length=30)
> >>>         postcode = models.IntegerField()
> >>>         state = models.CharField(max_length=3)
> >>>         email = models.EmailField()
> >>>         mobile_phone_number = models.IntegerField(max_length=12)
> >>>         home_phone_number = models.IntegerField(max_length=10,
> >>> null=True, blank=True)
> >>>         work_phone_number = models.IntegerField(max_length=8,
> >>> null=True, blank=True)
>
> >>>        spouse = models.ForeignKey('self', null=True, blank=True)
> >>>        children = models.ManyToManyField('self', null=True,
> >>> blank=True)
>
> >>> For string fields like street_address, I can make these "blank=True",
> >>> and Django will store an empty string if the user leaves it blank.
>
> >>> However, for integer fields like home_phone_number and
> >>> work_phone_number, I've had to make these "null=True" for the case
> >>> where somebody doesn't supply them (i.e. they're meant to be optional,
> >>> mobile is required).
>
> >>> However, is there a better way of handling this case? (assuming I want
> >>> to keep these fields as integers).
>
> >> Is it possible to know why you would want to keep them as integers?
> >> Given that there are no mathematical functions that you would want to
> >> apply to them
>
> >>> What about in the case of optional foreign keys (spouse and children)
> >>> - is there a better way of handling these, without using NULLs?
>
> >> As I understand it, foreign keys are kept in the db as follows:
>

Re: Issues importing models in between apps

2010-11-30 Thread Victor Hooi
heya,

Thanks to both for your advice.

Yeah, you're right, it's a somewhat unwanted circular dependency. It
was just the only way I could think of to deal with a somewhat
unwieldy/large models.py file.

Even using the string syntax, I hit a bunch of other issues, due to
how tightly the two models are coupled ('Accessor clashes with related
field...', the 'through' table for m2m needs to be imported etc.). So
it might be better to try and sort out the design issue first.

To give some context - it's a simple application for managing people's
attendance at conferences, and allocating accomodation to them.

 * I have a 'People' app that has a models 'Person', along with models
for all their required information (allergies, special requirements,
spouse/children, contact numbers and addresses etc.).

 * I have a 'Conferences' app that imports Person, and stores things
about their attendance, accommodation requests, what workshop they're
assigned to etc.

 * I have a 'Facilities' app that manages all the various accomodation
sites and workshop rooms, and what they each provide. (e.g. how many
beds, how many seats etc.)

There's a few others, but those are the main ones.

Previously, I had this all in a single models.py inside Conferences.
However, it got a bit unwieldy, hence the split. However, they're all
still tightly coupled.

With the above information, would you still recommend putting it all
in a single app - or should I try and work out the issues from this
split? It did seem cleaner in separate apps.

Anyhow, from my understanding, I can split up the models.py file

http://code.djangoproject.com/ticket/4470
http://andrewwilkinson.wordpress.com/2009/01/20/placing-django-models-in-separate-files/

However, I'll need to add a Meta/app_label to each and every single
model in that file - is that right? Or is there a better way of
splitting up a models.py file across multiple files, or of somehow
organising this?

Cheers,
Victor

On Nov 30, 10:44 pm, bruno desthuilliers
 wrote:
> On 30 nov, 07:01, Victor Hooi  wrote:
>
> > Hi,
>
> > I had an application with a fairly large models.py file, which I split
> > up into separate apps to make it easier to manage.
>
> This won't address your problem but FWIW, you don't have to use
> separate apps just to split a models.py file - you can turn it into a
> models package, with the package's __init__.py used as a "facade" for
> the submodules (usual pythonic solution).
>
> But anyway:
>
> > Two of the apps are called "conferences" and "people", each with their
> > own models.py.
>
> > These two are fairly tightly entwined, they each refer to each other.
>
> If both models really depend that much on each other then they ought
> te live in a same module. Or perhaps there's room for improvement in
> your design but you don't give enough context.
>
> (snip typical circular deps symptom)
>
> > I'm not sure why this is happening - from the looks of it, it's
> > opening up conferences/models.py, then importing people.models.Person
> > from there, which inside of that tries to import Conference
>
> In Python almost everything happens at runtime. The import, class and
> def statements are executable statements, and they are executed - with
> every other top-level statement - when the module is first loaded.
>
> > Or is there a better way of creating multiple apps that all share
> > models?
>
> Put the interdependent models in a same app. The you can have other
> apps using these models too as long as there's no circular
> dependencies.
>
> A Django app doesn't have to define models or views or urls or
> whatever - you can have one app with models, and another vwith views
> and forms and whatnot depending on the first app's models.
>
> > The main reason I split it up was for logically separating all
> > the different models, they still all need to import/relate to each
> > other.
>
> Once again: if your models are tightly coupled, they ought to live in
> a same module.

-- 
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: Issues importing models in between apps

2010-11-30 Thread Victor Hooi
heya,

Sorry to reply to myself, but I seem to have the split worked out,
using string syntax as suggested by Daniel, as you would for a FK to a
model not yet defined (http://docs.djangoproject.com/en/dev/ref/models/
fields/#foreignkey).

It seems to work now, however, it is a bit messier than directly
referring to models by their name alone.

So the design question from my previous message still stands - is this
a candidate for splitting up across apps like this, or am I better off
going for a single app, and splitting up the models.py within there?
Or any other techniques you might recommend, to make the design more
logical and the models.py less unwieldly/large?

Cheers,
Victor

On Nov 30, 10:44 pm, bruno desthuilliers
 wrote:
> On 30 nov, 07:01, Victor Hooi  wrote:
>
> > Hi,
>
> > I had an application with a fairly large models.py file, which I split
> > up into separate apps to make it easier to manage.
>
> This won't address your problem but FWIW, you don't have to use
> separate apps just to split a models.py file - you can turn it into a
> models package, with the package's __init__.py used as a "facade" for
> the submodules (usual pythonic solution).
>
> But anyway:
>
> > Two of the apps are called "conferences" and "people", each with their
> > own models.py.
>
> > These two are fairly tightly entwined, they each refer to each other.
>
> If both models really depend that much on each other then they ought
> te live in a same module. Or perhaps there's room for improvement in
> your design but you don't give enough context.
>
> (snip typical circular deps symptom)
>
> > I'm not sure why this is happening - from the looks of it, it's
> > opening up conferences/models.py, then importing people.models.Person
> > from there, which inside of that tries to import Conference
>
> In Python almost everything happens at runtime. The import, class and
> def statements are executable statements, and they are executed - with
> every other top-level statement - when the module is first loaded.
>
> > Or is there a better way of creating multiple apps that all share
> > models?
>
> Put the interdependent models in a same app. The you can have other
> apps using these models too as long as there's no circular
> dependencies.
>
> A Django app doesn't have to define models or views or urls or
> whatever - you can have one app with models, and another vwith views
> and forms and whatnot depending on the first app's models.
>
> > The main reason I split it up was for logically separating all
> > the different models, they still all need to import/relate to each
> > other.
>
> Once again: if your models are tightly coupled, they ought to live in
> a same module.

-- 
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-extensions - "Error: no module named django_extensions"

2010-12-08 Thread Victor Hooi
heya,


I original thought to post this in the django-extensions group, however
that seems like a fairly low-traffic group, so I thought I'd post here
in the hopes somebody here might be able to figure it out.


Basically, I've installed django-extensions via Pip
pip install django-extensions
Whenever I try to run any manage.py commands in my project, I get an
error:
Error: No module named django_extensions
In my settings.py, I have:
INSTALLED_APPS = (

'django_extensions',
In the Python shell,I can do a "import django_extensions" and it
imports fine with no error messages.


Not sure what's going on here?


I also tried with django-extensions from Github, same error.


Cheers,
Victor

-- 
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-extensions - "Error: no module named django_extensions"

2010-12-08 Thread Victor Hooi
heya,


Thanks for the reply. I'm fairly sure it is in the PYTHONPATH.


I'm using virtualenvs and pip to install, so it should be there in the
system-wide Python directory for that environment.


Also, as per my first post, I can import it fine from a Python shell,
it's just it seems to act up within Django...*confused*.


Cheers,
Victor

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



Generic Relations and Django Admin?

2010-01-18 Thread Victor Hooi
heya,

I'm trying to use an "Address" model as a generic relation against
multiple other models (e.g. in a "User Profile", for each User, as
well as for "Building", "Institution", and various other ones).

So I've added the content_type, object_id and content_object fields to
Address.

class Address(models.Model):
"""
Basic object for holding address information - for either people
or institutions.
"""
street_address = models.CharField(max_length=50)
suburb = models.CharField(max_length=20)
state = models.CharField(max_length=3,
choices=AUSTRALIAN_STATES_CHOICES)
# PositiveIntegerField doesn't allow max_length? Have to use form
validation for this.
postcode = models.CharField(max_length=4)
# This should probably be a list of choices.
country = models.CharField(max_length=20)
address_category = models.OneToOneField(AddressCategory)

# We make Address a generic relation model
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type',
'object_id')

class Meta:
verbose_name_plural = 'Addresses'

def __unicode__(self):
return self.street_address + ', ' + self.suburb

 And my other objects have GenericRelations to Address. E.g.:

class Hospital(models.Model):
name = models.CharField(max_length=20)
address = generic.GenericRelation(Address)

def __unicode__(self):
return self.name

However, when I try and use the Django admin to add an Address item,
the form has fields for content_type and object_id. I had thought
these fields wouldn't appear? Also, the model won't validate/save if I
don't fill in these fields. I don't think I'm quite using this right -
is there a better way of doing what I'm trying to achieve here?

Also, I'm using the Address object as in Inline for the other models,
so I have an Address Inline as well (Nb: I'm using django-reversion
with this site, hence the "VersionAdmin")

class AddressAdmin(VersionAdmin):
pass
class AddressInline(generic.GenericTabularInline):
model = Address
...
class HospitalAdmin(admin.ModelAdmin):
inlines = [
AddressInline,
]
...
admin.site.register(Address, AddressAdmin)

Thanks,
Victor
-- 
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: Generic Relations and Django Admin?

2010-01-19 Thread Victor Hooi
heya,

The thing is, the foreign key field is on the Address object, linking
to another object that *has* an address.

AFAIK, that's how it's meant to be in database design.

That's why I need to put something there - e.g.

class Address(models.Model):
...
user = models.ForeignKey(UserProfile)

but that doesn't work for hospitals, or say institutions, or anything
else that needs an address. So I can't just pick one. Or is my design
off?

Cheers,
Victor

On Jan 19, 6:03 pm, greatlemer  wrote:
> On Jan 19, 5:25 am, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > I'm trying to use an "Address" model as a generic relation against
> > multiple other models (e.g. in a "User Profile", for each User, as
> > well as for "Building", "Institution", and various other ones).
>
> > So I've added the content_type, object_id and content_object fields to
> > Address.
>
> > class Address(models.Model):
> >     """
> >     Basic object for holding address information - for either people
> > or institutions.
> >     """
> >     street_address = models.CharField(max_length=50)
> >     suburb = models.CharField(max_length=20)
> >     state = models.CharField(max_length=3,
> > choices=AUSTRALIAN_STATES_CHOICES)
> >     # PositiveIntegerField doesn't allow max_length? Have to use form
> > validation for this.
> >     postcode = models.CharField(max_length=4)
> >     # This should probably be a list of choices.
> >     country = models.CharField(max_length=20)
> >     address_category = models.OneToOneField(AddressCategory)
>
> >     # We make Address a generic relation model
> >     content_type = models.ForeignKey(ContentType)
> >     object_id = models.PositiveIntegerField()
> >     content_object = generic.GenericForeignKey('content_type',
> > 'object_id')
>
> >     class Meta:
> >         verbose_name_plural = 'Addresses'
>
> >     def __unicode__(self):
> >         return self.street_address + ', ' + self.suburb
>
> >  And my other objects have GenericRelations to Address. E.g.:
>
> > class Hospital(models.Model):
> >     name = models.CharField(max_length=20)
> >     address = generic.GenericRelation(Address)
>
> >     def __unicode__(self):
> >         return self.name
>
> > However, when I try and use the Django admin to add an Address item,
> > the form has fields for content_type and object_id. I had thought
> > these fields wouldn't appear? Also, the model won't validate/save if I
> > don't fill in these fields. I don't think I'm quite using this right -
> > is there a better way of doing what I'm trying to achieve here?
>
> > Also, I'm using the Address object as in Inline for the other models,
> > so I have an Address Inline as well (Nb: I'm using django-reversion
> > with this site, hence the "VersionAdmin")
>
> > class AddressAdmin(VersionAdmin):
> >     pass
> > class AddressInline(generic.GenericTabularInline):
> >     model = Address
> > ...
> > class HospitalAdmin(admin.ModelAdmin):
> >     inlines = [
> >         AddressInline,
> >     ]
> > ...
> > admin.site.register(Address, AddressAdmin)
>
> > Thanks,
> > Victor
>
> Hi,
>
> I think here what you're looking for is to use:
> address = models.ForeignKey(Address)
> rather than a GenericRelation.  GenericRelations are for cases when
> you don't know what the target model should be (hence the extra
> content_type field).
>
> --
> G
-- 
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: Generic Relations and Django Admin?

2010-01-19 Thread Victor Hooi
heya,

Thanks for the reply =).

I tried that, and the fields aren't there, but when I try to save the
object, I get a:

IntegrityError at /admin/people/address/add/
people_address.content_type_id may not be NULL

so obvoiusly Django doesn't like it if those fields aren't filled.

How do people normally do this sort of thing, with a polymorphic
object that's referenced by multiple other objects?

Cheers,
Victor

On Jan 19, 5:59 pm, Raffaele Salmaso 
wrote:
> Victor Hooi wrote:
> > class AddressAdmin(VersionAdmin):
> >     pass
> > class AddressInline(generic.GenericTabularInline):
> >     model = Address
> > ...
>
>       fields = (the fields you want to display)
> or
>       exclude = ('content_type', 'object_id',)
>
> > class HospitalAdmin(admin.ModelAdmin):
> >     inlines = [
> >         AddressInline,
> >     ]
> > ...
> > admin.site.register(Address, AddressAdmin)
>
> --
> ()_() | That said, I didn't actually _test_ my patch.      | +
> (o.o) | That's what users are for!                         | +---+
> 'm m' |                                   (Linus Torvalds) |  O  |
> (___) |              raffaele dot salmaso at gmail dot 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: Generic Relations and Django Admin?

2010-01-20 Thread Victor Hooi
heya,

The thing is, it's a one-to-many for UserProfile/Hospital/Institution
to Addresses - that is, each entity can (and probably will) have
multiple addresses. That's why the FK field is on Address.

Also, I thought that was the way it was traditionally modelled in
database design? (I admit I'm often confused by this part, so anybody
that can shed light on the rationale for one way or another, please
chime in).

Cheers,
Victor

On Jan 20, 12:20 am, LostCruz  wrote:
> Hi Victor,
>
> You are trying to do this the wrong way around. It shouldn't be the
> Adress class on which you want to define a relationship, but on the
> other classes. An address is an address whether it's the address of a
> User or the address of an Institution.
>
> class Address(models.Model):
>     # the field up until and including 'country'
>
> class Hostpital(models.Model):
>     name = models.CharField(max_length=20)
>     address = ForeignKey(Address)
>
> class YourUserClass(models.Model):
>     # all kinds of fields
>     address = ForeignKey(Address)
>
> Using Django's ORM system you then can get related Users and Hospitals
>
> Hope this helps.
>
> On 19 jan, 06:25, Victor Hooi  wrote:
>
>
>
> > heya,
>
> > I'm trying to use an "Address" model as a generic relation against
> > multiple other models (e.g. in a "User Profile", for each User, as
> > well as for "Building", "Institution", and various other ones).
>
> > So I've added the content_type, object_id and content_object fields to
> > Address.
>
> > class Address(models.Model):
> >     """
> >     Basic object for holding address information - for either people
> > or institutions.
> >     """
> >     street_address = models.CharField(max_length=50)
> >     suburb = models.CharField(max_length=20)
> >     state = models.CharField(max_length=3,
> > choices=AUSTRALIAN_STATES_CHOICES)
> >     # PositiveIntegerField doesn't allow max_length? Have to use form
> > validation for this.
> >     postcode = models.CharField(max_length=4)
> >     # This should probably be a list of choices.
> >     country = models.CharField(max_length=20)
> >     address_category = models.OneToOneField(AddressCategory)
>
> >     # We make Address a generic relation model
> >     content_type = models.ForeignKey(ContentType)
> >     object_id = models.PositiveIntegerField()
> >     content_object = generic.GenericForeignKey('content_type',
> > 'object_id')
>
> >     class Meta:
> >         verbose_name_plural = 'Addresses'
>
> >     def __unicode__(self):
> >         return self.street_address + ', ' + self.suburb
>
> >  And my other objects have GenericRelations to Address. E.g.:
>
> > class Hospital(models.Model):
> >     name = models.CharField(max_length=20)
> >     address = generic.GenericRelation(Address)
>
> >     def __unicode__(self):
> >         return self.name
>
> > However, when I try and use the Django admin to add an Address item,
> > the form has fields for content_type and object_id. I had thought
> > these fields wouldn't appear? Also, the model won't validate/save if I
> > don't fill in these fields. I don't think I'm quite using this right -
> > is there a better way of doing what I'm trying to achieve here?
>
> > Also, I'm using the Address object as in Inline for the other models,
> > so I have an Address Inline as well (Nb: I'm using django-reversion
> > with this site, hence the "VersionAdmin")
>
> > class AddressAdmin(VersionAdmin):
> >     pass
> > class AddressInline(generic.GenericTabularInline):
> >     model = Address
> > ...
> > class HospitalAdmin(admin.ModelAdmin):
> >     inlines = [
> >         AddressInline,
> >     ]
> > ...
> > admin.site.register(Address, AddressAdmin)
>
> > Thanks,
> > Victor
-- 
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: Generic Relations and Django Admin?

2010-01-20 Thread Victor Hooi
heya,

Hmm, I'm using generic.GenericTabularInline for the Address Inline, is
that the same?

class AddressAdmin(VersionAdmin):
exclude = ('content_type', 'object_id',)
...
class AddressInline(generic.GenericTabularInline):
model = Address
...
class HospitalAdmin(admin.ModelAdmin):
inlines = [
AddressInline,
]
...

Is there an error in the above?

Also, I'm still confused on whether I should have that exclude in
there? And the bug that Raffaele Salmaso pointed out (http://
code.djangoproject.com/ticket/12577), is that what's causing this?
(The traceback in the ticket is quite different to the traceback I'm
getting).

Cheers,
Victor

Cheers,
Victor

On Jan 19, 9:55 pm, Daniel Roseman  wrote:
> On Jan 19, 10:35 am, Victor Hooi  wrote:
>
> > heya,
>
> > Thanks for the reply =).
>
> > I tried that, and the fields aren't there, but when I try to save the
> > object, I get a:
>
> >     IntegrityError at /admin/people/address/add/
> >     people_address.content_type_id may not be NULL
>
> > so obvoiusly Django doesn't like it if those fields aren't filled.
>
> > How do people normally do this sort of thing, with a polymorphic
> > object that's referenced by multiple other objects?
>
> Edit the address inline with the parent object (hospital, etc) by
> using the generic.GenericInlineAdmin class - works exactly the same as
> a normal inline admin class, but using generic relations.
> --
> DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Fixtures Initial Data - Split Into Multiple Files?

2010-01-20 Thread Victor Hooi
heya,

This is a small question, is there any way for the initial_data.json/
xml/sql file to reference other files, or split it up across multiple
files?

Basically, I want to split up my existing monolithic files, into a
separate json file for each section (I'm basically using this to
populate all the lookup tables - e.g. for category names).

I couldn't find anything about this in the JSON spec, I'm not sure how
other people are doing this in Django? Or do you just put everything
in a single file?

Cheers,
Victor
-- 
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.




Scripting Import of CSV data?

2010-02-23 Thread Victor Hooi
heya,

I have a Django app that will need to grab CSV data being sent to an
email address into it's own database.

I'm assuming if I can get IMAP access to the mailbox, I can just
script all of that part in Python. However, what's the best way of
scheduling the process, so that it'll regularly check the mailbox?
Just make it a cron job, or is there a more integrated way of doing it
inside of Django?

Actually, is this the best way of doing it, importing the data this
way? Or if say, I could get access to the underyling database behind
those CSV files, would I be better off trying the approach here
(http://docs.djangoproject.com/en/dev/howto/legacy-databases/). Or
should I just import the data into a clean Django-originated database
and leave it at that?

Cheers,
Victor

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



Tagging - Extending by adding a rating?

2010-03-21 Thread Victor Hooi
heya,

I have a small Django app we're writing to hold reviews of newspaper
articles.

With each article, there's an arbitrary number of companies or
keywords associated with those articles. And for each of those
companies/keywords, there's either a rating (out of 10), or possibly
no rating (i.e. Null).

I was thinking of using django-tagging to add tags to each article,
but I'm not sure how on the best way to extend it to add in the
ratings. Should I somehow add a field to the tag model? I have a
feeling that's a very broken/improper way of doing things. Or is there
a better way of achieving what I want to do within Django?


Cheers,
Victor

-- 
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: Tagging - Extending by adding a rating?

2010-03-21 Thread Victor Hooi
Paolo,

Thanks for the quick reply =).

I did think of that, just using a M2M, however, that means I lose all
of the inherent features of django-tagging. For our case, that would
probably be things like helpers to do auto-complete for tags,
automatically parsing form inputs with commas into tags, tag-clouds
etc.

Is there any way to somehow leverage off django-tagging? Or am I
better of starting from scratch on this?

Cheers,
Victor

On Mar 22, 1:54 pm, Paulo Almeida  wrote:
> A possible solution would be to create a Many To Many relationship between
> articles and companies, with an intermediary model holding the ratings:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> - Paulo
>
>
>
> On Mon, Mar 22, 2010 at 2:41 AM, Victor Hooi  wrote:
> > heya,
>
> > I have a small Django app we're writing to hold reviews of newspaper
> > articles.
>
> > With each article, there's an arbitrary number of companies or
> > keywords associated with those articles. And for each of those
> > companies/keywords, there's either a rating (out of 10), or possibly
> > no rating (i.e. Null).
>
> > I was thinking of using django-tagging to add tags to each article,
> > but I'm not sure how on the best way to extend it to add in the
> > ratings. Should I somehow add a field to the tag model? I have a
> > feeling that's a very broken/improper way of doing things. Or is there
> > a better way of achieving what I want to do within Django?
>
> > Cheers,
> > Victor
>
> > --
> > 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: Tagging - Extending by adding a rating?

2010-04-06 Thread Victor Hooi
heya,

Hmm, I haven't thought about that. From what I can gather, the
"TaggedItem" model is what links "Tag" to your own model, via Generic
Relations - so it's basically the glue that binds the two.

I think adding another intermediary table between your model and
"TaggedItem" might break all the TagManager functionality. And there
still remains the issue of whether I'd need to fork/extend the
models.db in tagging.

I made a comment on django-tagging issues list here:

http://code.google.com/p/django-tagging/issues/detail?id=221&q=victorhooi

Not sure if anything will become of this *crosses fingers*.

Cheers,
Victor

On Mar 22, 9:19 pm, Paulo Almeida  wrote:
> I know django-tagging has the Tag model and the TaggedItem model. I wonder
> if it would be possible to create the Many to Many relationship between your
> Articles and this TaggedItem model, through a Ratings intermediary table. I
> have no idea if that would work (and keep all the django-tagging features),
> but that's something you can look into.
>
> Best,
> Paulo
>
>
>
> On Mon, Mar 22, 2010 at 3:21 AM, Victor Hooi  wrote:
> > Paolo,
>
> > Thanks for the quick reply =).
>
> > I did think of that, just using a M2M, however, that means I lose all
> > of the inherent features of django-tagging. For our case, that would
> > probably be things like helpers to do auto-complete for tags,
> > automatically parsing form inputs with commas into tags, tag-clouds
> > etc.
>
> > Is there any way to somehow leverage off django-tagging? Or am I
> > better of starting from scratch on this?
>
> > Cheers,
> > Victor
>
> > On Mar 22, 1:54 pm, Paulo Almeida  wrote:
> > > A possible solution would be to create a Many To Many relationship
> > between
> > > articles and companies, with an intermediary model holding the ratings:
>
> > >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > - Paulo
>
> > > On Mon, Mar 22, 2010 at 2:41 AM, Victor Hooi 
> > wrote:
> > > > heya,
>
> > > > I have a small Django app we're writing to hold reviews of newspaper
> > > > articles.
>
> > > > With each article, there's an arbitrary number of companies or
> > > > keywords associated with those articles. And for each of those
> > > > companies/keywords, there's either a rating (out of 10), or possibly
> > > > no rating (i.e. Null).
>
> > > > I was thinking of using django-tagging to add tags to each article,
> > > > but I'm not sure how on the best way to extend it to add in the
> > > > ratings. Should I somehow add a field to the tag model? I have a
> > > > feeling that's a very broken/improper way of doing things. Or is there
> > > > a better way of achieving what I want to do within Django?
>
> > > > Cheers,
> > > > Victor
>
> > > > --
> > > > 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.

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



DB Adapter for HTML5 Client Database Storage?

2010-04-07 Thread Victor Hooi
heya,

This is a bit of random musing, but I was wondering, how big a project
is it to write a DB adapter for the Client-side Client-side Database
Storage API in HTML5?

That is, there are already efforts to integrate in things like CouchDB
and MongoDB models, surely using HTML5's client-side Storage wouldn't
be too much of a stretch.

Are there any large barriers to an effort like this?

Cheers,
Victor

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



Inline and ForeignKeys - Weird ordering?

2010-04-14 Thread Victor Hooi
heya,

We're creating a small app to manage data-entry of publicat articles
in Django.

Each article has a category, a subject, a list of firms (as in the
companies mentioned), etc.

I'm trying to add firm as an inline to article, however, I think I've
got the ordered in the model all wrong, as it's telling me:

 has no ForeignKey to


Basically, each article can have one category, but there's obviously
many articles to each category.

An excerpt from models.py:

class Category(models.Model):
name = models.CharField(max_length=25)

def __unicode__(self):
return self.name

class Meta:
verbose_name_plural = "categories"

class Article(models.Model):
title = models.CharField(max_length=50)
publication_date = models.DateField()
abstract = models.TextField() # Can we restrict this to 450
characters?
category = models.ForeignKey(Category)
subject = models.ForeignKey(Subject)
source = models.ForeignKey(Publication)
page_number = models.CharField(max_length=20)
url = models.URLField()
firm = models.ManyToManyField(Firm)
#firm = models.ForeignKey(Firm)
spokesperson = models.ManyToManyField(Spokeperson)
#spokesperson = models.ForeignKey(Spokeperson)

And admin.py:

class CategoryInline(admin.TabularInline):
model = Category
...
class ArticleAdmin(admin.ModelAdmin):
inlines = [
CategoryInline,
]
...
admin.site.register(Article, ArticleAdmin)

Also, I noticed that dajngo-command-extensions, using the graph_models
command, it seems to ignore m2m relationships. It's really weird.

http://github.com/django-extensions/django-extensions/issues#issue/6

Has anybody else noticed something similar? Were there any major
changes to Django's m2m base recently?

Cheers,
Victor

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



Re: Inline and ForeignKeys - Weird ordering?

2010-04-15 Thread Victor Hooi
heya,

Just to clarify.

My understanding is that the FK should be on Articles, since that's
the many side of the many-to-one, and also the "child" in a sense.

However, I still wanted some way of creating categories on the "Add
Article" page - is there a way of doing inlines here, and having the
"Add Firm" embedded on that page (without having to open a new
window), or should I reverse the way my FK is?

Cheers,
Victor

On Apr 15, 3:58 pm, Victor Hooi  wrote:
> heya,
>
> We're creating a small app to manage data-entry of publicat articles
> in Django.
>
> Each article has a category, a subject, a list of firms (as in the
> companies mentioned), etc.
>
> I'm trying to add firm as an inline to article, however, I think I've
> got the ordered in the model all wrong, as it's telling me:
>
>  has no ForeignKey to
> 
>
> Basically, each article can have one category, but there's obviously
> many articles to each category.
>
> An excerpt from models.py:
>
> class Category(models.Model):
>     name = models.CharField(max_length=25)
>
>     def __unicode__(self):
>         return self.name
>
>     class Meta:
>         verbose_name_plural = "categories"
> 
> class Article(models.Model):
>     title = models.CharField(max_length=50)
>     publication_date = models.DateField()
>     abstract = models.TextField() # Can we restrict this to 450
> characters?
>     category = models.ForeignKey(Category)
>     subject = models.ForeignKey(Subject)
>     source = models.ForeignKey(Publication)
>     page_number = models.CharField(max_length=20)
>     url = models.URLField()
>     firm = models.ManyToManyField(Firm)
>     #firm = models.ForeignKey(Firm)
>     spokesperson = models.ManyToManyField(Spokeperson)
>     #spokesperson = models.ForeignKey(Spokeperson)
>
> And admin.py:
>
> class CategoryInline(admin.TabularInline):
>     model = Category
> ...
> class ArticleAdmin(admin.ModelAdmin):
>     inlines = [
>         CategoryInline,
>     ]
> ...
> admin.site.register(Article, ArticleAdmin)
>
> Also, I noticed that dajngo-command-extensions, using the graph_models
> command, it seems to ignore m2m relationships. It's really weird.
>
> http://github.com/django-extensions/django-extensions/issues#issue/6
>
> Has anybody else noticed something similar? Were there any major
> changes to Django's m2m base recently?
>
> Cheers,
> Victor

-- 
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: Anyone want to take over maintaining Instant Django?

2012-02-26 Thread Victor Hooi
Hi,

Whatever happened to this?

@sidmitra - did you manage to take over maintainership of this project?

If not, @cjl - do you still have the scripts for this?

Cheers,
Victor

On Thursday, 15 July 2010 23:25:44 UTC+10, sidmitra wrote:
>
>
> I would be willing to take it on or we can also do it as a community 
> effort? 
> Instant Django is how i got started into web dev and now i'm a full 
> time django freelancer so would love to give some love back. 
>
> -Sid 
> http://sidmitra.com 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/m3dY94ta3OgJ.
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.



Bulk Creating Django Models from CSV File?

2012-04-01 Thread Victor Hooi
Hi,

I have several large CSV files that I'm hoping to parse, and use to create 
Django objects. Each line looks might look something like this:

"Server Hostname", "Classification", "Country", "Operating System"

"foo.bar.com", "Prod", "Australia", "Solaris"

"alex.john.com", "Dev", "UK", "Linux"

"bob.hope.com", "UAT, "Japan", "Windows


For performance reasons, it would be nice to use something like 1.4's 
bulk_create:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.bulk_create
 

However, I noticed the caveat about it not populating the auto-incrementing 
PK field. What's the recommended way to populate the PK field then? How do 
you use it?

Secondly, the models will have FK relationships to other models (for 
instance, Classification, Country and Operating System would be stored in a 
lookup table). What's the best way to look these up, and assign the 
appropriate FK, whilst still preserving good performance and using bulk 
inserts?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bP0RG4NXJjEJ.
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.



Python-requests seems to 404 with Django/Tasty-pie?

2012-10-02 Thread Victor Hooi
Hi,

I have a Django app that's serving up a RESTful API using tasty-pie.

I'm using Django's development runserver to test.

When I access it via a browser it works fine, and using Curl also works 
fine:

curl "http://localhost:8000/api/v1/host/?name__regex=&format=json";


On the console with runserver, I see:

[02/Oct/2012 17:24:20] "GET /api/v1/host/?name__regex=&format=json 
> HTTP/1.1" 200 2845


However, when I try to use the Python requests module 
(http://docs.python-requests.org/en/latest/), I get a 404:

>>> r = 
> requests.get('http://localhost:8000/api/v1/host/?name__regex=&format=json')
> >>> r
> 


or:

>>> r = 
> requests.get('http://localhost:8000/api/v1/host/?name__regex=&format=json')
> >>> r
> 


or: 

>>> payload = { 'format': 'json'}
> >>> r = requests.get('http://localhost:8000/api/v1', params=payload)
> >>> r
> 
> >>> r.url
> u'http://localhost:8000/api/v1?format=json'


Also, on the Django runserver console, I see:

[02/Oct/2012 17:25:01] "GET 
> http://localhost:8000/api/v1/host/?name__regex=&format=json HTTP/1.1" 404 
> 161072


For some reason, when I use requests, runserver prints out the whole 
request URL, including localhost - but when I use the browser, or curl, it 
only prints out the part *after* the hostname:port

I'm assuming this is something to do with the encoding, user-agent or 
request type it's sending? Why does runserver print out different URLs for 
requests versus browser/curl?

Cheers, 
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ycLjP71ciAEJ.
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.



Re: Python-requests seems to 404 with Django/Tasty-pie?

2012-10-02 Thread Victor Hooi
heya,

Thanks for the tips - you're probably right, I might need to whip out 
wireshark or something and see what exactly is going on.

However, one thing I did notice - I normally have the http_proxy 
environment variable set, as we use a HTTP proxy at work.

However, if I unset the http_proxy variable, Python requests suddenly seems 
to start working again.

I tried to set the no_proxy variable, and put in localhost and 127.0.0.1 in 
there - however, Python requests doesn't seem to respect that?

Cheers,
Victor

On Tuesday, 2 October 2012 22:48:26 UTC+10, Cal Leeming [Simplicity Media 
Ltd] wrote:
>
> Hi Victor,
>
> I've had my fair share of exposure with python requests - so thought I'd 
> chime in.
>
> On first glance, this looks to be an issue with specifying the port number 
> into python-requests, doing so seems to send the entire "
> http://localhost:8000/api/v1/host/?name__regex=&format=json"; as the 
> request. However, further analysis shows that might not be the case.
>
> Looking at the python requests code;
> https://github.com/kennethreitz/requests/blob/develop/requests/models.py
>
> >>> urlparse.urlparse("http://localhost:8080/test/url?with=params";)
> ParseResult(scheme='http', netloc='localhost:8080', path='/test/url', 
> params='', query='with=params', fragment='')
>
> It then sends this directly into urllib3 using connection_from_url();
> https://github.com/shazow/urllib3/blob/master/urllib3/connectionpool.py
>
> This then calls the following;
> scheme, host, port = get_host(url)
> if scheme == 'https':
> return HTTPSConnectionPool(host, port=port, **kw)
> else:
> return HTTPConnectionPool(host, port=port, **kw)
>
> get_host -> parse_url()
> https://github.com/shazow/urllib3/blob/master/urllib3/util.py
>
> Tracing through urllib3 finally gets to parse_url();
>
> >>> urllib3.util.parse_url("http://localhost:8080/test/url?with=params";)
> Url(scheme='http', auth=None, host='localhost', port=8080, 
> path='/test/url', query='with=params', fragment=None)
>
> So, lets look at path_url() instead;
> https://github.com/kennethreitz/requests/blob/develop/requests/models.py
>
> >>> lol = requests.get("
> http://localhost:8000/api/v1/host/?name__regex=&format=json";)
> >>> lol.request.path_url
> '/api/v1/host/?name__regex=&format=json'
>
> Performing a test connection shows;
>
>  foxx@test01.internal [~] > nc -p8000 -l
> GET /api/v1/host/?name__regex=&format=json HTTP/1.1
> Host: localhost:8000
> Accept-Encoding: identity, deflate, compress, gzip
> Accept: */*
> User-Agent: python-requests/0.11.1
>
> So, from what I can tell, python requests is functioning normally.
>
> Personally, I'd say get wireshark running, or use the nc trick shown 
> above, perform 1 request using curl and 1 using python requests, then 
> compare the request headers.
>
> Can't throw much more time at this, but hope the above helps
>
> Cal
>
> On Tue, Oct 2, 2012 at 8:54 AM, Victor Hooi 
> > wrote:
>
>> Hi,
>>
>> I have a Django app that's serving up a RESTful API using tasty-pie.
>>
>> I'm using Django's development runserver to test.
>>
>> When I access it via a browser it works fine, and using Curl also works 
>> fine:
>>
>> curl 
>> "http://localhost:8000/api/v1/host/?name__regex=&format=json<http://localhost:8000/api/v1/host/?name__regex=&format=json>
>>> "
>>
>>
>> On the console with runserver, I see:
>>
>> [02/Oct/2012 17:24:20] "GET /api/v1/host/?name__regex=&format=json 
>>> HTTP/1.1" 200 2845
>>
>>
>> However, when I try to use the Python requests module (
>> http://docs.python-requests.org/en/latest/), I get a 404:
>>
>> >>> r = requests.get('
>>> http://localhost:8000/api/v1/host/?name__regex=&format=json')
>>> >>> r
>>> 
>>
>>
>> or:
>>
>> >>> r = requests.get('
>>> http://localhost:8000/api/v1/host/?name__regex=&format=json<http://localhost:8000/api/v1/host/?name__regex=&format=json>
>>> ')
>>> >>> r
>>> 
>>
>>
>> or: 
>>
>> >>> payload = { 'format': 'json'}
>>> >>> r = requests.get('http://localhost:8000/api/v1', params=payload)
>>> >>> r
>>> 
>>> >>

set_test_cookie() on every page?

2011-09-29 Thread Victor Hooi
Hi,

I've read the Django docs on setting test cookies 
(https://docs.djangoproject.com/en/dev/topics/http/sessions/#setting-test-cookies),
 
and I'm still a bit confused.

One of our views sets a session variable to remember the object a user is 
currently viewing (we figured it wasn't worth storing in the database for 
this).

Should I put set_test_cookie() on every view? That seems a bit 
silly/redundant.

However, if I only put it on the view that sets the session variable, 
doesn't that mean the user has to visit that page twice - once to set the 
cookie, and (since the if test will fail that first time) again to verify it 
was set? How will the user even know to do that?

Do people actually check for the test cookie these days, or do they just 
assume it's set?

But then if we call delete_test_cookie(), doesn't that mean we have to set 
it all over again if the user needs to sets thesession variable again? Or 
should we not call delete_test_cookie()

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VZwP7behBtAJ.
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.



View decorator for common navigation elements?

2011-09-29 Thread Victor Hooi
Hi,

We have a common navigation bar on nearly every page (view) that contains a 
dropdown - this dropdown is populated with items from a database table. This 
dropdown also has AJAX behaviour attached to it.

I'm thinking I can create a decorator that will retrieve the list from the 
database, and return a Python list

We can then wrap every single view in this decorator, and then pass the list 
to the template for rendering.

Firstly - is there a more elegant alternative, rather than wrapping every 
single view in this decorator? (Middleware? Or is that a poor fit here? 
Anything else?).

And secondly - are there are any performance issues here? We're making 
database calls with every single view, just to get a list for a navigation 
dropdown. Smarter way?

I know I can use the caching middleware to cache entire pages, or even 
template fragments - but how about caching a single list() like this? What 
are other methods people are using to tackle this?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/8cKewo2DudcJ.
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.



Re: set_test_cookie() on every page?

2011-09-30 Thread Victor Hooi
heya,

John - thanks for the reply.

In this case, it's an JQuery .post() call linked to a dropdown menu 
(https://groups.google.com/d/topic/django-users/tw0lM-QkdGw/discussion).

The dropdown is a common navigation element on every page. It's used to set 
a session variable that stores which object a user is working on at the 
moment (see attached screenshot).

In my webpage:

  $('#dropdown_choice').click(function() {

$.post("/set_conference", {"current_conference": "conference_name"}, 
function(data) {alert(data)});

});


Then in my view:

# TODO: Set test cookies (although if we're logged in, we can assume cookies 
works)

def set_current_conference(request):

if not request.is_ajax() or not request.method == 'POST':

return HttpResponseNotAllowed(['POST'])
request.session['current_conference'] = 
request.POST.get("current_conference")
return HttpResponse('Set current_conference to ' + 
str(request.POST.get("current_conference")))

 
So it seems I would need to put the set_test_cookie() logic on every page, 
since they could make this call from any page with the dropdown. Or is there 
another way?

How would people normally handle having an AJAX POST call like this to set a 
session variable?

Or should I just (dangerously) assume that cookies will work automatically? 
Alternative?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/OnnKcnL2oD0J.
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.

<>

Re: View decorator for common navigation elements?

2011-09-30 Thread Victor Hooi
heya,

I do like the idea of just including a custom template tag =).

Hmm, can custom template tags interact with models or query the database 
like that?

Firstly, Is it possible, and secondly, is it considered good practice? 

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ScSr2-kGquYJ.
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.



__unicode__ and u'%s'?

2011-10-01 Thread Victor Hooi
heya,

What's the recommended best practice for printing model fields in 
__unicode__?

Currently, I'm using (simply because the Django docs do):

def __unicode__(self):
return u'%s' % (self.name)

What's the rationale behind using the unicode literal u'%s'? Is it always 
needed, versus just return self.name?

And should I be using .format() instead? Or using something else?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/T1ENoBx4HooJ.
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.



Re: View decorator for common navigation elements?

2011-10-02 Thread Victor Hooi
heya,

This SO post seems to suggest that data and template tags shouldn't mix...

http://stackoverflow.com/questions/5046046/where-put-database-interaction-in-django-templatetags

Not sure how I feel about that myself - I see the philosophical argument 
behind it, but I don't see another more efficiently creating common page 
elements (like my category dropdowns).

Also, if you look at James Bennett's posts here:

http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/

His code actually *does* interact with the database, as does the blog post 
here 
(http://www.webmonkey.com/2010/02/use_templates_in_django/#Roll_your_own_template_tags).

Also, as an aside, each link on our category dropdown is bound to a JS click 
event - not sure how this would tie in with the custom template tag - 
separate tag for that part of it?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9cYeQwELEYsJ.
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.



Using render() with Form?

2011-10-03 Thread Victor Hooi
heya,

I was previously using the following to render a form:

from django.shortcuts import render_to_response, RequestContext
...
def upload_file(request):
...
return render_to_response('upload_form.html', {'form': form}, 
context_instance=RequestContext(request))

I can confirm that this works fine, form was rendered perfectly fine.

However, I read that render() is now the bee-knees...lol 
(http://stackoverflow.com/questions/5154358/django-what-is-the-difference-between-render-render-to-response-and-direct),
 
so I thought I'd switch to that:

from django.shortcuts import render
...
def upload_file(request):
...
return render('upload_form.html', {'form': form})


However, when I try to do that, I get an error:

Environment:


Request Method: GET
Request URL: http://localhost:8000/upload/

Django Version: 1.4 pre-alpha SVN-16922
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'card']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File 
"/Users/victorhooi/.virtualenvs/appname/src/django/django/core/handlers/base.py"
 
in get_response
  111. response = callback(request, *callback_args, 
**callback_kwargs)
File "/Users/victorhooi/djangoProjects/appname/card/views.py" in upload_file
  18. return render('upload_form.html', {'form': form})
File 
"/Users/victorhooi/.virtualenvs/appname/src/django/django/shortcuts/__init__.py"
 
in render
  40. context_instance = RequestContext(request, 
current_app=current_app)
File 
"/Users/victorhooi/.virtualenvs/appname/src/django/django/template/context.py" 
in __init__
  172. self.update(processor(request))
File 
"/Users/victorhooi/.virtualenvs/appname/src/django/django/core/context_processors.py"
 
in debug
  35. if settings.DEBUG and request.META.get('REMOTE_ADDR') in 
settings.INTERNAL_IPS:

Exception Type: AttributeError at /upload/
Exception Value: 'str' object has no attribute 'META'


Any idea from the above why this might be happening?

Thanks,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/f0sywLsLB28J.
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.



Re: Using render() with Form?

2011-10-03 Thread Victor Hooi
heya,

Aha, thanks guys. I can confirm that works fine now.

That'll teach me to read the API docs a bit better...lol, I just assumed it 
was a 1-to-1 swap with render_to_response, didn't check the arguments =).

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KYwa7jhg6IsJ.
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.



Import CSV to create multiple Models - Model Manager or in View?

2011-10-03 Thread Victor Hooi
heya,

I'm coding up a Django form which will let the user upload a CSV file, then 
create and save multiple Model instances for each row in the CSV file.

At the moment, I'm trying to decide where to put the code that parses the 
CSV file and creates/saves the models.

I don't think it'd be an instance method on the Model itself, since that's 
for working on individual instances, and you'd need to pass a valid instance 
to the method.

Would it go in a custom Model Manager? Or should I have this logic in the 
View itself?

Also, I need to figure out a good way of passing ValidationErrors from the 
model.save() and passing them back to the view to display the user.

What would be a good way of hooking that up?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/CiJuzj-Sh3wJ.
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.



Re: Import CSV to create multiple Models - Model Manager or in View?

2011-10-03 Thread Victor Hooi
heya,

@Shawn: Hmm, that looks like quite an interesting approach - so the 
ModelForm would handle the validation logic? =) Me likes! Haha.

I can parse the CSV and get the field names to match up (or just do a simple 
transform to get them to match).

However, how do I then pass this information into a ModelForm? Also, the CSV 
file is for creating multiple models - one model per CSV line - how will 
that work with a single ModelForm? Do I just call it repeatedly?

And how will I then capture the ValidationError and get them back in my 
form?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/wT8cDUDW62IJ.
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.



TemplateView compatible with permission_required decorator?

2011-10-05 Thread Victor Hooi
Hi,

I'm attempting to use one of the new class-based TemplateView with the 
permission_required decorator:

@permission_required('foo.count_peas')
class Pea(TemplateView):
template_name = "pea.html"

However, when I do that, I get an error:

Exception Type: AttributeError at /someurl/
Exception Value: 'function' object has no attribute 'as_view'


If I comment out the permission_required decorator, the view seems to work 
fine.

Are the new class-based views compatible with the permission_required 
decorator?

Or is there something I need to do to make them work together.

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/BLrtdUAyciYJ.
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.



Permission_require decorator, and redirecting to Login Page

2011-10-05 Thread Victor Hooi
heya,

I'm using the permission-required decorator with the inbuilt login view.

When I login as a user who has the appropriate permissions, it logs in fine, 
and all is good.

When I try to login as a user with valid credentials but lacking the 
appropriate permission, it simply keeps redirecting to the login page again 
- but doesn't display any error message at all.

I tried adding "{{ form.non_field_errors }}" to the form but it still 
doesn't display any error messages.

Is there any way to get it to display that your user lacks the appropriate 
permissions, as opposed to just redirecting to a blank login page again and 
again.

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/alIHHeQMVb4J.
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.



Re: Django - how to create a private subpage?

2011-10-11 Thread Victor Hooi
heya,

I might be misunderstanding your requriements, but could you use the 
@user_passes_test decorator with a has_perm check?

@user_passes_test(lambda u: u.has_perm('private_pages.foo'))

https://docs.djangoproject.com/en/dev/topics/auth/

You can probably make the lambda a bit smarter, instead of using has_perm, 
check if the pagename matches the username.

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/CxrZ-hFFD9QJ.
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.



Storing regex raw string literal in Django model?

2011-10-13 Thread Victor Hooi
Hi,

I have Django model and in one of the fields I need to store a regex string 
that I can later use.

class Foo(models.Model):
name = models.CharField(max_length=30, unique=True)
regex_string = models.TextField()


So for example, the regex_string field might be set to:

r'\d{2}'


I then try to retrieve this later, compile it as a regex expression and use 
it - however, it doesn't seem to work as planned:

>>> pattern = re.compile(ham.regex_string)
>>> print(pattern.match("22"))
None


Obviously if I pass the raw string literal in directly, it works fine:

>>> pattern = re.compile(r'\d{2}')
>>> pattern.match("22")
<_sre.SRE_Match object at 0x1505100>


If I actually print ham.regex_string, it returns:

u"r'\\d{2}'"


So it's a unicode string, but for some reason the backslashes are 
doubled-up?

What I actually need is a way to store a regex raw string literal, so that I 
can retrieve it later and use it in a regex.

Is there a better way of doing this?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/k7i1EJD2fVwJ.
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.



Changes to default project layout?

2011-11-08 Thread Victor Hooi
heya,

*NB: Not sure if this belongs in dev or general, but I'm assuming here - 
please let me know if I'm wrong.*

I just noticed there was a change made to startproject/startapp, and the 
default Django layout in trunk (yes, I'm a bit behind the curve...haha).

https://code.djangoproject.com/changeset/16964
https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py

Just a couple quick questions:

   1. Previously, we'd put the app name in INSTALLED_APPS in settings.py - 
   however, since settings.py now lives inside one of the Django apps, I 
   assume we don't need to put that app itself under INSTALLED_APPS? But we 
   should put any other apps in there, right?
   2. ./manage.py is setup with a default DJANGO_SETTINGS_MODULE - however, 
   what's the recommended practice if we want multiple settings.py files? 
   (e.g. development, testing and production environments). And I assume 
   having any other settings.py in other apps is a bad practice?
   3. I noticed there's a new wsgi.py file - anything we should be aware of 
   here? I suppose projects like gunicorn, django_extensions etc. will have to 
   be adapted to be aware of the changes? 

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KW9CF_D0axoJ.
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.



Re: Changes to default project layout?

2011-11-08 Thread Victor Hooi
heya,

Also, I noticed that there's no models.py file in the first app that 
startproject 
creates - I assume this is by design, right?

Hmm, what's the rationale behind it?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/nRLeLBLsde0J.
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.



Django

2011-12-01 Thread Victor Hooi
Hi,

I'm writing a  Django application to mange some XML configuration files 
through the Django-admin.

Currently, I'm converting the XML values/hierarchies into Django models.

After this, we also need to code an import - to import in configuration 
files and populate Django models based on them, and also an export, to 
export from our Django models back into the finished XML configuration 
files.

However, another way might be just to inspect the XSD files we have, and 
try to create the models from that.

I know there's django-models-schemas 
(https://bitbucket.org/eegg/django-model-schemas/wiki/Home), that is meant 
to generate XSD files from Django models. I'm not aware of anything going 
the other way (introspecting XSD files to get Django models).

However, what are your thoughts on this?

Is there an easier way of achieving the main goal - editing XMl 
configuration files through a Django interface? Things I should be aware of?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/iWVmPfYsrOQJ.
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.



Re: Django

2011-12-01 Thread Victor Hooi
heya,

Damn, I didn't edit the subject - apologies - if there's a moderator, can 
you change it to "Using Django to edit XML configuration files" please?

Thanks,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_7FYPrf30k0J.
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.



Re: Django

2011-12-02 Thread Victor Hooi
Hi,

The XML files are all configuration files, storing things like boolean 
configuration flags, timeout values, username/passwords, IP addresses and 
ports etc.

Some of them will maps somewhat logically to the relational model - for 
example, they'll be a configuration for an application, as well as each of 
it's sub-modules, as well as usernames/passwords linked to the application 
etc.

I've included three example XSD files - hopefully that will give you a 
better idea.

The reason we're using Django is I was hoping to leverage off the 
Django-admin, as well as Django forms, if need be, to provide an easy 
interface to edit the files, and enforce some validation rules (many of 
which aren't really contained in the XML/XSD files).

And the other issue is the configuration format may change over time, so 
we'll need to keep the models.py up-to-date, not sure of the best way to do 
that.

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/s3td-Oy5jG8J.
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.



CConfigRefData.xsd
Description: Binary data


CConfigFIXAA.xsd
Description: Binary data


CConfigXXX.xsd
Description: Binary data


Re: Bulk import of data

2011-12-05 Thread Victor Hooi
heya,

Hmm, I was previously under the impression that for these sorts of things 
(importing and instantiating models from CSV), the recommended way to 
create a ModelForm, and pass each line of the CSV through that, and have 
that handle model validation for you.

In our case, we have a CSV file, but quite a few of those lines are 
probably invalid/erroneous - we need to provide useful messages on those, 
and import the rest of the file.

Is the recommended way now to use bulk_create 
(https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create), 
process all the lines, and hit that in one call?

How would you handle invalid lines or validation errors for individual rows?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/qYfAZWsydQoJ.
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.



Django Forms and Twitter Bootstrap - Add fieldset, div wrapper and CSS labels to Django Forms?

2011-12-11 Thread Victor Hooi
Hi,

I'm attempting to use Django forms with Twitter's CSS library Bootstrap 
(http://twitter.github.com/bootstrap/):

The default form outputted by {{ form.as_p }} doesn't seem to be enough to 
be formatted nicely with Bootstrap.

You need to add a , as well as class="control-label" to each 
.

So for example, to output a single text field:


Text input


Help text here. Be sure to fill this out 
like so, or else!



Is there a way to easily get Django's form handling to produce a form like 
this? (I'd like to avoid hardcoding every form field in my template if 
possible).

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/BClad_qCrnEJ.
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.



Re: django/Data Base Advice

2012-01-02 Thread Victor Hooi
Hi,

Do you mean learning more about Django in general, or about the 
models.py/database portion specifically?

If you haven't done much web-development before, or used any MVC 
frameworks, I suggest you start by reading up on those - there's plenty of 
guides to that online.

In terms of learning database theory, I'd suggest either "Database Design 
for Mere Mortals" 
(http://www.amazon.com/Database-Design-Mere-Mortals-Hands/dp/0201694719), 
or "Database Design with UML and SQL" (http://www.tomjewett.com/dbdesign/).

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kGmkW-Gk7I8J.
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.



Using STATIC_URL in CSS/JS files?

2012-01-02 Thread Victor Hooi
Hi,

In Django, you can use {{ STATIC_URL }} in your HTML templates to point to 
the correct path for static files, however I'm wondering if there's any way 
to use it inside of CSS/JS files?

E.g. I have a CSS file that points to a PNG sprite, and I'd like a way to 
get it to point to {{ STATIC_URL}} without hardcoding the URL/path - any 
way?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/24ML6hwMPCAJ.
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.



Highlighting Active Navigation Link - correct approach?

2012-01-08 Thread Victor Hooi
hi,

I have a project where I'm using Bootstrap 
(www.github.com/twitter/bootstrap) with Django.

I need to add a CSS class ("active") to highlight the active navigation 
link.

Anyhow, I did some Googling:

http://www.turnkeylinux.org/blog/django-navbar
http://ilostmynotes.blogspot.com/2010/03/django-current-active-page-highlighting.html
http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/
http://stackoverflow.com/questions/340888/navigation-in-django
http://djangosnippets.org/snippets/1726/
http://stackoverflow.com/questions/7665514/django-highlight-navigation-based-on-current-page

The approach in the above seems to be to either use custom template tag, 
middleware or JS-hackery.

Is there a current consensus in the Django community in terms of what is 
the "correct" approach for this?

Is there a reason something like this isn't part of Django core, or an 
in-built templatetag?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Xx5Rk_rBuxIJ.
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.



Model method versus overriding save()

2012-12-07 Thread Victor Hooi
Hi,

I have a "ranking" field for an item that returns an integer between 1 to 
10 based on a number of criteria of each item.

My question is - what are the pros and cons of using a model method to 
return this, versus overriding the save() method and saving it directly 
into a normal IntegerField on that item?

I understand that model methods *won't* let me use them within QuerySet 
filters on that item - is there any way around that?

If I just override the model's save() method to get it recalculate and save 
that field each time, I can use it within QuerySet filters. Any cons with 
that approach?

What do you guys tend to use in your projects?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rpb_ZNSMS_8J.
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.



Re: Model method versus overriding save()

2012-12-09 Thread Victor Hooi
Hi,

Hmm, so are we saying that:

   - Using model methods uses less storage, but performs worse.
   - Overriding the model's save() method uses more storage, but performs 
   better.

I understand the storage part - but I'm a bit confused about the 
performance part - how does one perform better than the other?

Also - in terms of using them with QuerySets - there aren't any workarounds 
to use model methods with QuerySets are there? It seems like that would be 
a definite argument in favour of using the second method, right?

Finally - thanks for the tip about signals() - so should I be using 
something like django.db.models.signals.post_save in addition to overriding 
save(), or instead of it?

Cheers,
Victor

On Monday, 10 December 2012 10:49:22 UTC+11, Chris Cogdon wrote:
>
> Even though I'm a total database junkie (and where by that I mean 
> postgresql > mysql :) ), I have to agree with Mike. If you can keep it in 
> the model layer, do that. Once you start putting optimisations into the 
> database layer, you lose a lot of portability between databases: there is 
> no such thing as "standard SQL" for anything other than toy applications. 
> Optimisation tend to be very engine-specific.
>
> However, just remember that those optimisations are possible, and the 
> database is far more reliable for maintaining your invariants than the 
> client is.
>
>
>
> On Sunday, December 9, 2012 3:30:01 AM UTC-8, Mike Dewhirst wrote:
>>
>>
>>
>> For the sake of maintainability it might be better to keep all database 
>> manipulation in the model layer rather than split it betweem models and 
>> database. 
>>
>>
>>
>> and, well, that code is part of the 
>> > code base too. 
>>
>> Which means you need to keep pretty comprehensive documentation if you 
>> are doing database stuff in two areas. 
>>
>> Personally, I'd keep it all in the django ORM until the project is 
>> mature and requires the final molecule of optimisation. 
>>
>> Mike 
>>
>> > 
>> >- Tom 
>> > 
>> >> 
>> >> Derek 
>> >> 
>> >> [1] https://docs.djangoproject.com/en/dev/topics/signals/ 
>> >> 
>> >> On Saturday, 8 December 2012 04:27:50 UTC+2, Chris Cogdon wrote: 
>> >> 
>> >> It's a simple performance vs storage question. 
>> >> 
>> >> Storing a calculatable field also risks it getting out of sync 
>> >> with reality, but if you're doing the query on that _so_ much, 
>> >> then its usualyl worth it. 
>> >> 
>> >> Also, with the right database and a trigger, that's something the 
>> >> database can ensure for you. Ie, a field that the database updates 
>> >> for you. 
>> >> 
>> >> 
>> >> On Friday, December 7, 2012 5:54:37 PM UTC-8, Victor Hooi wrote: 
>> >> 
>> >> Hi, 
>> >> 
>> >> I have a "ranking" field for an item that returns an integer 
>> >> between 1 to 10 based on a number of criteria of each item. 
>> >> 
>> >> My question is - what are the pros and cons of using a model 
>> >> method to return this, versus overriding the save() method and 
>> >> saving it directly into a normal IntegerField on that item? 
>> >> 
>> >> I understand that model methods *won't* let me use them within 
>> >> QuerySet filters on that item - is there any way around that? 
>> >> 
>> >> If I just override the model's save() method to get it 
>> >> recalculate and save that field each time, I can use it within 
>> >> QuerySet filters. Any cons with that approach? 
>> >> 
>> >> What do you guys tend to use in your projects? 
>> >> 
>> >> Cheers, 
>> >> Victor 
>> >> 
>> >> -- 
>> >> You received this message because you are subscribed to the Google 
>> >> Groups "Django users" group. 
>> >> To view this discussion on the web visit 
>> >> https://groups.google.com/d/msg/django-users/-/G7fp5OLkapgJ. 
>> >> To post to this group, send email to django...@googlegroups.com. 
>> >> To unsubscribe from this group, send email to 
>> >> django-users...@googlegroups.com. 
>> >> For more options, visit this group at 
>> >> http:/

Storing versioned maps of application connections?

2013-03-02 Thread Victor Hooi
Hi,

We have a legacy Django application that parses configuration files for 
several in-house applications, builds up a map of those applications, 
including any network connections between them (based on IP address and 
port), then stores them in Django models.

Each application object will store several things, such as a process name 
(which is unique), the application binary and version, as well as any 
network connections (listening or connecting).

For simplicity (I'm assuming), each day they blow away the existing model 
instances, then reparse all the configuration, and build up a new map with 
new model instances.

I'm looking at using similar to django-reversion to add version control to 
this application (It probably will be django-reversion - I'm not aware of 
any viable alternatives to django-reversion).

Now, obviously, the current blowing away approach isn't going to work with 
Django-reversion.

However, say we do a re-parse, what's the best way of integrating 
django-reversion into the workflow?

I assume we'd need some way of linking an existing application model with 
the new one from each daily re-parse.

We could use the process name (which is unique), do a lookup to see if that 
process name already exists, get it if it does, write our new values to the 
model, then save it.

My understanding is that django-reversion will only pickup on the changed 
fields.

We'd need to do a lookup on every single application and a save though - 
there's probably a smarter way to bulk these? (I know there's bulk create 
in Django, I'm not aware of any bulk updates?).

Are there any performance considerations we should be wary of? (There are 
probably between 100-200 applications).

Cheers,
Victor

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




Using django-devserver with Werzbeug to debug an app - interactive debugger not being trigged?

2013-03-14 Thread Victor Hooi
Hi,

I'm trying to use django-devserver 
(https://github.com/dcramer/django-devserver) to debug localshop 
(https://github.com/mvantellingen/localshop), a Django-based Pypi server.

I've installed django-devserver and werzbeug.

I then added 'devserver' to INSTALLED_APPS, and have started it up:

(temp)Victors-MacBook-Air:code victorhooi$ localshop runserver --werkzeug
> Validating models...
> 0 errors found
> Django version 1.4.3, using settings 'localshop.settings'
> Running django-devserver 0.4.0
> Threaded werkzeug server is running at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
>  * Running on http://127.0.0.1:8000/


I then try to access the view that triggers a 500 Internal Server Error (in 
this case from a file being in the wrong location).

On the console, I can see:

127.0.0.1 - - [14/Mar/2013 20:31:00] "GET /simple/yolk/ HTTP/1.1" 401 -
> 127.0.0.1 - - [14/Mar/2013 20:31:03] "GET /simple/yolk/ HTTP/1.1" 401 -
> 127.0.0.1 - - [14/Mar/2013 20:31:04] "GET /simple/yolk/ HTTP/1.1" 200 -
> Internal Server Error: /packages/yolk/download/1/yolk-0.4.3.tar.gz
> Traceback (most recent call last):
>   File 
> "/Users/victorhooi/.venvs/temp/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/handlers/base.py",
>  
> line 111, in get_response
> response = callback(request, *callback_args, **callback_kwargs)
>   File 
> "/Users/victorhooi/.venvs/temp/lib/python2.7/site-packages/localshop-0.4.1-py2.7.egg/localshop/apps/packages/views.py",
>  
> line 171, in download_file
> logger.info(release_file.distribution.file)
>   File 
> "/Users/victorhooi/.venvs/temp/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/db/models/fields/files.py",
>  
> line 46, in _get_file
> self._file = self.storage.open(self.name, 'rb')
>   File 
> "/Users/victorhooi/.venvs/temp/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/files/storage.py",
>  
> line 33, in open
> return self._open(name, mode)
>   File 
> "/Users/victorhooi/.venvs/temp/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/files/storage.py",
>  
> line 156, in _open
> return File(open(self.path(name), mode))
> IOError: [Errno 2] No such file or directory: 
> u'/Users/victorhooi/code/source/y/yolk/yolk-0.4.3.tar.gz'
> 127.0.0.1 - - [14/Mar/2013 20:31:04] "GET 
> /packages/yolk/download/1/yolk-0.4.3.tar.gz HTTP/1.1" 500 -


However, I don't seem to get any interactive prompt, or a debugger, or 
anything?

The server just keeps going, ready to receive the next request. Is 
something stopping the debugger from triggering here?

Cheers,
Victor 

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




Deployment best practices - reasons?

2013-04-29 Thread Victor Hooi
Hi,

I'm currently looking at tidying up deployment for a Django app we use 
internally.

There's a couple of things that I know are best-practices, or it's just how 
I normally deploy Django apps, but I need to come up with strong cases for 
all of them. As in any organisation, if it ain't broke, don't fix it - so 
there needs to be a compelling argument from me to put them in place.

For example:

Why use Gunicorn? (versus just Apache)
Gunicorn is lightweight, uses less memory, and is easier to configure. 
Anything else?

Why use Apache/Nginx in front of Gunicorn? (versus just hitting Gunicorn on 
it's own)
Gunicorn isn't designed to be front-facing - so for example, it doesn't 
handle slow clients well. Ideally you'd want something like Nginx or Apache 
to buffer requests. Anything else?

Why use Supervisord (versus just init.d scripts with say ./manage.py 
run_gunicorn in there)?
Supervisord will restart crashed processes. Anything else?

Why use Sentry?
Allows easier viewing of errors. Anything else?

Cheers,
Victor

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




Store arbitrary key-value pairs in model?

2013-04-29 Thread Victor Hooi
Hi,

I have a Django application that will need to store arbitraty

Basically, there are a series of "job scripts" that are submitted by users 
and then run.

Each of these jobs scripts may have an arbitrary number of key-value pairs 
attached to them (for example, output directory, or search term, or email 
address etc.).

There variables are then used by each script. The set of variables varies 
for each job script.

Is there an easy way to model this within Django?

We could store a serialised dict as a blob, but that sounds rather hackish.

I was thinking a document database (e.g. MongoDB, or Couch DB) might be 
more suitable, however, I'd like to keep it within Django, if possible 
(Django and relational DBs are widely used where I am, and there's good 
support for them).

Cheers,
Victor

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




Design for storing likes/dislikes?

2013-07-16 Thread Victor Hooi
Hi,

We have a list of users, who are going to like/dislike various widgets.

My question is regarding how to store the like/dislikes.

Essentially, there can be three states between a user and a widget - like, 
dislike, and unrated, so it's not just a straight Boolean.

I'm thinking of just doing a M2M between user and widgets models, and then 
storing an extra field on that M2M.

I can either store a Boolean, for whether the item is liked/unliked - and 
then an unrated item simply won't be exist in the table.

Or I can store a integer (with a choice tupled defined), with say 
0=unrated, 1=like, 2 = unlike, and all possible combinations are listed.

We'll be doing queries to compare users, and see if their likes/dislikes 
intersect.

Are there any pros/cons of the two approaches for this given query, or is 
there perhaps a more efficient way of storing this data?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




  1   2   >