Re: Comparing BoundField values in templates

2009-03-12 Thread George Song

I think the easier way is just to write a custom widget which
subclasses RadioSelect and override the render() method to however you
want to output the HTML.

On Jan 19, 6:45 am, ekellner  wrote:
> Hi, I am having trouble working with a BoundField value in a template.
>
> What I have is a IntergerField that is represented by a set of Radio
> Buttons in html. I want to lay out these buttons myself, and plus
> there's javascript involved.  I don't believe there's a way to do this
> while letting the field render itself.
>
> I need to have the "checked" attribute set for the appropriate radio
> button, according to the bound field value on the form.    I am trying
> to do this manually -- to print out "checked" inside the input element
> a manual comparison of the bound field's value, but it isn't working.
>  Note that I need to do this even when the form doesn't validate, so I
> need to pull the value from form.field.initial or form.field.data
> selectively, and so I have a template filter tag to do this.
>
> Here's the code, isolated:
>
> ### a filter to get the bound field value independent of whether it
> comes from initial/data
> @register.filter
> def boundvalue(boundfield):
>         "Copied from BoundField.as_widget"
>         if not boundfield.form.is_bound:
>             data = boundfield.form.initial.get(boundfield.name,
> boundfield.field.initial)
>             if callable(data):
>                 data = data()
>         else:
>             data = boundfield.data
>         return data
>
> ### My Template
> 
>
> ### The HTML page:
> 
>
> As you can see, I am getting some kind of string-typed output on the
> page, so I've got *some* value. It casts to boolean true, but I
> haven't been able to successfully compare it to 0.
>
> If there's a better way to do this overall, I would also welcome
> suggestions.  I am not especially attached to solving this using
> string comparisons but the form.data hash seems to force me down this
> road.
>
> Thank you
> Elizabeth
--~--~-~--~~~---~--~~
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: Setting tzinfo for DateTimeFields with Postgresql - workaround

2009-09-28 Thread George Song

Sounds about right to me. Hopefully I'll have more time after this
month to pick this up again.

On Aug 16, 6:24 pm, Ramiro Morales  wrote:
> Hi George,
>
> On Thu, May 21, 2009 at 7:56 PM, George Song wrote:
>
> > Hi Glenn,
>
> > When you get the chance can you review my proposal[1] for fixing
> > DateTimeField in Django?
>
> > I'm going to try to get this in for 1.2 release.
>
> > [1]http://code.djangoproject.com/ticket/10587
>
> I've took the liberty of adding this to the Version1.2Features wikipage that 
> is
> currently being used as a bag of potential 1.2 modifications:
>
>  http://code.djangoproject.com/wiki/Version1.2Features?action=diff&ver...
>
> Feel free to fix  the description if the one I used isn't correct.
>
> Regards,
>
> --
> Ramiro Moraleshttp://rmorales.net
>
> PyCon 2009 Argentina - Vie 4 y Sab 5 Setiembre
> Buenos Aires, Argentinahttp://ar.pycon.org/2009/about/
--~--~-~--~~~---~--~~
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 Test Coverage

2009-04-30 Thread George Song

I've decided to release the test coverage app I've been using on my 
projects as open source. I've packaged it as a third-party Django app 
for convenience. But the underlying components can be used independently 
from Django as well.



-- 
George

--~--~-~--~~~---~--~~
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: Tables with same schema

2009-05-01 Thread George Song

Plain ol' Python multiple inheritance should work. Just define the
fields you want in some class:
{{{
class PersonMixin(object):
first = models.CharField(max_length=16)
last = models.CharField(max_length=16)

class Person(models.Model, PersonMixin):
pass

class Person2(models.Model, PersonMixin):
pass
}}}

On Apr 30, 10:58 pm, Ramashish Baranwal 
wrote:
> > > I want to create several tables with same schema. This is to partition
> > > the data into different tables. Apart from having model classes with
> > > same definition, is there another way to do it?
>
> > > Here is a trivial example that duplicates the class definition-
>
> > > class Person(models.Model):
> > >    first = models.CharField(max_length=16)
> > >    last = models.CharField(max_length=16)
>
> > > class Person2(models.Model):
> > >    first = models.CharField(max_length=16)
> > >    last = models.CharField(max_length=16)
>
> > > Apart from the code duplication, the above doesn't capture the intent
> > > that the two models represent tables with same schema. I'm looking for
> > > something like-
>
> > > class Person2(Person):
> > >    pass
>
> > > The above however doesn't work.
> > > Any idea?
>
> > > Thanks,
> > > Ram
>
> > I'd do it with one class that has all the common fields that is an abstract
> > class(check the docs for this).  And then just 2 classes that subclass it.
> > This should do just what you want.
>
> Hi Alex,
>
> Thanks for the quick reply. Abstract class fits the need perfectly.
> However, I am using Django 0.96 where abstract class functionality is
> not available. I can't upgrade  Django currently.
> Any other way?
>
> -Ram
--~--~-~--~~~---~--~~
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: Validation error when uploading jpeg via admin

2009-05-01 Thread George Song

On 5/1/2009 6:56 AM, Jason Sypolt wrote:
> I have pil 1.1.6 installed - it can find a jpeg decoder and all tests
> pass. I'm using django 1.0.2 and python 2.5 on centos 5.3. Whenever I
> try to upload a jpeg via the admin (ImageField), I get the following
> validation error.
> 
> "Upload a valid image. The file you uploaded was either not an image
> or a corrupted image."
> 
> Can anyone provide some help? This is driving me crazy. Thanks!

Are you able to successfully operate on *that* file using PIL directly 
in Python interactive shell?

-- 
George

--~--~-~--~~~---~--~~
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: Create a web service for an existing stand alone python script

2009-05-01 Thread George Song

On 5/1/2009 5:13 AM, pallavi wrote:
> For example lets say my python script is named "science.py" and it
> reads two input files for the input data : abc.txt  and xyz.txt and
> after computation the output file is : output.txt

If abc.txt and xyz.txt are available somehow directly on the application 
server w/o user upload, then you simply need to write a view that parses 
them and serves them out as the appropriate format. If you require users 
to upload abc.txt and xyz.txt, then you have a slightly more complicated 
issue of having another view which accepts those files as uploads.

So the simplest scenario could be something like this:

{{{
from django.http import HttpResponse

from science import my_function

def science_service(request):
 # assuming my_function takes abc.txt and xyz.txt
 # and turns them into some plain text output
 return HttpResponse(
 my_function('abc.txt', 'xyz.txt'), , mimetype="text/plain"
 )
}}}

--~--~-~--~~~---~--~~
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: Validation error when uploading jpeg via admin

2009-05-01 Thread George Song

Can you try the same operation using the Django development server and 
see what happens?

On 5/1/2009 7:19 AM, Jason Sypolt wrote:
> Also, I'm going through wsgi and not mod_python. Not sure if that
> makes a difference..
> 
> 
> On May 1, 10:12 am, George Song  wrote:
>> On 5/1/2009 6:56 AM, Jason Sypolt wrote:
>>
>>> I have pil 1.1.6 installed - it can find a jpeg decoder and all tests
>>> pass. I'm using django 1.0.2 and python 2.5 on centos 5.3. Whenever I
>>> try to upload a jpeg via the admin (ImageField), I get the following
>>> validation error.
>>> "Upload a valid image. The file you uploaded was either not an image
>>> or a corrupted image."
>>> Can anyone provide some help? This is driving me crazy. Thanks!
>> Are you able to successfully operate on *that* file using PIL directly
>> in Python interactive shell?

--~--~-~--~~~---~--~~
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: save_formset() in admin.TabularInline doesn't work.

2009-05-01 Thread George Song

On 5/1/2009 4:29 AM, eli wrote:
> Hi,
> 
> I have problem with save_form, save_model, save_formset methods in
> Admin class admin.TabularInline.
> 
> class AAdmin(admin.TabularInline):
> model = A1
> extra = 3
> 
> def save_form(self, request, form, change):
> print "form"
> return form.save(commit=False)
> 
> def save_model(self, request, obj, form, change):
> print "model"
> obj.save()
> 
> def save_formset(self, request, form, formset, change):
> print "formset"
> formset.save()
> 
> 
> class BAdmin(admin.ModelAdmin):
> inlines = [AAdmin]
> 
> def save_model(self, request, obj, form, change):
> super(BAdmin, self).save_model(request, obj, form, change)
> 
> When I save BAdmin in Admin Panel the method in AAdmin aren't called.
> 
> Where is the problem?

The problem is you're not telling us what it is you're trying to achieve.

It's hard to debug code without knowing what you're tying to do, other 
than to say what you already know -- this doesn't work. The fact that 
you are trying to override `save_formset()` in `AAdmin` tells me you're 
stabbing in the dark a little bit.

-- 
George

--~--~-~--~~~---~--~~
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: Displaying rows as columns

2009-05-01 Thread George Song

On 5/1/2009 5:47 PM, mamco wrote:
> Hi,
> In attempting to get a better grasp of Django, I'm attempting a fairly
> simple timecard app.  Multiple users of a small chain of retail
> stores, where occasionally the employees jump between stores(company),
> and between projects and activities.
> 
> The interesting model is something like this:
> 
> class Timecard(models.Model):
>  employee = models.ForeignKey(Employee)
>  company = models.ForeignKey(Company)
>  project = models.ForeignKey(Project)
>  activity = models.ForeignKey(Activity)
>  start = models.DateTimeField('The start time of the shift')
>  duration = models.DecimalField('The duration of the shift in
> hours',max_digits=4, decimal_places=2)
>  notes = models.TextField('Special Notes on the shift')
> 
> I've populated it with some data from a previous system (trying to
> reproduce with Django), and I'm now trying to display a form which
> shows a week at a time given a particular start date (which for now is
> always a Sunday).
> 
> I'm trying to show
> employee, company, project  on a single line followed by the totals
> (summing the activity as its always 'default' for now) for Sun to Sat
> and a total.
> 
> So something like the following (pipes show columns for this post
> purpose only):
> J Smith | BranchA | Admin | 0.0 | 4.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0 |
> 36.5
> J Smith | BranchA | Training | 0.0 | 3.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0
> | 36.5
> 
> Being new to Python and Django, I can't seem to get a function written
> to kick this output out.  Any pointers?

How would you approach this if you weren't using Python and Django? Is 
your inclination to do this using SQL or would you use an associative 
array of some sort in the programming language of your choice?

I guess what I'm trying to say is this really doesn't have much to do 
with Python/Django, but is a general data pivot problem. So my advice 
would be to search for a solution that fits your need. It doesn't matter 
what the language/framework the solution is in, it's the general pattern 
you're after.

A hint: I personally would avoid trying to do this in SQL, if nothing 
for the readability of the code.

-- 
George

--~--~-~--~~~---~--~~
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: Displaying rows as columns

2009-05-02 Thread George Song

On 5/1/2009 5:47 PM, mamco wrote:
> In attempting to get a better grasp of Django, I'm attempting a fairly
> simple timecard app.  Multiple users of a small chain of retail
> stores, where occasionally the employees jump between stores(company),
> and between projects and activities.
> 
> The interesting model is something like this:
> 
> class Timecard(models.Model):
>  employee = models.ForeignKey(Employee)
>  company = models.ForeignKey(Company)
>  project = models.ForeignKey(Project)
>  activity = models.ForeignKey(Activity)
>  start = models.DateTimeField('The start time of the shift')
>  duration = models.DecimalField('The duration of the shift in
> hours',max_digits=4, decimal_places=2)
>  notes = models.TextField('Special Notes on the shift')
> 
> I've populated it with some data from a previous system (trying to
> reproduce with Django), and I'm now trying to display a form which
> shows a week at a time given a particular start date (which for now is
> always a Sunday).
> 
> I'm trying to show
> employee, company, project  on a single line followed by the totals
> (summing the activity as its always 'default' for now) for Sun to Sat
> and a total.
> 
> So something like the following (pipes show columns for this post
> purpose only):
> J Smith | BranchA | Admin | 0.0 | 4.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0 |
> 36.5
> J Smith | BranchA | Training | 0.0 | 3.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0
> | 36.5

I always like to represent code as closely to how I think first and then 
optimize. There are probably more clever ways of achieving this, but 
this is generally how I would approach it (in pseudo code):

{{{
sd = datetime.date(start_date)
ed = datetime.date(end_date)
# Iterate to populat this, obviously
date_header = {
 datetime.date(first_day): 0,
 datetime.date(second_day): 1,
 datetime.date(third_day): 2,
 ...
 }

entries = TC.objects.range_filtered.values_list(
 'employee', 'company', 'project').order_by(...)

schedule = {}
timecards = Timecards.objects.range_filtered
for t in timecards:
 info = schedule.setdefault((t.employee, t.company, t.project), {})
 by_day = info.setdefault('by_day', [0]*len(date_header))
 i = date_header[datetime.date(t.start)]
 by_day[i] += t.duration
 info['total'] = info.get('total', 0) + t.duration
}}}

Pass `entries` and `schedule` as context vars to your template, and you 
can iterate through your schedule using ordered list of entries. You get 
the idea.

-- 
George

--~--~-~--~~~---~--~~
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: getting no such table error

2009-05-02 Thread George Song

On 5/2/2009 6:02 AM, tekion wrote:
> Exception Type: OperationalError at /play_django/page/start/save/
> Exception Value: no such table: mywiki_page_tags

Did you log into SQLite and see if that table exists?

-- 
George

--~--~-~--~~~---~--~~
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: Accessing related object data in template

2009-05-02 Thread George Song

On 5/2/2009 6:07 AM, Paddy Joy wrote:
> I have a model "Car" with a related model "Car_Attribute" where I
> store instance specific details.
> 
> 
> class Car(models.Model):
> name = models.CharField(max_length=50)
> 
> class Car_Attribute(models.Model):
> car = models.ForeignKey(Car)
> key = models.CharField(max_length=50)
> data = models.TextField()
> 
> I have written a custom template filter to retrieve attributes
> 
> from django import template
> 
> register = template.Library()
> 
> @register.filter(name='car_tag_get')
> def car_tag_get(value, arg):
> try:
> return value.car_attribute_set.get(key=arg).data
> except:
> return "#CAR_ATTRIBUTE_NOT_FOUND key: %s" % arg
> car_tag_get.is_safe = False
> 
> and in my templates I use
> 
> {{ car|car_tag_get:"colour" }}
> 
> This works fine but is there an easier or more practical way?

 on 
your Car model is perhaps the way to go.

-- 
George

--~--~-~--~~~---~--~~
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: Displaying rows as columns

2009-05-02 Thread George Song

On 5/2/2009 7:40 AM, George Song wrote:
> Pass `entries` and `schedule` as context vars to your template, and 
> you can iterate through your schedule using ordered list of entries.

There's also `django.utils.datastructures.SortedDict` so you can bypass 
the `entries` business and save yourself another query.

-- 
George

--~--~-~--~~~---~--~~
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: getting no such table error

2009-05-02 Thread George Song

On 5/2/2009 8:32 AM, tekion wrote:
> No, I ended up removing the db and recreating it via manage.py
> syncdb.  it works after this.
> 
> Next time I will log into SQL lite and check it out.
> 
> I am curious why running "manage.py syncdb" didn't work until I blow
> away the db and re-run it.

Is it possible you made model changes after the first time you ran syncdb?

-- 
George

--~--~-~--~~~---~--~~
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: Debug middleware

2009-05-02 Thread George Song

On 5/2/2009 9:53 AM, Malcolm Tredinnick wrote:
> On Sat, 2009-05-02 at 04:11 -0700, Kless wrote:
>> How to debug a middleware? I would print any variables for a
>> middleware that I'm building
>>
>> Is there any way to make it?
> 
> In any sensible web server setup, printing to sys.stderr will send the
> output the server's error log. With Django's development server (the
> "runserver") command, it will send the output to the console that you
> started the dev server from. So use
> 
> print >> sys.stderr, ""
> 
> to your heart's content.

Or you can always use `pdb` if you're running the development server.

-- 
George

--~--~-~--~~~---~--~~
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: Create a web service for an existing stand alone python script

2009-05-02 Thread George Song

On 5/2/2009 10:01 AM, pallavi wrote:
> Dear Mr.George,
> 
> Thank a lot for your help.
> But, in the python program "science.py"  there are several  functions
> that do some calculations by reading the values in the two input
> files.
> 
> your code:
>> from science import my_function
>>
>> def science_service(request):
> 
> but how can i define and import all the modules in "my_function" as
> you said.
> Or can I directly paste the complete python code under my_function. I
> am confused as I am completely new this field.
> 
> May I request you to let me know if it is possible to make my big
> python program as an executable (science.exe or some thing) and
> directly call it in the views.py for example.
> Your help will be highly appreciated. Eagerly looking forward for your
> help.
> Thank you. Best regards -Pallavi

Hi Pallavi,

I don't have the time or the inclination to teach you Python. You should 
learn that on your own. There are excellent resources on the web to help 
you with that.

Also you should keep a group discussion thread going by replying to the 
group, not to me directly.

-- 
George

--~--~-~--~~~---~--~~
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: print_r() in Django & SQL debug output

2009-05-02 Thread George Song

On 5/2/2009 4:53 PM, Okto Silaban wrote:
> Ok, I know this is not a PHP mailing list.. I just want to make the 
> question simpler.
> 
> I'm coming from CakePHP background.
> 
> 1. What Django template tags can I use to replace print_r() / var_dump() 
> in PHP?
> 2. How can I display SQL debug output?
> 
> *in cakePHP I can use debug() function to show the SQL debug. So I can 
> see what SQL query it runs
> 
> debug output example :
> 
> SELECT * FROM myapp_entry

Django has extensive documentation. It's advisable that you look it up 
first before asking:



--~--~-~--~~~---~--~~
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: Altering database object

2009-05-02 Thread George Song

On 5/2/2009 6:24 PM, Vedlen wrote:
> I've got multiple tuples, and I need all the fields.
> I just need to pass all the "moment" fields from the tuples, into my
> function.
> 
> Here is what my template looks like :
> 
> 
> {{ for s in Score }}
> {{ s.moment }}{{ s.someOtherField }}
> {{ endfor }}
> 
> 
> 
> It's like I'd need to do this :
> 
> 
> {{ for s in Score }}
> {{ DateFr(s.moment) }}{{ s.someOtherField }} tr>
> {{ endfor }}
> 
> 
> but it doesn't work since you can't call functions in templates :( so
> I need to alter the "moment" fields before getting to the template
> thing, you know what I mean. It's a pretty basic task when you know
> Django pretty well though, but I don't :)

I think the easiest solution for you is to write a custom method on your 
Score model:

{{{
class Score(models.Model):
 

 def date_fr_moment(self):
 return DateFr(self.moment)
}}}

In your template, you can just access it with s.date_fr_moment.

-- 
George


--~--~-~--~~~---~--~~
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: problem rendering html images in browser

2009-05-03 Thread George Song

On 5/3/2009 7:22 PM, Mac wrote:
> I've had trouble rendering images in my browser. I just get a broken
> link. Any thoughts on how to fix this? I'm working with the
> development server, and I've check my code carefully to insure the src=path/>  to the image file is correct. If I open the html template
> file with my browser, it does render the image, but in a view, it does
> not.

It would be helpful if you can dpaste your view/template code, as well 
as the rendered HTML.

-- 
George

--~--~-~--~~~---~--~~
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: ManyToMany with a "through" attribute in the admin profile

2009-05-03 Thread George Song

On 5/3/2009 8:17 PM, nbv4 wrote:
> On May 3, 3:51 pm, Ramiro Morales  wrote:
>> On Sun, May 3, 2009 at 4:26 PM, nbv4  wrote:
>>
>>> Everything is fine and dandy, except for when I want to use the admin
>>> interface to create a new route. All I see is a dropdown for the
>>> "often" field. I have to go to the RouteBase section of the admin to
>>> add the rest. Normally if there is a ManyToMany field, in the admin
>>> interface there will be a little green plus sign that you can use to
>>> create a new object to attach. If the "through" option is used, it
>>> doesn't show up. Why? Is there a way to change this behavior? Is this
>>> a bug or is there a reason for this?
>> See
>>
>> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>>
> 
> Gee whiz thanks a lot.
> 
> I've got one more problem. How do I access the information from within
> that intermediate class?
> 
> I can do:
> --
> r = Route.objects.get(pk=1)
> r.bases.all()
> 
> 
> and r will be a list of all bases. From within that Route object (r),
> is there anyway to get access to the RouteBase attributes? Something
> like r.sequence?

The intermediate class is no different than any other many-to-one 
related classes:


-- 
George

--~--~-~--~~~---~--~~
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: Os.path in window and linux help?

2009-05-03 Thread George Song

On 5/3/2009 9:36 PM, phan sarak wrote:
> this is the def in my view.py
> 
> #
> return ouputting_pdf('reports/employee_report_pdf.html',{
>  'pagesize':'A4',
>  'curr_employee':get_employee,
>  'status':status,
> 'url':'../'+settings.MEDIA_ROOT,
>  #'url':os.path.join('..',settings.MEDIA_ROOT),
> # 
> 'url':os.path.join(os.path.dirname(__file__),'site_media'),
>  'age':employee_age() })
> 
> --
> and this is mytemplate
> ---
> 
> 
> -
> this application is to make a report(reportlab,xhtml2pdf,pisa ) .it 
> works fine on my OS( Ubuntu )
> But the images could not display on other OS(Windows)
> look at my templates source code i try to works on cross platforms such 
> as linux ,windows.
> Anyone have an experience with os.path to work cross platforms Please 
> help me to resolve this problem.

Why aren't you just using settings.MEDIA_URL? Does xhmtl2pdf need a file 
URI? If so, you should take a look at urllib.pathname2url.

-- 
George

--~--~-~--~~~---~--~~
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: How to handle view/url situation (Newbie)

2009-05-03 Thread George Song

On 5/3/2009 9:54 PM, scott212 wrote:
> I'm reading through the djangobook and trying to build a small app as
> I go. The app is just a list that I can add to and delete entries
> from. Deleting is easy, but I'm not sure how the url/view portion
> should be handled.
> 
> http://127.0.0.1:8080/lists/show/
> 
> list item 1 - [delete]
> list item 2 - [delete]
> list item 3 - [delete]
> 
> When an item is deleted, I would just like it to return to the same
> url. The way I'm seeing to do it would leave a somewhat ugly and
> irrelevant url (lists/delete/item1) while viewing the list. What's a
> more proper way to do this?
> 
> #urls.py
> 
> urlpatterns = patterns('',
> (r'^lists/show/$', showItems),
> (r'^lists/delete/([^/]+)$', deleteItem)
> )
> 
> 
> #views.py
> 
> def showItems(request):
> # get the items from the model
> return render_to_response('lists/show.html', {'items':items})
> 
> def deleteItems(request, item):
> # delete the item
> return render_to_response('lists/show.html', {'items':items})

The HTTP protocol is your friend:


-- 
George

--~--~-~--~~~---~--~~
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: Anyone else having issues with filter_horizontal in trunk?

2009-05-04 Thread George Song

On 5/4/2009 8:24 AM, Brandon Taylor wrote:
> filter_vertical also appears to be suffering the same problem.
> 
> On May 4, 10:23 am, Brandon Taylor  wrote:
>> Hi everyone,
>>
>> When I specify filter_horizontal for any ManyToMany field on a model
>> using Django trunk, and that field is required, admin will not allow
>> me to save the choice(s). it will tell me the field is required, no
>> matter how many choices I select.
>>
>> If I remove the filter_horizontal, and I make selection(s), the form
>> will submit properly.
>>
>> Anyone else seeing the same issue?

I just tested it in my app and it's fine.

-- 
George

--~--~-~--~~~---~--~~
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: data too long in a CharField column

2009-05-04 Thread George Song

On 5/4/2009 8:46 AM, MS wrote:
> I have a problem with django+postgresql:
> I have a model with a CharField(max_length=255) field, and I'm
> assigning some much longer value to this field, like:
> 
> m = MyModel()
> m.myfield = 'very long text - say 400 chars'
> m.save()
> 
> In save() I'm getting an error "ERROR:  value too long for type
> character varying(255)", and the SQL statement contains the 'very long
> text - say 400 chars' intact.
> 
> I thought that if django knows that a field is restricted to 255
> chars, then it will validate it and
> truncate excessive chars before saving. But it doesn't. How can I get
> rid of that problem?

If you want that behavior, just truncate `myfield` in `MyModel.save()` 
before calling the super save.



-- 
George

--~--~-~--~~~---~--~~
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: form elements css changes on errors

2009-05-04 Thread George Song

On 5/4/2009 10:23 AM, joeygartin wrote:
> I would like to add a css class to form elements if there is an error
> in the form.  Not sure the BEST/EASIEST way to do this.  I would only
> want the attribute added if there was an error and I would like to do
> this in the cleanest way possible.  Meaning I would LIKE to stay away
> from if statements for every form element I have in the HTML and
> rather put the proper code in Python (perhaps forms.py with the form
> declaration), but I am new and not exactly sure how to proceed.

Once you've determined that your form didn't validate, something like 
this should work:

{{{
for field_name in form.errors:
 form.fields[field_name].widget.attrs['class'] = 'error'
}}}

Then just output your form again.

-- 
George

--~--~-~--~~~---~--~~
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: ManyToMany with a "through" attribute in the admin profile

2009-05-05 Thread George Song

On 5/4/2009 6:36 PM, nbv4 wrote:
> 
> 
> On May 4, 12:03 am, George Song  wrote:
>> On 5/3/2009 8:17 PM, nbv4 wrote:
>>
>>
>>
>>> On May 3, 3:51 pm, Ramiro Morales  wrote:
>>>> On Sun, May 3, 2009 at 4:26 PM, nbv4  wrote:
>>>>> Everything is fine and dandy, except for when I want to use the admin
>>>>> interface to create a new route. All I see is a dropdown for the
>>>>> "often" field. I have to go to the RouteBase section of the admin to
>>>>> add the rest. Normally if there is a ManyToMany field, in the admin
>>>>> interface there will be a little green plus sign that you can use to
>>>>> create a new object to attach. If the "through" option is used, it
>>>>> doesn't show up. Why? Is there a way to change this behavior? Is this
>>>>> a bug or is there a reason for this?
>>>> See
>>>> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-...
>>> Gee whiz thanks a lot.
>>> I've got one more problem. How do I access the information from within
>>> that intermediate class?
>>> I can do:
>>> --
>>> r = Route.objects.get(pk=1)
>>> r.bases.all()
>>> 
>>> and r will be a list of all bases. From within that Route object (r),
>>> is there anyway to get access to the RouteBase attributes? Something
>>> like r.sequence?
>> The intermediate class is no different than any other many-to-one
>> related classes:
>> <http://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects>
>>
> 
> 
> It's not possible to get those attributes unless I make another query?
> Basically I have one object that has a TON of related fields, some
> ForeignKey, some ManyToMany. Is it possible to pass just one instance
> of that one object to a Template and have access to the whole shebang
> through that one object? The link you gave me suggests that, but it
> just doesn't seem right...

Well, it is possible. Having an intermediate table for m2m suggests you 
need two pieces of information to locate a specific record. If you just 
to loop through all RouteBase objects for a certain Route object, you 
can just do:
{{{
for rb in r.routebase_set.all():
 do_something_with(rb.base)
 do_someotherthing_with(rb.other_rb_field)
}}}

-- 
George

--~--~-~--~~~---~--~~
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: "Lookups that span relationships" + objects.exclude()

2009-05-05 Thread George Song

On 5/5/2009 12:47 AM, bweiss wrote:
> Thanks Alex, that's really helpful and I'm certainly closer  now!
> However, after a fair bit of experimenting with that exclude() method,
> I still can't quite get it to do what I need.
> 
> I'm trying to get a list of all employees who do not have a
> qualification of a certain type (which I'llcall 'A1').
> 
> I can get a list of those who do have the qualification by using a
> lookup on the related "Qualification" model as follows:
> Employee.objects.filter(qualification__type__exact='A1')
> 
> Essentially, what I need is a list of all Employees, minus the names
> on that filtered list.
> 
> If I use the exclude()  method on the same lookup (so,
> Employee.objects.exclude(qualification__type__exact='A1')), the query
> returns those employees who have a qualification of any type other
> than A1.  It doesn't include the employees who have no qualifications
> at all, and it *does* include the ones who have A1 as well as other
> qualifications.
> 
> Can anyone suggest what I'm doing wrong?

{{{
excludes = Employee.objects.filter(
 qualification__type__exact='A1').values_list('pk', flat=True)
what_you_want = Employee.objects.exclude(pk__in=excludes)
}}}

or

{{{
all = Employee.objects.all()
excludes = Employee.objects.filter(qualification__type__exact='A1')
what_you_want = set(all) - set(excludes)
}}}

-- 
George

--~--~-~--~~~---~--~~
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: Create a web service for an existing stand alone python script

2009-05-05 Thread George Song

On 5/5/2009 4:39 AM, pallavi wrote:
> Dear all,
> thans for your input.
> I read doumentation from different resources and still confused to
> solve my problem. any help would be appreciated.
> 
> My main python program is science.py
> it have several modules.in it (each definition reads some parameters
> and results some data, that will be read
> by next module). but at the end, only few of the results are printed
> to a data file.
> 
> science.py
> ---
> def function1(parameter1,parmeter2) :
>   {
>-
>-
>   }
>   return data1
> 
> def function2(data1,parmeter3) :
>   {
>-
>-
>   }
>   return data2
> 
> #output is printed to a file as data.dat that contains data1, data2
> 
> 
> view.py
> 
> from django.http import HttpResponse
> from science import function1
> from science import function2
> 
> def science_service(request):
>  return HttpResponse(
>  # function1 reads parameter1, and parameter2
>  function1 (parameter1, parameter2), , mimetype="text/plain"
>  )
> 
> def science_service(request):
>  return HttpResponse(
>  function2 (data1, parameter3), , mimetype="text/plain"
>  )
> 
> 
> is this the correct way to write my view based on George's
> suggestion:
> i keep my science.py in the current working directory.
> pls shed some lightyour suggestions are very valuable for novice
> like me.

You're on the right track.

1. You can't name both views the same, if they're in the same module. 
Otherwise the second definition will override the first one.
2. There's a slight mistake in your response:
{{{
def science_service(request):
 return HttpResponse(
 function1(p1, p2), mimetype="text/plain"
 )
}}}

Of course you'll have to instantiate p1 and p2 somewhere in the module, 
if you're not passing those in through the request somehow.

-- 
George

--~--~-~--~~~---~--~~
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: "Lookups that span relationships" + objects.exclude()

2009-05-05 Thread George Song

On 5/5/2009 12:47 AM, bweiss wrote:
> So to enter a Qualification obtained, users choose a name from the 
> data in the Employee table, and a Qualification Type from the data in
>  that table, and then enter the remaining details (eg.  date 
> obtained, expiry date).

Also the Qualification table is an "intermediate" many-to-many table. 
You might want ot model it as such so your domain is more accurately 
reflected.

I haven't tested it yet, but it might be the case that if you do this, 
Django will perform the outer join for you automatically when you use 
your original exclude filter.

See:


-- 
George

--~--~-~--~~~---~--~~
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: TIME_ZONE problem

2009-05-05 Thread George Song

On 5/5/2009 6:48 AM, Michel Thadeu Sabchuk wrote:
> Hi guys,
> 
> I'm having a weird problem with TIME_ZONE settings. Some view list
> objects based on the time, future time objects are not shown.
> 
> The problem is that sometimes all objects that need to be shown appear
> normally, sometimes the latest objects are not shown.
> 
> Digging on the problem I found that sometimes my os.environ['TZ'] are
> set to 'America/Sao_Paulo' (the correct one) and sometimes it is the
> default 'America/Chicago'. I can't see any reason to this problem.
> 
> I using python2.5 with django1.1-beta installed on a vps with ubuntu
> hardy. My django settings module have the following line:
> 
> TIME_ZONE = 'America/Sao_Paulo'
> 
> And my apache virtual host configuration has the following:
> 
> 
> SetHandler python-program
> PythonPath "['/path-to-my-project/'] + sys.path"
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE portal.settings
> PythonDebug Off
> 
> 
> Does someone facing the same problem? Does anyone has a suggestion?

That is very odd indeed. Are there other Django instances within the 
same virtual host?

-- 
George

--~--~-~--~~~---~--~~
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: restrict choice of recursive many to many relation

2009-05-05 Thread George Song

On 5/5/2009 12:29 PM, Bastien wrote:
> This is quite new to me, I have done a recursive (self) many to many
> relation between blog entries so they can be linked together if the
> user thinks they are semantically related. It works but I would like
> to restrict the choices I can see in the admin list box: right now I
> can see every blog entry but I would like to see only the blog entries
> that belong to a given category. Can I refine the query?
> 
> That's what I have for now:
> related_entries  = models.ManyToManyField('self', blank=True,
> symmetrical=False, related_name='original_entries')

ModelAdmin has a `formfield_for_dbfield` hook. You can probably do 
something clever with that.

-- 
George

--~--~-~--~~~---~--~~
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: restrict choice of recursive many to many relation

2009-05-05 Thread George Song

On 5/5/2009 12:29 PM, Bastien wrote:
> This is quite new to me, I have done a recursive (self) many to many
> relation between blog entries so they can be linked together if the
> user thinks they are semantically related. It works but I would like
> to restrict the choices I can see in the admin list box: right now I
> can see every blog entry but I would like to see only the blog entries
> that belong to a given category. Can I refine the query?
> 
> That's what I have for now:
> related_entries  = models.ManyToManyField('self', blank=True,
> symmetrical=False, related_name='original_entries')

There's also `limit_choices_to` param:


-- 
George

--~--~-~--~~~---~--~~
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: Can not get Django admin page

2009-05-05 Thread George Song

On 5/5/2009 8:57 AM, David wrote:
> Hello,
> 
> I am following  those steps in django tutorial 2,  however I can not
> get "django administration: Username and Password" page. I still get
> the "Welcome" page.
> 
> I did these steps twice but I got the same result.
> 
> 1.   Add "django.contrib.admin" to your INSTALLED_APPS setting.
> 2.   Run python manage.py syncdb. Since you have added a new
> application to INSTALLED_APPS, the database tables need to be
> updated.
> 3.   Edit your mysite/urls.py file and uncomment the lines below the
> “Uncomment the next two lines...”
> 
> Can anybody tell me what I should do to fix this?
> 
> Thanks so much.

What URL are you accessing? If you're using the local development server 
you should be hitting http://localhost:8000/admin/.

-- 
George

--~--~-~--~~~---~--~~
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: Django custom ManyToManyField widget

2009-05-06 Thread George Song

On 5/6/2009 6:07 AM, atik wrote:
> When i create a ModelForm from a Model with a ManyToManyField in it,
> the default widget creates a select drop down with all the foreign key
> objects in it. I want to replace the widget with a textarea with a
> comma separated list of names.How can i do this? I am using django
> 1.02. Plz help me.

Usability issues aside, you can easily achieve this by writing your own 
custom widget.

You can subclass from the `SelectMultiple` widget and override the 
`render()` and `value_from_datadict()` methods.

Good luck.

-- 
George

--~--~-~--~~~---~--~~
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: Getting to the 'latest' item in a template list

2009-05-06 Thread George Song

On 5/5/2009 5:13 AM, Alfonso wrote:
> I'm using the following to pull all cost prices that match a
> particular product by the company that supplied the product:
> 
> View:
> 
> cost_prices = ProductCostPrice.objects.filter
> (product_id__product_id=product_id)
> 
> Template:
> ...
> {% regroup cost_prices|dictsort:"supplier" by supplier as cost_list %}
>   {% for cost in cost_list %}
> {% for item in cost.list %}
> 
>   {{ item.date_cost|date:"d/m/Y" }}
>   {{ item.supplier }}
>   {{ item.cost_price_gross }}
>  
> {% endfor %}
>   {% endfor %}
> 
> Works great - only thing is that in some cases there is more than one
> cost price in the db for a supplier, how do I just grab the latest
> price entered for each supplier?  Familiar with latest() lookup but
> not sure about it's use in the above scenario. I feel I should know
> this but can't make it work.  FYI there is normally more than one
> supplier for a product hence why it's set up like this.

You might be able to solve this with some fancy SQL. However, the way I 
would approach it is to model how you would use this information in your 
domain.

Since you have the need to know what the "latest" price is for a given 
product/supplier combination, I would add a `ProductCostPrice.is_latest` 
boolean field. At `ProductCostPrice.save()` you can use whatever logic 
you like to determine what the value of that flag should be for all rows 
with that product/supplier combination, ensuring only one record has 
is_latest=True. That way it's trivial to filter on that field. And the 
data also makes sense directly in the table.

By the way, `filter(product_id__product_id=product_id)` looks funny to 
me. Are you sure you don't want just `filter(product__pk=product_id)`?

-- 
George

--~--~-~--~~~---~--~~
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: TIME_ZONE problem

2009-05-06 Thread George Song

On 5/6/2009 4:02 AM, Graham Dumpleton wrote:
> 
> 
> On May 6, 4:38 am, George Song  wrote:
>> On 5/5/2009 6:48 AM, Michel Thadeu Sabchuk wrote:
>>
>>
>>
>>> Hi guys,
>>> I'm having a weird problem with TIME_ZONE settings. Some view list
>>> objects based on the time, future time objects are not shown.
>>> The problem is that sometimes all objects that need to be shown appear
>>> normally, sometimes the latest objects are not shown.
>>> Digging on the problem I found that sometimes my os.environ['TZ'] are
>>> set to 'America/Sao_Paulo' (the correct one) and sometimes it is the
>>> default 'America/Chicago'. I can't see any reason to this problem.
>>> I using python2.5 with django1.1-beta installed on a vps with ubuntu
>>> hardy. My django settings module have the following line:
>>> TIME_ZONE = 'America/Sao_Paulo'
>>> And my apache virtual host configuration has the following:
>>> 
>>> SetHandler python-program
>>> PythonPath "['/path-to-my-project/'] + sys.path"
>>> PythonHandler django.core.handlers.modpython
>>> SetEnv DJANGO_SETTINGS_MODULE portal.settings
>>> PythonDebug Off
>>> 
>>> Does someone facing the same problem? Does anyone has a suggestion?
>> That is very odd indeed. Are there other Django instances within the
>> same virtual host?
> 
> It doesn't strictly have to be other Django instances, it can be PHP
> or mod_perl as well. Basically anything that runs embedded in Apache
> processes and which expects a different timezone setting.
> 
> For case where only running Python applications, for mod_wsgi this
> problem is described in:
> 
>   
> http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_Locale_Settings
> 
> Same thing with mod_python, but with mod_python no way around it.

With mod_python, can you just use multiple interpreters?
<http://www.modpython.org/live/mod_python-3.2.5b/doc-html/pyapi-interps.html>

-- 
George

--~--~-~--~~~---~--~~
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: Help with some models inheritance and the use of default

2009-05-06 Thread George Song

On 5/6/2009 6:56 AM, Felix wrote:
> I have the next models:
> 
> class Place(models.Model):
> currency = models.CharField(_('currency'), max_length=128,
> blank=True, null=True)
> language = models.CharField(_('official language'),
> max_length=128, blank=True, null=True)
> class Meta:
> abstract = True
> 
> class Country(Place):
> country = models.CharField(_('country'), max_length = 100)
> continent = models.CharField(_('continent'),
> choices=CONTINENT_CHOICES, max_length = 2, blank = True, null=True)
> president = models.CharField(_('president'), max_length = 100,
> blank = True, null=True)
> 
> class City(Place):
> city = models.CharField(_('city'), max_length=100)
> country = models.ForeignKey(Country)
> language = ??
> 
> How can I set language of the to the language of its country's
> language by default?

I think the easiest thing is to put the logic in your `City.save()` 
method, since you'll have access to the instance's country at that 
point. Then it's just a matter of looking up the country to language 
mapping somewhere.

-- 
George

--~--~-~--~~~---~--~~
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: Django and a basic SQL join

2009-05-06 Thread George Song

On 5/6/2009 9:48 AM, jrs_66 wrote:
> I have 2 models...
> 
> class Category(models.Model):
> name = models.CharField(max_length=255)
> parent = models.ForeignKey('self', null=True)
> has_children = models.BooleanField(default=False)
> language = models.ForeignKey(Language, null=False, default=1)
> active = models.BooleanField(default=False)
> priority = models.IntegerField(null=False, default=5)
> display_treatment = models.IntegerField(null=False, default=5)
> last_update = models.DateTimeField(auto_now=True)
> 
> def __unicode__(self):
> return self.name
> 
> class Meta:
> verbose_name_plural = "Categories"
> db_table = u'categories'
> 
> class FlattenedCategory(models.Model):
> category = models.ForeignKey(Category)
> member_of_category = models.ForeignKey(Category,
> related_name='memberof')
> language = models.ForeignKey(Language)
> hidden = models.IntegerField()
> class Meta:
> db_table = u'flattened_category'
> 
> 
> I have a Queryset...
> 
> e = FlattenedCategory.objects.select_related('category').filter
> (member_of_category=15)
> 
> which works... This, however, doesn't
> 
> e = e.category
> 
> How do I access the related records from the Category model?
> 
> Thanks.
> 
> ps... Please refrain from commenting if the best you have is 'read the
> docs'...

e.category_set is what you want.

And, yes, please read the docs.

-- 
George

--~--~-~--~~~---~--~~
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: Django and a basic SQL join

2009-05-06 Thread George Song

In your case e is a QuerySet, with multiple FlattenedCategory objects.

So the proper code would be to loop through them:

{{{
for fc in e:
 fc.category_set
}}}

On 5/6/2009 10:17 AM, jrs_66 wrote:
> No...   'QuerySet' object has no
> attribute 'category_set'
> 
> George,
> 
> I have read the docs... MANY times... from the docs...
> 
> 'Django also creates API accessors for the "other" side of the
> relationship -- the link from the related model to the model that
> defines the relationship. For example, a Blog object b has access to a
> list of all related Entry objects via the entry_set attribute:
> b.entry_set.all().'
> 
> If you would look at my model, you will see that I'm not attempting to
> join 'backwords'... forwards, my man... please review the docs for
> more info.
> 
> This is definitely the most angry forum I've ever seen... the kicker
> is that the anger is almost always coming from the people associated
> with the django project... hmmm..
> 
> On May 6, 12:48 pm, jrs_66  wrote:
>> Hi,
>>
>> I have 2 models...
>>
>> class Category(models.Model):
>> name = models.CharField(max_length=255)
>> parent = models.ForeignKey('self', null=True)
>> has_children = models.BooleanField(default=False)
>> language = models.ForeignKey(Language, null=False, default=1)
>> active = models.BooleanField(default=False)
>> priority = models.IntegerField(null=False, default=5)
>> display_treatment = models.IntegerField(null=False, default=5)
>> last_update = models.DateTimeField(auto_now=True)
>>
>> def __unicode__(self):
>> return self.name
>>
>> class Meta:
>> verbose_name_plural = "Categories"
>> db_table = u'categories'
>>
>> class FlattenedCategory(models.Model):
>> category = models.ForeignKey(Category)
>> member_of_category = models.ForeignKey(Category,
>> related_name='memberof')
>> language = models.ForeignKey(Language)
>> hidden = models.IntegerField()
>> class Meta:
>> db_table = u'flattened_category'
>>
>> I have a Queryset...
>>
>> e = FlattenedCategory.objects.select_related('category').filter
>> (member_of_category=15)
>>
>> which works... This, however, doesn't
>>
>> e = e.category
>>
>> How do I access the related records from the Category model?
>>
>> Thanks.
>>
>> ps... Please refrain from commenting if the best you have is 'read the
>> docs'...docs'...
> > 

--~--~-~--~~~---~--~~
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: aggregate formatting

2009-05-06 Thread George Song

On 5/6/2009 10:27 AM, mamco wrote:
> I have two models "Deposit" and "Cheque".  I'm trying to show total
> the amount of cheques in the admin area using the method name in the
> list_display.  It seems to work (although I think the documentation
> suggests it may not because it requires the lookup for each row
> shown).
> 
> I've got this in the admin.py
> class DepositAdmin(admin.ModelAdmin)
>   list_display = ('date', 'cash', 'ChequeTotal')
> 
> and in the Deposit model:
> 
> def chequeTotal(self):
>  return '%s' % Cheque.objects.aggregate(cheque_sum=Sum('amount'))
> 
> The problem I'm having is that it is displayed as:
> {'cheque_sum': Decimal('123.12')}
> in the list.  How do I get that to display just the 123.12?
> 
> I know this is likely a simply python question, but not sure what that
> returned format is called in order to search accordingly for an
> answer.

The object being returned back by aggregate is a Python dictionary. In 
this case, you just want the value of the 'checkque_sum' element, so:

{{{
return '%s' 
%Cheque.objects.aggregate(cheque_sum=Sum('amount'))['cheque_sum']
}}}

-- 
George

--~--~-~--~~~---~--~~
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: Run context processor conditionally?

2009-05-06 Thread George Song

On 5/6/2009 1:37 PM, ringemup wrote:
> I've got some context that every view in one of my apps needs to pass
> to its templates... but that I don't want to have to run for pages
> that don't use that app, since it executes a lot of queries.  Is there
> a way to execute the context processor only for views defined in that
> app's URL conf or something?

You can specify extra context processors to use with RequestContext in 
your view:



-- 
George

--~--~-~--~~~---~--~~
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: Custom function to serve a static file with Django...

2009-05-06 Thread George Song

On 5/6/2009 1:50 PM, mediumgrade wrote:
> I know of the "standard" way of serving static files in Django for
> development purposes, but I want to create my own function which reads
> the contents of a file then serves it to the user (I want to put some
> security around the downloading of the file).
> 
> What is the best way to accomplish this?

Just return the content of the file in a standard HttpResponse object, 
and make sure you set the right mimetype and any other header you want, 
and that should be it.

-- 
George

--~--~-~--~~~---~--~~
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: Run context processor conditionally?

2009-05-06 Thread George Song

There's no reason a view needs to be a function. You can easily make 
views out of classes. In which case you can stuff some of these things 
in the class __init__ and not have to about them for each view.

On 5/6/2009 3:37 PM, ringemup wrote:
> Hm, and RequestContext has to be instantiated from every view for
> which one wants to use the context processor anyway, huh?
> 
> I always feel like I'm repeating myself when passing global context to
> every single template.
> 
> On May 6, 5:13 pm, George Song  wrote:
>> On 5/6/2009 1:37 PM, ringemup wrote:
>>
>>> I've got some context that every view in one of my apps needs to pass
>>> to its templates... but that I don't want to have to run for pages
>>> that don't use that app, since it executes a lot of queries.  Is there
>>> a way to execute the context processor only for views defined in that
>>> app's URL conf or something?
>> You can specify extra context processors to use with RequestContext in
>> your view:
>>
>> <http://docs.djangoproject.com/en/dev/ref/templates/api/#id1>

-- 
George

--~--~-~--~~~---~--~~
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: running filters on db objects in template?

2009-05-06 Thread George Song

On 5/6/2009 5:32 PM, snorkel wrote:
> I am passing a model to a template that also has foreign keys to other
> models, so in my template I can do things like
> {% for a in a_list %}
>{% for b in a.b_model.all %}
>  this is b.name b.value  b.date 
>{% endfor %}
> {% endfor %}
> 
> Is there some way to filter the b_model in the template or do I have
> to do this in views?
> For example only return b_model with date before Jan 2009 or with
> names beginning with c?

Depends on what you want to do. With the set of conditional template 
tags and filters, you can definitely perform some comparisons in the 
template itself for each b record based on some b.value.

For flexibility and power, you probably want to do it in the view, 
though. You don't have access to any QuerySet API that requires params 
inside the template.

-- 
George

--~--~-~--~~~---~--~~
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: Problem with overriding save() method

2009-05-06 Thread George Song

On 5/6/2009 9:57 PM, Lee Hinde wrote:
> I have this as part of the model for a class called "Class"
> 
> 
> def save(self, force_insert=False, force_update=False):
> start = defaultfilters.slugify(self.Name)
> count = Class.objects.filter(Slug__equal=start).count()
> if count != 0:
> filterme = "%s_%d" % (self.Name, count)
> self.Slug = defaultfilters.slugify(filterme)
> else:
> self.Slug = start
> 
> 
> The reason is, it's ok to have duplicate Names,  and I want to use a
> Slug as the canonical url.
> 
> I have a bunch of data to import and so , in shell I run
> 
>  c = Class.objects.all()
> for o in c:
> o.save()
> 
> 
> My goal would be to see something like:
> 
> yoga-for-kids
> yoga-for-kids_1
> yoga-for-kids_2
> 
> What's weird is I'm getting:
> 
> yoga-for-kids
> yoga-for-kids
> yoga-for-kids_2
> 
> i.e., I get dupes and then not.
> 
> I've played with it most of the evening and now I'm hoping someone
> with a fresh pair of eyes might have a suggestion.
> 
> Thanks in advance.

I'm not sure why you're getting yoga-for-kids_2, what I expect is 
yoga-for-kids, yoga-for-kids_1, then more yoga-for-kids_1 if your slug 
field is not unique=True.

In any case, your logic will keep generating yoga-for-kids_1 because 
there will only ever be one count for yoga-for-kids in your DB.

-- 
George

--~--~-~--~~~---~--~~
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: Problem with overriding save() method

2009-05-06 Thread George Song

On 5/6/2009 11:18 PM, Lee Hinde wrote:
> On Wed, May 6, 2009 at 11:15 PM, Lee Hinde  wrote:
>> On Wed, May 6, 2009 at 10:54 PM, George Song  wrote:
>>> On 5/6/2009 10:34 PM, Lee Hinde wrote:
>>>> On Wed, May 6, 2009 at 10:22 PM, George Song  wrote:
>>>>> On 5/6/2009 9:57 PM, Lee Hinde wrote:
>>>>>> I have this as part of the model for a class called "Class"
>>>>>>
>>>>>>
>>>>>> def save(self, force_insert=False, force_update=False):
>>>>>> start = defaultfilters.slugify(self.Name)
>>>>>> count = Class.objects.filter(Slug__equal=start).count()
>>>>>> if count != 0:
>>>>>> filterme = "%s_%d" % (self.Name, count)
>>>>>> self.Slug = defaultfilters.slugify(filterme)
>>>>>> else:
>>>>>> self.Slug = start
>>>>>>
>>>>>>
>>>>>> The reason is, it's ok to have duplicate Names,  and I want to use a
>>>>>> Slug as the canonical url.
>>>>>>
>>>>>> I have a bunch of data to import and so , in shell I run
>>>>>>
>>>>>>  c = Class.objects.all()
>>>>>> for o in c:
>>>>>> o.save()
>>>>>>
>>>>>>
>>>>>> My goal would be to see something like:
>>>>>>
>>>>>> yoga-for-kids
>>>>>> yoga-for-kids_1
>>>>>> yoga-for-kids_2
>>>>>>
>>>>>> What's weird is I'm getting:
>>>>>>
>>>>>> yoga-for-kids
>>>>>> yoga-for-kids
>>>>>> yoga-for-kids_2
>>>>>>
>>>>>> i.e., I get dupes and then not.
>>>>>> hasn't
>>>>>> I've played with it most of the evening and now I'm hoping someone
>>>>>> with a fresh pair of eyes might have a suggestion.
>>>>>>
>>>>>> Thanks in advance.
>>>>> I'm not sure why you're getting yoga-for-kids_2, what I expect is
>>>>> yoga-for-kids, yoga-for-kids_1, then more yoga-for-kids_1 if your slug
>>>>> field is not unique=True.
>>>>>
>>>>> In any case, your logic will keep generating yoga-for-kids_1 because
>>>>> there will only ever be one count for yoga-for-kids in your DB.
>>>>>
>>>> Well, depends on when it's run, right? yoga-for-kids_1 would be the
>>>> correct response for the 2nd record.
>>>>
>>>>  In this case I'm updating imported data, so there's a pre-existing
>>>> match. If it's a new record, it should come back zero, sine the record
>>>> hasn't been saved yet?
>>>>
>>>> Thanks for looking at it.
>>> Well, I imagine your Class.Name for your test case is "Yoga For Kids",
>>> right?
>>>
>>> So your `start` is always going to be "yoga-for-kids" no matter what.
>>>
>>> Since you're search on that slug, you should only ever have one record
>>> since your slugs are supposed to be unique. So your re-generated slug
>>> will always be "yoga-for-kids_1".
>>>
>>> --
>>> George
>>>
>>
>> Yes, I see what you're saying and it means I've left out a step.
>> Before I run the model.save() loop, I clear the existing slug data, so
>> it starts clean each run.
>>
> 
> But still should always leave me with 1... So, how did I end up with 2
> blanks and one 2?
> 
> Assuming I start off with blanks.
> 
> First time - no match, save as is
> Second time - one match save as X_1
> third time, still one match (this is what you described), should save
> again as x_1 (I'd tried 'startedwith' but that had other problems.)

I can't be sure what your exact conditions are, but in my test, the 
result is exactly as I described:

{{{
from django.db import models
from django.template.defaultfilters import slugify

class Class(models.Model):
 name = models.CharField(max_length=50)
 slug = models.SlugField()

 def save(self, force_insert=False, force_update=False):
 self.slug = slugify(self.name)
 count = self.__class__.objects.filter(slug=self.slug).count()
 if count:
 self.slug = '%s_%d' %(self.slug, count)
 super(Class, self).save(force_insert, force_update)

 >>> from yoga.models import Class
 >>> c1 = Class.objects.create(name='Yoga For Kids')
 >>> c2 = Class.objects.create(name='Yoga For Kids')
 >>> c3 = Class.objects.create(name='Yoga For Kids')
 >>> c1.slug
u'yoga-for-kids'
 >>> c2.slug
u'yoga-for-kids_1'
 >>> c3.slug
u'yoga-for-kids_1'
}}}

-- 
George

--~--~-~--~~~---~--~~
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: Problem with overriding save() method

2009-05-06 Thread George Song

On 5/6/2009 10:34 PM, Lee Hinde wrote:
> On Wed, May 6, 2009 at 10:22 PM, George Song  wrote:
>> On 5/6/2009 9:57 PM, Lee Hinde wrote:
>>> I have this as part of the model for a class called "Class"
>>>
>>>
>>> def save(self, force_insert=False, force_update=False):
>>> start = defaultfilters.slugify(self.Name)
>>> count = Class.objects.filter(Slug__equal=start).count()
>>> if count != 0:
>>> filterme = "%s_%d" % (self.Name, count)
>>> self.Slug = defaultfilters.slugify(filterme)
>>> else:
>>> self.Slug = start
>>>
>>>
>>> The reason is, it's ok to have duplicate Names,  and I want to use a
>>> Slug as the canonical url.
>>>
>>> I have a bunch of data to import and so , in shell I run
>>>
>>>  c = Class.objects.all()
>>> for o in c:
>>> o.save()
>>>
>>>
>>> My goal would be to see something like:
>>>
>>> yoga-for-kids
>>> yoga-for-kids_1
>>> yoga-for-kids_2
>>>
>>> What's weird is I'm getting:
>>>
>>> yoga-for-kids
>>> yoga-for-kids
>>> yoga-for-kids_2
>>>
>>> i.e., I get dupes and then not.
>>> hasn't
>>> I've played with it most of the evening and now I'm hoping someone
>>> with a fresh pair of eyes might have a suggestion.
>>>
>>> Thanks in advance.
>> I'm not sure why you're getting yoga-for-kids_2, what I expect is
>> yoga-for-kids, yoga-for-kids_1, then more yoga-for-kids_1 if your slug
>> field is not unique=True.
>>
>> In any case, your logic will keep generating yoga-for-kids_1 because
>> there will only ever be one count for yoga-for-kids in your DB.
>>
> 
> Well, depends on when it's run, right? yoga-for-kids_1 would be the
> correct response for the 2nd record.
> 
>  In this case I'm updating imported data, so there's a pre-existing
> match. If it's a new record, it should come back zero, sine the record
> hasn't been saved yet?
> 
> Thanks for looking at it.

Well, I imagine your Class.Name for your test case is "Yoga For Kids", 
right?

So your `start` is always going to be "yoga-for-kids" no matter what.

Since you're search on that slug, you should only ever have one record 
since your slugs are supposed to be unique. So your re-generated slug 
will always be "yoga-for-kids_1".

-- 
George

--~--~-~--~~~---~--~~
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: Ajax and non-ajax forms.

2009-05-07 Thread George Song

On 5/7/2009 1:43 AM, Chris Dew wrote:
> Do other developers consider it vital to support non-javascript
> browsers for accessibility reasons?  Or are people largely using ajax
> regardless of accessibility, to make their apps look shiny?

It depends on who the app is for. If it's in a corporate environment 
where you know the constraints you're working with, then by all means 
AJAX away w/o fallback.

Or in another extreme, maybe you can't use AJAX at all in that environment.

But if it's public facing, you're probably better off constructing the 
entire app w/o AJAX first and then selectively put in widgets where 
usability can be improved. This way you're not locking out some segment 
of your users.

Note this doesn't just apply to AJAX, but to JS in general. And more 
importantly, you should have valid semantic markup that can still be 
read w/o relying on styling if possible, if you want things like screen 
readers to work.

-- 
George

--~--~-~--~~~---~--~~
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: ManyToMany relationships in an object creation view

2009-05-07 Thread George Song

On 5/3/2009 12:59 AM, notcourage wrote:
> I'm interested in hearing how you cope w/ the problem of specifying
> ManyToMany relationships in an object creation view. Consider two
> models M1 & M2 and a creation view/form for M1. A technique I'm using
> is to specify M2 values as an unbound field in a ModelForm for M1.
> When the form validates:
> m1Form.save()
> I convert m1Form['m2'] into ManyToMany relationship chgs. This works
> but it defeats the purpose of ModelForm.
> 
> I'm making use of a scrolling  of checkboxes instead of a shuttle
> widget (takes up too much space) or a multi-select widget (easy to
> mess up the selection). I'm considering creating a custom widget for
> the MultipleChoiceField. Is this practical or a good idea?

I don't think you need to create a custom widget. There's already a 
`CheckboxSelectMultiple` widget that you can use.

{{{
from django.db import models
from django import forms

class Pizza(models.Model):
 name = models.CharField(max_length=50)
 toppings = models.ManyToManyField('Topping')

 def __unicode__(self):
 return self.name

class Topping(models.Model):
 name = models.CharField(max_length=50)

 def __unicode__(self):
 return self.name

class PizzaForm(forms.ModelForm):
 TOPPINGS_CHOICES = [(t.pk, t) for t in Topping.objects.all()]
 toppings = forms.MultipleChoiceField(
 choices=TOPPINGS_CHOICES, widget=forms.CheckboxSelectMultiple)

 class Meta:
 model = Pizza

 >>> from m2m.models import PizzaForm
 >>> f = PizzaForm()
 >>> print f['toppings']

 Pesto
 Garlic

}}}

-- 
George

--~--~-~--~~~---~--~~
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: Need help optimizing a view, too many queries

2009-05-07 Thread George Song

On 5/7/2009 8:56 AM, Eric Chamberlain wrote:
> Our view is taking too long to render, can anyone offer suggestions to 
> improve its speed?
> 
> There are 5830 profiles.
> 
> /Total query count:/ 23809
> /Total duplicate query count:/ 493
> /Total SQL execution time:/ 66.003
> /Total Request execution time:/ 142.931
> 
> class Profile(Model):
> id = UUIDField(primary_key=True)
> user = ForeignKey(User, verbose_name=_('user'), unique=True, null=True)
> partner = ForeignKey('Partner')
> call_records = ManyToManyField('CallRecord', verbose_name=_('call 
> record'), null=True, blank=True, help_text='Calls made by the user')
> 
> class Partner(Model):
> id = UUIDField(primary_key=True)
> name = CharField(max_length=255, help_text='The name for the partner')
> users = ManyToManyField(User, related_name='partner_users', 
> null=True, blank=True, help_text='Users signed up specifically through 
> this partner')
> providers = ManyToManyField('Provider', 
> related_name='provider_partners', blank=True, null=True, 
> help_text="Calling services owned by this provider.")
> calls = ManyToManyField('CallRecord', related_name='call_partners', 
> blank=True, null=True, help_text='Calls made through this calling service.')
> 
> class CallRecord(Model):
> id = UUIDField(primary_key=True)
> provider_account = ForeignKey('ProviderAccount', null=True, 
> blank=True, help_text='The calling service, if any, the call was made 
> through')
> provider = ForeignKey('Provider', blank=True, null=True, 
> help_text='The calling service the call was made through')
> 
> class Provider(Model):
> id = UUIDField(primary_key=True)
> name = CharField(max_length=255)
> 
> class ProviderAccount(Model):
> provider = ForeignKey('Provider', help_text='The calling service 
> this account works with')
> username = TextField()
> encrypted_password = TextField(db_column='password')
> user = ForeignKey(User, help_text='The user this calling service 
> account belongs to')
> 
> 
> profiles = 
> Profile.objects.filter(partner=request.partner,user__is_active=True).order_by('-user__date_joined')
> for p in profiles:
>   p.provider_list = list(
>   account.provider for account in 
> ProviderAccount.objects.filter(user=p.user,provider__provider_partners=request.partner))
>   p.call_count = p.call_records.filter().count()
> return PartnerResponse(request, {'profiles': profiles})
> 
> PartnerResponse returns the view to the user, the template uses a for 
> loop to iterate through the profiles.

Well, it seems like what you're really after is the ProviderAccount, right?

So you can just pass this to your template:
{{{
accounts = 
ProviderAccount.objects.filter(provider__provider_partners=request.partner).order_by('-user__date_joined')
}}}

In your template you can regroup accounts by user and you should be good 
to go, right?

-- 
George

--~--~-~--~~~---~--~~
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: Aggregated Expression.

2009-05-07 Thread George Song

On 5/7/2009 10:42 AM, overgroove wrote:
> I have the following models:
> 
> Customer
> Order
> Lineitem
> 
> Customers have orders and orders have lineitems.  In lineitems there's
> a product price and a product quantity.  I would like to be able to,
> using django querysets and whatever magic I have to do, to annotate
> the multiplication of price and quantity in lineitem to the customer.
> I know I can do this with raw sql, however, I'd like to do it with
> querysets so that I can afterwards apply a filter.  I've tried a hack
> where I perform some trivial annotation to the customer based on a
> lineitem (which gives me the appropriate joins) and then add SUM(price
> * quantity) with extra() to the select.  However, this column also
> gets added to the group by clause, rendering the query useless.

There might be a fancy way to do this in QuerySet, but I don't know how.

I personally would just write a custom method on Customer or Order to do 
this for you, depending on what level of aggregation you need.

-- 
George

--~--~-~--~~~---~--~~
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: Need help optimizing a view, too many queries

2009-05-07 Thread George Song

On 5/7/2009 11:16 AM, Eric Chamberlain wrote:
> 
> On May 7, 2009, at 10:36 AM, George Song wrote:
> 
>> On 5/7/2009 8:56 AM, Eric Chamberlain wrote:
>>> Our view is taking too long to render, can anyone offer suggestions  
>>> to
>>> improve its speed?
>>>
>>> There are 5830 profiles.
>>>
>>> /Total query count:/ 23809
>>> /Total duplicate query count:/ 493
>>> /Total SQL execution time:/ 66.003
>>> /Total Request execution time:/ 142.931
>>>
>>> class Profile(Model):
>>>id = UUIDField(primary_key=True)
>>>user = ForeignKey(User, verbose_name=_('user'), unique=True,  
>>> null=True)
>>>partner = ForeignKey('Partner')
>>>call_records = ManyToManyField('CallRecord', verbose_name=_('call
>>> record'), null=True, blank=True, help_text='Calls made by the user')
>>>
>>> class Partner(Model):
>>>id = UUIDField(primary_key=True)
>>>name = CharField(max_length=255, help_text='The name for the  
>>> partner')
>>>users = ManyToManyField(User, related_name='partner_users',
>>> null=True, blank=True, help_text='Users signed up specifically  
>>> through
>>> this partner')
>>>providers = ManyToManyField('Provider',
>>> related_name='provider_partners', blank=True, null=True,
>>> help_text="Calling services owned by this provider.")
>>>calls = ManyToManyField('CallRecord',  
>>> related_name='call_partners',
>>> blank=True, null=True, help_text='Calls made through this calling  
>>> service.')
>>>
>>> class CallRecord(Model):
>>>id = UUIDField(primary_key=True)
>>>provider_account = ForeignKey('ProviderAccount', null=True,
>>> blank=True, help_text='The calling service, if any, the call was made
>>> through')
>>>provider = ForeignKey('Provider', blank=True, null=True,
>>> help_text='The calling service the call was made through')
>>>
>>> class Provider(Model):
>>>id = UUIDField(primary_key=True)
>>>name = CharField(max_length=255)
>>>
>>> class ProviderAccount(Model):
>>>provider = ForeignKey('Provider', help_text='The calling service
>>> this account works with')
>>>username = TextField()
>>>encrypted_password = TextField(db_column='password')
>>>user = ForeignKey(User, help_text='The user this calling service
>>> account belongs to')
>>>
>>>
>>> profiles =
>>> Profile 
>>> .objects 
>>> .filter(partner=request.partner,user__is_active=True).order_by('- 
>>> user__date_joined')
>>> for p in profiles:
>>>  p.provider_list = list(
>>>  account.provider for account in
>>> ProviderAccount 
>>> .objects 
>>> .filter(user=p.user,provider__provider_partners=request.partner))
>>>  p.call_count = p.call_records.filter().count()
>>> return PartnerResponse(request, {'profiles': profiles})
>>>
>>> PartnerResponse returns the view to the user, the template uses a for
>>> loop to iterate through the profiles.
>> Well, it seems like what you're really after is the ProviderAccount,  
>> right?
>>
>> So you can just pass this to your template:
>> {{{
>> accounts =
>> ProviderAccount 
>> .objects 
>> .filter(provider__provider_partners=request.partner).order_by('- 
>> user__date_joined')
>> }}}
>>
>> In your template you can regroup accounts by user and you should be  
>> good
>> to go, right?
>>
> 
> We are after user information and a user can have 0 or more  
> ProviderAccounts.
> 
> The template looks like:
> 
> {% for profile in profiles %}
>  
>  {{profile.user.email}}
>  {{profile.user.first_name}} {{profile.user.last_name}}
>  {{profile.user.date_joined|date:"Y M d H:i"  }}
>  
>  {% for calling_service in profile.provider_list %}
>  {{calling_service.name}} a>{% if not forloop.last %}{% endif %}
>  {% endfor %}
>  
>  
>  {% for sim in profile.sims.all %}
>  {{sim.caller_id}}{% if not forloop.last %}{% endif %}
>  {% endfor %}
>  
>  {{profile.call_count}}
>  
>  
> {% endfor %}

I'll have to look at this some more when I have time. But you can 
eliminate call_count right off the bat, right? Since that can be 
accessed directly via `profile.call_records.count` directly on the template.

-- 
George

--~--~-~--~~~---~--~~
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: Trouble Starting Up with runserver

2009-05-07 Thread George Song

On 5/7/2009 11:23 AM, Phil Mocek wrote:
> On Thu, May 07, 2009 at 12:49:28PM -0500, Tim Chase wrote:
>>> was searching for "interface" or "IP address" but the tutorial
>>> says -- incorrectly or colloqially, depending on how you see
>>> things -- "So to listen on all public IPs (useful if you want
>>> to show off your work on other computers), use:".  There's no
>>> such thing as a "public IP".
>> I suspect the intent is "external IP" compared to an internal IP 
>> (localhost/127.0.0.1).
> 
> I agree.
> 
> What makes the tutorial technically incorrect, and what prevents
> someone who seeks information about using the 0.0.0.0 IP address
> from finding that passage using reasonable search terms, is its
> omission of the word "address".  The subject at hand is an
> address, not a protocol, yet what was written is "public IP" not
> "public IP address".  This is fine for casual conversation, but --
> for reasons including that which was discovered in this discussion
> -- not for a technical tutorial whose target audience is software
> developers.

This is good clarification. It would be great if one of you can open a 
ticket and supply a patch.

-- 
George

--~--~-~--~~~---~--~~
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: Wrapping object_detail generic view in another view

2009-05-07 Thread George Song

On 5/7/2009 1:01 PM, Jamie Pittock wrote:
> Basically, am I doing things right, and if so which is the best
> solution from the above?

Yup, you are doing things correctly as far as I can tell.

As for creating a custom method or not, it's up to you, it's just a 
convenience wrapper, after all. I don't see much value in this specific 
instance, unless you think the meaning of "get_by_author" may change at 
some point.

p.s. Use spaces instead of tabs in your code. It was extremely hard to read.

-- 
George

--~--~-~--~~~---~--~~
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: Problem with overriding save() method

2009-05-07 Thread George Song

On 5/7/2009 8:05 AM, Lee Hinde wrote:
> On Wed, May 6, 2009 at 11:37 PM, George Song  wrote:
>> On 5/6/2009 11:18 PM, Lee Hinde wrote:
>>> On Wed, May 6, 2009 at 11:15 PM, Lee Hinde  wrote:
>>>> On Wed, May 6, 2009 at 10:54 PM, George Song  wrote:
>>>>> On 5/6/2009 10:34 PM, Lee Hinde wrote:
>>>>>> On Wed, May 6, 2009 at 10:22 PM, George Song  wrote:
>>>>>>> On 5/6/2009 9:57 PM, Lee Hinde wrote:
>>>>>>>> I have this as part of the model for a class called "Class"
>>>>>>>>
>>>>>>>>
>>>>>>>> def save(self, force_insert=False, force_update=False):
>>>>>>>> start = defaultfilters.slugify(self.Name)
>>>>>>>> count = Class.objects.filter(Slug__equal=start).count()
>>>>>>>> if count != 0:
>>>>>>>> filterme = "%s_%d" % (self.Name, count)
>>>>>>>> self.Slug = defaultfilters.slugify(filterme)
>>>>>>>> else:
>>>>>>>> self.Slug = start
>>>>>>>>
>>>>>>>>
>>>>>>>> The reason is, it's ok to have duplicate Names,  and I want to use a
>>>>>>>> Slug as the canonical url.
>>>>>>>>
>>>>>>>> I have a bunch of data to import and so , in shell I run
>>>>>>>>
>>>>>>>>  c = Class.objects.all()
>>>>>>>> for o in c:
>>>>>>>> o.save()
>>>>>>>>
>>>>>>>>
>>>>>>>> My goal would be to see something like:
>>>>>>>>
>>>>>>>> yoga-for-kids
>>>>>>>> yoga-for-kids_1
>>>>>>>> yoga-for-kids_2
>>>>>>>>
>>>>>>>> What's weird is I'm getting:
>>>>>>>>
>>>>>>>> yoga-for-kids
>>>>>>>> yoga-for-kids
>>>>>>>> yoga-for-kids_2
>>>>>>>>
>>>>>>>> i.e., I get dupes and then not.
>>>>>>>> hasn't
>>>>>>>> I've played with it most of the evening and now I'm hoping someone
>>>>>>>> with a fresh pair of eyes might have a suggestion.
>>>>>>>>
>>>>>>>> Thanks in advance.
>>>>>>> I'm not sure why you're getting yoga-for-kids_2, what I expect is
>>>>>>> yoga-for-kids, yoga-for-kids_1, then more yoga-for-kids_1 if your slug
>>>>>>> field is not unique=True.
>>>>>>>
>>>>>>> In any case, your logic will keep generating yoga-for-kids_1 because
>>>>>>> there will only ever be one count for yoga-for-kids in your DB.
>>>>>>>
>>>>>> Well, depends on when it's run, right? yoga-for-kids_1 would be the
>>>>>> correct response for the 2nd record.
>>>>>>
>>>>>>  In this case I'm updating imported data, so there's a pre-existing
>>>>>> match. If it's a new record, it should come back zero, sine the record
>>>>>> hasn't been saved yet?
>>>>>>
>>>>>> Thanks for looking at it.
>>>>> Well, I imagine your Class.Name for your test case is "Yoga For Kids",
>>>>> right?
>>>>>
>>>>> So your `start` is always going to be "yoga-for-kids" no matter what.
>>>>>
>>>>> Since you're search on that slug, you should only ever have one record
>>>>> since your slugs are supposed to be unique. So your re-generated slug
>>>>> will always be "yoga-for-kids_1".
>>>>>
>>>>> --
>>>>> George
>>>>>
>>>> Yes, I see what you're saying and it means I've left out a step.
>>>> Before I run the model.save() loop, I clear the existing slug data, so
>>>> it starts clean each run.
>>>>
>>> But still should always leave me with 1... So, how did I end up with 2
>>> blanks and one 2?
>>>
>>> Assuming I start off with blanks.
>>>
>>> First time - no match, save as is
>>> Second time - one match s

Re: TIME_ZONE problem

2009-05-07 Thread George Song

On 5/7/2009 5:00 PM, Graham Dumpleton wrote:
> 
> 
> On May 7, 2:41 am, George Song  wrote:
>> On 5/6/2009 4:02 AM, Graham Dumpleton wrote:
>>
>>
>>
>>
>>
>>> On May 6, 4:38 am, George Song  wrote:
>>>> On 5/5/2009 6:48 AM, Michel Thadeu Sabchuk wrote:
>>>>> Hi guys,
>>>>> I'm having a weird problem with TIME_ZONE settings. Some view list
>>>>> objects based on the time, future time objects are not shown.
>>>>> The problem is that sometimes all objects that need to be shown appear
>>>>> normally, sometimes the latest objects are not shown.
>>>>> Digging on the problem I found that sometimes my os.environ['TZ'] are
>>>>> set to 'America/Sao_Paulo' (the correct one) and sometimes it is the
>>>>> default 'America/Chicago'. I can't see any reason to this problem.
>>>>> I using python2.5 with django1.1-beta installed on a vps with ubuntu
>>>>> hardy. My django settings module have the following line:
>>>>> TIME_ZONE = 'America/Sao_Paulo'
>>>>> And my apache virtual host configuration has the following:
>>>>> 
>>>>> SetHandler python-program
>>>>> PythonPath "['/path-to-my-project/'] + sys.path"
>>>>> PythonHandler django.core.handlers.modpython
>>>>> SetEnv DJANGO_SETTINGS_MODULE portal.settings
>>>>> PythonDebug Off
>>>>> 
>>>>> Does someone facing the same problem? Does anyone has a suggestion?
>>>> That is very odd indeed. Are there other Django instances within the
>>>> same virtual host?
>>> It doesn't strictly have to be other Django instances, it can be PHP
>>> or mod_perl as well. Basically anything that runs embedded in Apache
>>> processes and which expects a different timezone setting.
>>> For case where only running Python applications, formod_wsgithis
>>> problem is described in:
>>>  http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_...
>>> Same thing with mod_python, but with mod_python no way around it.
>> With mod_python, can you just use multiple interpreters?
>> <http://www.modpython.org/live/mod_python-3.2.5b/doc-html/pyapi-interp...>
> 
> No you can't. Those multiple interpreters are in the same process
> exactly as described from mod_wsgi case. The problem is because
> application in each interpreter is changing a value which is shared
> across all interpreters. This value being sorted at C library level
> outside of context of specific Python sub interpreter.

Gotcha, that makes sense.

--~--~-~--~~~---~--~~
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: limiting choices for foreign key choices in the admin view

2009-05-07 Thread George Song

On 5/7/2009 6:29 PM, Margie wrote:
> I know this question has been pondered in a bunch of posts, and I'm
> sorry to repeat it, but I just can't figure out what is the right
> direction to take.
> 
> Let's say I have a model for a Task:
> 
> class Task(models.Model):
> owner = models.ForeignKey('auth.User')
> resources = models.ManyToManyField('auth.User')
> 
> The resources field identifies the set of possible owners for the
> task.  I would like to have the admin change_list view show the
> resources as the choices for the owner field, rather than showing all
> Users.
> 
> Has anyone had success doing this?  Can someone point me in the right
> direction?  Am happy to do some coding or override internal methods.
> I see some people talking about using jquery to do this, but if there
> is a way of overriding an internal method, that seems preferable to
> me.

I'll point you in the right direction: `django.contrib.admin.options`.

Look specifically at `formfield_for_dbfield()` and the various flavors 
of related "hooks." I'll bet you can figure out what to do in your admin 
definition.

-- 
George

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

2009-05-07 Thread George Song

On 5/7/2009 4:28 PM, Andy Lei wrote:
> I have 3 models.  Something like this:
> 
> Writer:
>  content = ManyToMany(Content)
> Content
>  tags = ManyToMany(Tag)
> Tag
> 
> Now suppose I have a Tag, call it "tag1".  The idea of the query is
> that I want the Writers that have the most pieces of Content tagged
> with tag1.
> 
> Theoretically, it'd be something like
> Writer.objects.annotate(content_count=Count
> ("content__tags=tag1")).order_by('content_count")
> 
> Obviously, that doesn't work.  Any help would be greatly appreciated.

Hmm. I'm not sure if this is possible through the ORM. If it is, it's 
beyond me.

The closest thing I can think of is:
{{{
Writer.objects.filter(content__in=Content.objects.filter(tags=tag))
}}}

Which will yield a QuerySet with each Writer repeated n times (once for 
each Content associated with that writer, tagged with `tag`).

You should be able to do something in Python to get the Writer:count() 
mapping that you want.

-- 
George

--~--~-~--~~~---~--~~
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: limiting choices for foreign key choices in the admin view

2009-05-07 Thread George Song

On 5/7/2009 9:19 PM, Margie wrote:
> Thanks much George, that was a big help.  I have some "proof of
> concept code below" that simply limits choices to the first four
> users, and I have verified that that works.
> 
> class TaskAdmin(admin.ModelAdmin):
> 
> def formfield_for_dbfield(self, db_field, **kwargs):
> if db_field.name == "owner":
> kwargs["queryset"] = User.objects.all()[0:3]
> formField = super(TaskAdmin, self).formfield_for_dbfield
> (db_field, **kwargs)
> return formField
> 
> I think that at the time formfield_for_dbfield is called we are
> creating the class for the form, ie, in this case, the class
> TaskForm.  It seems to me that I don't have any info at this time
> about what the actual values of the manyToMany field 'resources' is.
> In fact, it may be different for each line in the admin display.   IE,
> for each  line in the admin display, resources may point to different
> users and it is the value of resources hat I would really like to have
> for my choices for the owner field.  I have a feeling this isn't going
> to be possible ...
> 
> It seems like I would need to be setting the queryset for owner at a
> much later point in the code to really be able to set it to the
> 'resources' field for that same task.

If you can't predict ahead of time what the choice set is, then you will 
have to use some AJAX magic to accomplish what you want. The nice thing 
is you can attach JS to the fields you want.

-- 
George

--~--~-~--~~~---~--~~
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: QuerySet.values() for single object?

2009-05-07 Thread George Song

On 5/7/2009 9:23 PM, Shadow wrote:
> If i get a model object with Model.objects.get()
> 
> Is their a way to turn that into a dictionary?

Why not just filter for it and use values()?

-- 
George

--~--~-~--~~~---~--~~
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: Moving from perl/cgi to Django/Python

2009-05-08 Thread George Song

On 5/8/2009 6:55 AM, consiglieri wrote:
> I have a running perl/cgi app in conjunction with mysql which works
> fine.
> 
> For various reasons i want to move to either django or RoR. I've
> pretty much decided to go with Django, however i'm wondering about one
> thing.
> 
> Ideally i would like to use the mysql database that i have, does
> Django provide som good method for either converting a database for
> use by Django? How have other people done when moving to Django.
> 
> As the question shows i'm not exactly a pro at this, but i would
> appreciate any and all constructive comments.

It depends on the complexity of your original application. If there 
aren't many tables/models, my advice would be to just rewrite everything 
from scratch, including the models, and do a data migration.

There are couple things you'll want to look into:

* inspectdb [1]
* unmanaged models [2]

Good luck, and welcome.

[1] 
[2] 

-- 
George

--~--~-~--~~~---~--~~
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: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

2009-05-08 Thread George Song

On 5/8/2009 4:32 PM, Lee Hinde wrote:
> Hi;
> 
> I get the error below at a point I'm trying to add 1 to an int field.
> I'm understanding the error that django doesn't know what the type is
> for sn.
> 
> 
> Model:
> 
> class Sequence_Number(models.Model):
> Sequence_Name = models.CharField(max_length=100)
> Next_Sequence_Number = models.IntegerField()
> LastUpdate = models.DateField(auto_now = True)
> dupefixed = models.DateField(blank=True,null=True)
> 
> def __unicode__(self):
> return self.Sequence_Name
> 
> Sequence Number function:
> 
> @transaction.autocommit
> def get_SequenceNumber(itemToSequnce):
> try:
> sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce)
> except Sequence_Number.DoesNotExist:
> sn = Sequence_Number(Sequence_Name=itemToSequnce)
> next_number = sn.Next_Sequence_Number
> sn.Next_Sequence_Number += 1
> sn.save()
> return next_number
> 
> def buildSlug(slug):
> slug = "slug__%s" % (slug)
> next_Num = get_SequenceNumber(slug)
> slug_with_number = "%s%d" % (slug,next_Num)
> return slug_with_number
> 
> 
> 
> Traceback:
> 
>   File "", line 2, in 
>   File 
> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
> line 314, in save
> self.Slug = buildSlug(start)
>   File 
> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
> line 20, in buildSlug
> next_Num = get_SequenceNumber(slug)
>   File "/Library/Python/2.5/site-packages/django/db/transaction.py",
> line 223, in _autocommit
> return func(*args, **kw)
>   File 
> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
> line 14, in get_SequenceNumber
> sn.Next_Sequence_Number += 1
> TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

{{{
try:
 sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce)
except Sequence_Number.DoesNotExist:
 sn = Sequence_Number(Sequence_Name=itemToSequnce)
next_number = sn.Next_Sequence_Number
}}}

Well, in your except block, you're just instantiating a Sequence_Number 
object, so of course it doesn't have the Next_Sequence_Number attribute yet.

Did you mean to do:
{{{
Sequence_Number.objects.create(Sequence_Name=itemToSequnce)
}}}
?

-- 
George

--~--~-~--~~~---~--~~
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: using id as a model field name ?

2009-05-08 Thread George Song

On 5/8/2009 4:31 PM, paul wisehart wrote:
> I didn't realize that id was a python builtin function.
> 
> I have a large pre-existing database that I wrote a bunch of models
> for.
> 
> I used 'id' as the primary key field for all of them.
> 
> """
> class SalesQuoteItemDetail(models.Model):
> id = models.AutoField(primary_key=True, db_column='ID')
> ...
> """
> 
> Could that hurt anything to name a field the same as a built-in
> function?
> 
> I'm trying to decide if I should change all of my code to something
> like:
> pk = models.AutoField(...

I think it's unlike you'll collide with the built-in `id()`, unless you 
explicitly do something like id=blahblahblah, but that can happen with 
anything, not just your models.

In other words, don't worry about it.

-- 
George

--~--~-~--~~~---~--~~
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: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

2009-05-08 Thread George Song

On 5/8/2009 5:58 PM, Lee Hinde wrote:
> On Fri, May 8, 2009 at 5:12 PM, Lee Hinde  wrote:
>> On Fri, May 8, 2009 at 4:48 PM, George Song  wrote:
>>> On 5/8/2009 4:32 PM, Lee Hinde wrote:
>>>> Hi;
>>>>
>>>> I get the error below at a point I'm trying to add 1 to an int field.
>>>> I'm understanding the error that django doesn't know what the type is
>>>> for sn.
>>>>
>>>>
>>>> Model:
>>>>
>>>> class Sequence_Number(models.Model):
>>>> Sequence_Name = models.CharField(max_length=100)
>>>> Next_Sequence_Number = models.IntegerField()
>>>> LastUpdate = models.DateField(auto_now = True)
>>>> dupefixed = models.DateField(blank=True,null=True)
>>>>
>>>> def __unicode__(self):
>>>> return self.Sequence_Name
>>>>
>>>> Sequence Number function:
>>>>
>>>> @transaction.autocommit
>>>> def get_SequenceNumber(itemToSequnce):
>>>> try:
>>>> sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce)
>>>> except Sequence_Number.DoesNotExist:
>>>> sn = Sequence_Number(Sequence_Name=itemToSequnce)
>>>> next_number = sn.Next_Sequence_Number
>>>> sn.Next_Sequence_Number += 1
>>>> sn.save()
>>>> return next_number
>>>>
>>>> def buildSlug(slug):
>>>> slug = "slug__%s" % (slug)
>>>> next_Num = get_SequenceNumber(slug)
>>>> slug_with_number = "%s%d" % (slug,next_Num)
>>>> return slug_with_number
>>>>
>>>>
>>>>
>>>> Traceback:
>>>>
>>>>   File "", line 2, in 
>>>>   File 
>>>> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
>>>> line 314, in save
>>>> self.Slug = buildSlug(start)
>>>>   File 
>>>> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
>>>> line 20, in buildSlug
>>>> next_Num = get_SequenceNumber(slug)
>>>>   File "/Library/Python/2.5/site-packages/django/db/transaction.py",
>>>> line 223, in _autocommit
>>>> return func(*args, **kw)
>>>>   File 
>>>> "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py",
>>>> line 14, in get_SequenceNumber
>>>> sn.Next_Sequence_Number += 1
>>>> TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
>>> {{{
>>> try:
>>> sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce)
>>> except Sequence_Number.DoesNotExist:
>>> sn = Sequence_Number(Sequence_Name=itemToSequnce)
>>> next_number = sn.Next_Sequence_Number
>>> }}}
>>>
>>> Well, in your except block, you're just instantiating a Sequence_Number
>>> object, so of course it doesn't have the Next_Sequence_Number attribute yet.
>>>
>>> Did you mean to do:
>>> {{{
>>> Sequence_Number.objects.create(Sequence_Name=itemToSequnce)
>>> }}}
>>> ?
>>>
>> I may mean that. :-) I was trying to emulate the documentation around
>> the get_or_create method.
>>
>> The documentation around transaction implied that the transaction
>> would be closed when the object was saved,, I wasn't sure if
>> get_or_create would end the transaction.
>>
>> In any case I get the same error if I seed the  Next_Sequence_Number.
>>sn = 
>> Sequence_Number(Sequence_Name=itemToSequnce,Next_Sequence_Number=0)
>> or
>>
>> Sequence_Number.objects.create(Sequence_Name=itemToSequnce,Next_Sequence_Number=0)
>>
> 
> 
> 
> I moved everything out to the shell and it worked. That made me think
> that there must be a typo or somesuch in what I'd originally done. I
> also may not understand mutability in Python just yet. After futzing
> around some I ended up with this and it works now:
> 
> @transaction.autocommit
> def get_SequenceNumber(itemToSequnce):
> try:
> sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce)
> except Sequence_Number.DoesNotExist:
> sn = 
> Sequence_Number.objects.create(Sequence_Name=itemToSequnce,Next_Sequence_

Re: How to disable deletion af a model instance

2009-05-09 Thread George Song

On 5/9/2009 7:14 AM, Rune Bromer wrote:
> Hi,
> 
> I run a small project handling payments from users. Each user has the
> possibility to delete their account and if they do I have to keep
> their payment data. Also, I would like to disable admins from deleting
> the data as there are NEVER a valid reason to do so. The payment model
> has foreign keys so obviously I need to set these to None before I
> delete the instances ref'ed by the payment. I do this in a pre_delete
> () signal for all the models ref'ed by the payment model.
> 
> Also, I created a delete() method on the payment model that will not
> call the supers delete() when the payment is complete.
> 
> The only thing missing is the admin. As I understand the admin will
> send a pre_delete() signal so hopefully it will not find the payment
> objects when deleting a user because the link will go away in the
> signal. What I'm more worried about is if a stupid admin tries to
> delete the payment objects themselves. I can remove the actions of
> cause, but how about the per-object delete functionality? Removing the
> permission will not work for people having is_superuser = True.
> 
> Hope the problem is understandable. Hopefully I'm overlooking
> something simple?

If you already did an override on `Payment.delete()`, then you should be 
fine.

Although be mindful of bulk delete, as it doesn't use `Model.delete()`:


Also you might want to think about setting up a group in auth to have 
finer grained permission control. It's pretty simple to just leave out 
delete for this specific model. Is there a reason they need to be 
superusers?

-- 
George

--~--~-~--~~~---~--~~
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: Print question

2009-05-09 Thread George Song

Does `pprint.pprint(obj.__dict__)` not do what you want?

On 5/9/2009 8:41 AM, phoebebright wrote:
> Masklinn,
> 
> Thanks. I see what you mean about being bored!  But that's a big step
> forward for me.
> 
> As a PHP convert to Django/Python, I'm looking for the equivalent of
> print_r
> 
> On May 9, 4:31 pm, Masklinn  wrote:
>> On 9 May 2009, at 16:37 , phoebebright wrote:
>>
>>> Not looking for a discussion on debug methods, just want to know if
>>> there is any way to print an object.
>>> eg. print myobject  OR  pprint.pprint(myobject)
>>> just says something like
>>> 
>>> And unless I know the structure of the object I can't access the
>>> values.
>>> I'm probably going to get a blasting for not understanding how python
>>> works, but there we go!
>> You can print its __dict__ attribute if you're really bored. If it's  
>> an object you created, correctly override the corresponding magic  
>> methods (__str__, __repr__, ...)

-- 
George

--~--~-~--~~~---~--~~
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: timeuntil filter

2009-05-09 Thread George Song

On 5/9/2009 11:28 AM, adrian wrote:
> 
> This filter is returning an empty string for a valid date (or datetime
> with 0,0,0 added) in
> Django 1.0.2.
> 
> The documentation for this says:
> 
>> Comparing offset-naive and offset-aware datetimes will return an empty 
>> string.
> 
> but it doesn't say which type it uses.
> 
> Shouldn't this say something like:
> 
>> Using an offset-naive datetime will return an empty string.
> 
> Or is there something else I could be doing wrong?
> 
> Thanks
> 
> The template:
> 
>>  There are {{ earliest_date }}{{ earliest_date|timeuntil }} until the event.
> 
> displays:
> 
> There are 2009-05-17 until the event.

Are you definitely passing in `earliest_date` as a `datetime.date` 
object to the template?

-- 
George

--~--~-~--~~~---~--~~
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: How to disable deletion af a model instance

2009-05-09 Thread George Song

On 5/9/2009 12:34 PM, Margie wrote:
> I've had my share of confusion over delete.  Here's a thread that I
> had with Malcolm recently:
> 
> http://groups.google.com/group/django-users/browse_thread/thread/582f21486c1073eb/7f5743953047d9fa?lnk=raot&fwc=1
> 
> However, I guess I'm still quite confused.  One thing I don't
> understand is when the "bulk delete" happens.  I thought, for example,
> that it happened when one uses the queryset delete.  So I just wrote
> myself a little test.
> 
> Here's the model.  I have a 'Book' and it has readers (that have
> ForeignKey back to Book)
> 
> class Publisher(models.Model):
> name = models.CharField(max_length=100)
> 
> class Book(models.Model):
> title = models.CharField(max_length=100)
> publisher = models.ForeignKey(Publisher, blank=True, null=True)
> 
> class Reader(models.Model):
> book = models.ForeignKey(Book, blank=True, null=True)
> name = models.CharField(max_length=100)
> 
> Here's a small snippet of code that creates a book with two readers.
> I then delete the book using a queryset delete.  I thought that in
> this case neither Book.delete() nor Reader.delete() would get called.
> However, the output indicates that preDeleteCallBack() does get
> called, once for the deletion of book1, and once for each of the two
> reader objects.
> 
>   def preDeleteCallBack(sender, instance=None, **kwargs):
>   print "PreDelete called for instance", instance
> 
>   pre_delete.connect(preDeleteCallBack, sender=Reader)
>   pre_delete.connect(preDeleteCallBack, sender=Book)
> 
>   pub1 = Publisher.objects.create(name="pub1")
>   book1 = Book.objects.create(title="book1", publisher=pub1)
>   reader1 = Reader.objects.create(name="reader1", book=book1)
>   reader2 = Reader.objects.create(name="reader2", book=book1)
> 
>   Book.objects.filter(title="book1").delete()
> 
> The output from this call to delete() is:
> 
> PreDelete called for instance book1
> PreDelete called for instance Reader object
> PreDelete called for instance Reader object
> 
> 
> In my app, I use a lot of formsets.  I thought that bulk delete got
> used for those.  Yet again, when I tested it using a little debug app
> I find that the preDeleteCallBack() function gets called.  For
> example:
> 
> bookPostDict = {
> 'form-INITIAL_FORMS': u'1', 'form-TOTAL_FORMS': u'1', 'form-0-
> title': u'book1', 'form-0-DELETE': u'on', 'form-0-id': u'1', 'form-0-
> publisher': u'1',
> }
> 
> bookFormSet = BookFormSet(data=bookPostDict)
> if bookFormSet.is_valid():
> bookFormSet.save()
> 
> When bookFormSet.save() gets executed, I get this output:
> 
> PreDelete called for instance book1
> PreDelete called for instance Reader object
> PreDelete called for instance Reader object
> 
> So I guess I am totally confused now.   I know I have had a ton of
> problems with my foreignKey objects getting deleted when the thing
> they point to gets deleted.  Based on Malcolm's response in the thread
> above, it certainly seemed like I was in bulk delete territory, but
> using these pruned down examples I find I can't even get a bulk delete
> to happen.
> 
> George, would you be able to clarify when the bulk delete happens?  I
> see in the doc that it says:
> 
> "Keep in mind that this will, whenever possible, be executed purely in
> SQL, and so the delete() methods of individual object instances will
> not necessarily be called during the process."
> 
> Perhaps in my queryset delete I am not hitting the case where bulk
> delete will be called?  I am also interested particularly in formsets
> and what happens when can_delete is True and what happens when the
> delete occurs as a result of doing a formset save() when some objects
> have been targeted for deletion.
> 
> Sorry for the length of this.  I've spent all morning trying to grock
> this and am disappointed that my debugging work has resulted in me
> being even more confused than before!

I haven't looked at the code so I can't comment on specifics. Keep in 
mind, however, that signals are sent independently of whether 
`Model.delete()` is invoked.

I think if you want to know definitively if your `delete()` method is 
being called or not, your debug statement should go in that method. I 
wouldn't be surprised if Django is sending pre and post delete signals 
even during bulk deletion.

-- 
George

--~--~-~--~~~---~--~~
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: User Authentication Woes

2009-05-10 Thread George Song

On 5/10/2009 5:38 AM, Alfonso wrote:
> Hi,
> 
> App I'm currently working on can be accessed by either authorised
> admin users or authenticated customers (one customer might have a
> number of users on their account).  A non-admin user can login and
> view restricted sections of the site to check stuff like invoices,
> orders etc.
> 
> So as an example a customer, called bob can view his company's
> invoices at /customer/invoices/85  (number being the invoice number
> viewed).  In an attempt to break it I changed the url to /customer/
> invoices/84 and Bob can see invoice 84 but that invoices isn't
> registered to him, its for a different customer entirely.
> 
> Obviously I'm missing some authentication magic to stop that
> happening.  Question is I'm not sure how to go about that - is there a
> straightforward way I can implement more robust user authentication so
> a customer only sees the invoices they are destined to view!?
> 
> Code for invoice list and invoice detail:
> 
> http://dpaste.com/hold/42642/

Authentication as it says, only deals with authentication. Any kind of 
_authorization_ activity within your project is up to you to implement. 
In this case, all you have to do is a simple check to see if the right 
user can see the invoice requested, throw a 403 if not, and allow them 
to pass if they are.

-- 
George

--~--~-~--~~~---~--~~
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: Field value from queryset as extra_context

2009-05-10 Thread George Song

On 5/10/2009 8:03 AM, Jamie Pittock wrote:
> Please excuse the subject if it makes no sense.
> 
> Simplified, I have two models Pub and Town.  Pub has a ForeignKey
> field called 'town'.  I'm using the generic object_list view to
> display all pubs in a particular town (based on a town slug in the
> url).  Something like this...
> 
> def pubs_by_town(request, town_slug):
> town = get_object_or_404(Town, slug=town_slug)
> return list_detail.object_list(
> request,
> queryset=Pub.objects.filter(town__slug=town_slug),
> extra_context={ 'town': town },
> template_name='pubs/pubs_by_town.html')
> 
> Pubs in {{ town.name }}
> 
> {% for pub in object_list %}
> * {{ pub.name }}
> {% endfor %}
> 
> This all works fine but getting the town object to use in the h1 seems
> a bit redundant seeing as every pub instance in object_list will have
> the same name of the town anyway.
> 
> Is it possible to use the queryset to pass the town name as
> extra_context so that a variable is available to use in my template?
> Is there a better way?

What you're doing is perfectly fine. You've already instantiated the 
town object anyway.

-- 
George

--~--~-~--~~~---~--~~
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: Accessing value of a Form.Field in templates

2009-05-10 Thread George Song

On 5/10/2009 4:27 PM, Martin wrote:
> Hi,
> 
> I'm trying to check in a template if the form on this page was sent or
> not (in other words if the page was accessed by POST or GET). Is there
> a build-in way to do something like that down on the template. Or do I
> have to add a extra 'flag' for this in my view?
> Another possible solution for me would be to check if one of the
> 'required' fields of the form has a value.
> I stumbled upon http://code.djangoproject.com/ticket/10427
> So, I checked out the trunk, but MyForm.MyField.value still doesn't
> work. Did I misinterpret the status of the ticket? It's sometimes hard
> for me to understand the history.

The ticket doesn't appear to be what you're asking for. I think the 
easiest way is for you to insert an extra context variable in your view, 
since `GET` and `POST` are verbs associated with a request, not a response.

-- 
George

--~--~-~--~~~---~--~~
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: Accessing value of a Form.Field in templates

2009-05-10 Thread George Song

On 5/10/2009 5:32 PM, Martin wrote:
> 
> On 11 Mai, 02:07, George Song  wrote:
>> The ticket doesn't appear to be what you're asking for. I think the
>> easiest way is for you to insert an extra context variable in your view,
>> since `GET` and `POST` are verbs associated with a request, not a response.
>>
>> --
>> George
> 
> Thank you for the fast reply. Hm, my intention was to include a large
> JavaScript-file only if my form is not empty.
> I don't really understand why '.value' doesn't work for me.

Well, the ticket is still open so that means the issue is not resolved 
yet. If you want you can apply the patch, in which case you should be 
able to use the `.value` property.

-- 
George

--~--~-~--~~~---~--~~
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: After a form submit, getting user info into an attribute while still using generic views?

2009-05-11 Thread George Song

On 5/11/2009 4:04 AM, Lior wrote:
> Hello,
> I'm using generic views to manage a model. In that model, when I
> create an instance (and not when I update it), I need to set one of
> its attribute (owner) to the currently logged in user value. I'd like
> to continue using generic views, so can I do this without creating a
> view? Is that possible?
> The only solution, so far would be to create a new view (and in that
> view do all what the generic view do, that is testing form fields,
> etc.), and set my attribute from the request.user variable. But I
> don't see how to keep the generic view usage in url.py.
> 
> Any other way ?

You can easily use the generic view in your own view. It's a pretty 
common pattern in Django.

In this case, you probably just want to pass the user as a extra context 
variable to be rendered as a hidden for your form.

-- 
George

--~--~-~--~~~---~--~~
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: How to create a newforms label unattached to an input field?

2009-05-11 Thread George Song

On 5/11/2009 12:29 PM, Nash-t wrote:
> I apologize if this is a dumb newbie question...
> I am trying to create a newform label that doesn't have an associated
> input field. This label is used as a title for a set of  input fields.
> I don't want to use django templates because of the way the form/data
> is passed around and saved on the server side.
> Any advice?

I'm not sure I understand entirely what you're doing. In any case, you 
have a few options:

1. If this is one specific form, you can just override it's rendering 
method, or write your own rendering method for that form which takes 
care of generating the correct label at the right place.

2. Write a custom widget, since widgets are responsible for rendering 
fields out to the form.

-- 
George

--~--~-~--~~~---~--~~
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: two models, 1 table

2009-05-11 Thread George Song

On 5/11/2009 8:55 PM, rpupkin77 wrote:
> Hi, can I use the same table in two different models and surface
> different data in each, model, particularly in the admin panel?

Sounds like a job for proxy models[1], each with its own default manager.

[1]

-- 
George

--~--~-~--~~~---~--~~
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: modular django site: projects vs. apps

2009-05-12 Thread George Song

On 5/12/2009 3:27 AM, mabuse wrote:
> I am developing a django site and my aim is to obtain a site with a
> core  application that would be the site basis and above it addons
> that would upgrade the standard application ( like firefox and its
> extensions).
> 
> My question is, how can I achieve that? My idea is to create two
> projects:
> 1. One project would be the "core project": with all basic apps.
> 2. The other would be the "addons site project": including the addons
> configured as apps.
> 
> Is it the best solution? Or it would be nicer to have only one project
> and the addons configured as separate apps?

It depends on if these "add-ons" are truly independent apps or not. If 
they can't be used outside of the context of your core project, then 
there's no need to separate them, really.

If they are meant to be independent, then you'll need to take care that 
they have no dependences on *any* project whatsoever. And preferably not 
on other apps as well (except maybe django.contrib ones).

-- 
George

--~--~-~--~~~---~--~~
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: session through redirects

2009-05-12 Thread George Song

On 5/12/2009 5:45 AM, Iqbal Abdullah wrote:
> I'm confused on how to get data in request.session if a certain view
> redirects the user using HttpResponseRedirect()
> 
> A sample code:
> 
> def view_start(request):
> try:
> Member(id)
> except Exception, e:
> # redirect to registration page if this id is not
> registered
> template_path = "member/register.html"
> 
> request.session['test_id'] = 200
> 
> url = "/member/register/" # This url is processed by
> view_register()
> return HttpResponseRedirect(url)
> 
> def view_register(request):
> 
> test_id = request.session.get('test_id', None)
> 
> 
> in this case I will get None for test_id in view_register().
> Is it possible to pass along sessions data when we use
> HttpResponseRedirect() to redirect? Just from the code above I don't
> see how that's possible because request in view_start() didn't get
> passed anywhere when the redirect occurred.
> 
> I searched through the discussions and found something exactly like
> what I'm doing (http://groups.google.com/group/django-users/
> browse_thread/thread/451abbaf1feccf0b/19f266af42f4ed62?
> hl=en&lnk=gst&q=sessions+HttpResponseRedirect#) and the OP says it's
> working for him, but I'm not seeing the same results. Can members
> point me to the right direction on how to use sessions through
> redirects?

Your code appears correct for how you're using `request.session`. Couple 
things to check:

1. Make sure you've enabled your sessions[1].
2. Make sure you are getting the `sessionid` cookie in your browser.

[1] 


-- 
George

--~--~-~--~~~---~--~~
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: Help a noob with a stupid question - forms

2009-05-12 Thread George Song

On 5/12/2009 7:05 AM, zachp wrote:
> Yes, but the calendar widget isn't what I want. My user only really
> needs to pick a month (and maybe a year) but not a day. I could resort
> to using that field type, but I wanted to see if I could overcome this
> problem since, at least in my opinion, the calendar widget might be a
> little confusing.

To get you started, here's a widget I wrote and use myself:


-- 
George

--~--~-~--~~~---~--~~
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: get_or_create not atomic?

2009-05-12 Thread George Song

On 5/12/2009 10:47 AM, Phil Mocek wrote:
> It seems risky to try to handle at the
> application level these things that a DBMS is specifically
> designed to do.

Well, exactly. If the correct constraints are put in place, then your 
DB/adaptor would raise the proper error.

So if a row is supposed to be "unique", by whatever criteria, and that 
criteria is enforced through the DB via proper model definition, the 
second insert would fail properly.

-- 
George

--~--~-~--~~~---~--~~
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: flatpage content not appearing

2009-05-12 Thread George Song

On 5/12/2009 10:54 AM, Jesse wrote:
> Now I get all kinds of 404 errors.  I guess I'm missing something in
> my understanding of flatpages.  I was going to place all my html pages
> into flatpages, including the home page.  How does all that work
> without using URLs and views?

It's answered in the documentation section for flatpages under "How it 
works":


-- 
George

--~--~-~--~~~---~--~~
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: how can I modify automatic ordering of fields in a ModelForm?

2009-05-12 Thread George Song

On 5/12/2009 11:22 AM, Luke Graybill wrote:
> Is there a good way to dynamically reorder these fields on the fly? 
> Preferably, the code should be contained within the Mixin class. In 
> my situation, the mixin fields would be better if placed after all 
> the other fields on a model, but in other situations a mixin might 
> want a different order.

Do you have a proposed solution on how to achieve what you want? How 
would you express the different "situations" within the mixin?

-- 
George

--~--~-~--~~~---~--~~
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: how can I modify automatic ordering of fields in a ModelForm?

2009-05-12 Thread George Song

On 5/12/2009 11:32 AM, Luke Graybill wrote:
> I didn't mean to imply a feature suggestion, I meant to ask if this is 
> possible already. If not, then is there some way to manipulate the form 
> __init__ (through _meta.fields perhaps?) to accomplish an approximation 
> of what I want?
> 
> I'm just looking for a best-practice solution here - am I out of luck on 
> this, or can I get some ideas on how better to handle things?

I'm not clear on how you would:

1. Avoid knowing what fields are served up by a given mixin.
2. Avoid explicitly referring to those fields to affect the order other 
than the default.

Since you want "automatic" ordering, I'm assuming you're just throwing 
{{ form }} on your template, right?

As far as I know, there's no hook into a Form object to directly 
manipulate the field order. I think your options are:

1. Manipulate the order of `form.fields` upon `__init__`.
2. Subclass `forms.Form` and override `_html_output` however you want.
3. Write a custom form rendering method on your form class or superclass.
4. You can couple #3 with a form factory that accepts something like 
`ModelAdmin.fields` so you can be dynamic about the field order without 
having to create additional form classes.

I think the ModelAdmin form factory pattern is a pretty good one to follow.

-- 
George

--~--~-~--~~~---~--~~
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: how can I modify automatic ordering of fields in a ModelForm?

2009-05-12 Thread George Song

On 5/12/2009 12:12 PM, Alex Gaynor wrote:
> You can control the order of fields on a modelform by settings the 
> ordering in the fields option in the inner Meta class.  That is if you 
> set fields = ['b', 'a', 'c'] that's the same order they will apear in.

Duh. There you go, problem solved:


The changes are fast and furious, hard to keep up with everything.

-- 
George

--~--~-~--~~~---~--~~
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: how can I modify automatic ordering of fields in a ModelForm?

2009-05-12 Thread George Song

On 5/12/2009 12:28 PM, Luke Graybill wrote:
> Here is how I've implemented field ordering for 1.0.2

The snippet doesn't appear to be available anymore.

--~--~-~--~~~---~--~~
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: How do you handle apostrophe and spaces in dynamic url?

2009-05-12 Thread George Song

On 5/12/2009 1:10 PM, Thierry wrote:
> I have a table with the following names:
> 
> id  name
> 1   Foo
> 2   Foo goo
> 3   Foo's goo
> 
> I want to use the name to construct my url.  I don't have a problem
> constructing Foo:
> 
> localhost/foo
> 
> But how am I supposed to handle "Foo goo" and "Foo's goo"?  Will I
> need to create a 3rd column just to hold the url like the following:
> 
> id  name   url
> 1   Foo foo
> 2   Foo goo   foo-goo
> 3   Foo's goo foos-goo
> 
> I will also need that url to retrieve information on that entry from
> the table.  Can someone with a lot of experience in web dev confirm
> that the above is the best way to handle this situation?



-- 
George

--~--~-~--~~~---~--~~
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: Trouble starting up runserver

2009-05-12 Thread George Song

On 5/12/2009 2:01 PM, Chris DPS wrote:
> I am new to Django.
> 
> When I try to execute: python manage.py runserver, I get the following
> error
> 
> Error: [Errno 10104] getaddrinfo failed
> 
> What is going on and what should I do?
> 
> I am running Django Version 1.0.2-final and Python 2.6
> 
> I have turned off all Firewalls.
> 
> ping to localhost in the cmd works fine
> 
> I tried starting runserver on 0.0.0.0:8000, :8000, and other ports
> with the same results.
> 
> Please help!

Maybe this thread can be of help?


-- 
George

--~--~-~--~~~---~--~~
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: ForeignKeys to MTI models break admin (as of 10756)

2009-05-15 Thread George Song

On 5/14/2009 11:40 PM, Russell Keith-Magee wrote:
> On Fri, May 15, 2009 at 2:21 PM, Michael Strickland  
> wrote:
>> Hi all,
>>
>> I've recently encountered a problem that arose with revision 10756.
>> Say you have the following models:
>>
>> class Person(models.Model):
>>name = models.CharField(max_length=20)
>>
>> class Student(Person):
>>grad_year = models.IntegerField()
>>
>> class Picture(models.Model):
>>image = models.ImageField(upload_to='images')
>>owner = models.ForeignKey(Student)
>>
>> In other words, Pictures belong to Students through a FK, and Students
>> use MTI to inherit from Persons.
>>
>> This worked fine, up until 10756 (http://code.djangoproject.com/
>> changeset/10756). Now, it throws a DoesNotExist exception (at  /usr/
>> lib/python2.5/site-packages/django/db/models/fields/related.py in
>> __get__, line 243) when Picture is included in the inlines for
>> Student.
>>
>> I've been able to make it work by having the foreignkey point to
>> Person instead of Student, but that's not exactly ideal with my real
>> models. Since the specifics of that revision are a bit over my head,
>> can anyone tell me if this was an intended side effect of it, and if
>> so, why foreignkeys to inherited models would no longer be supported?
> 
> I can't see immediately wrong with your example, so I'm guessing this
> is an unintended consequence. I'll take a look at this; it would be
> most helpful if you could open a ticket with your example code.

Imagine my surprise when I svn updated tonight. I opened a ticket:


-- 
George

--~--~-~--~~~---~--~~
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: abstract classes in models

2009-05-15 Thread George Song

On 5/15/2009 8:18 AM, Rusty Greer wrote:
> 
> 
> I have something like this:
> 
> class Class1(models.Model):
> // lots of fields here
> 
> class AbstractThing(models.Model):
> // lots of fields here
> class1field = model.ForeignKey(Class1)
> class Meta:
> abstract = True
> 
> class ThingType1(AbstractThing):
> // lots of fields here
> 
> class ThingType2(AbstractThing):
> // lots of fields here
> 
> 
> in my template, i want to be able to do something like:
> class1.abstractthing_set.all
> 
> but that doesn't seem to work, i seem to have to do:
> class1.thingtype1_set.all and class1.thingtype2_set.all
> 
> does this make sense?  am i missing something?
> 
> any help would be appreciated.

The pattern you describe should work fine. What exactly isn't working?

-- 
George

--~--~-~--~~~---~--~~
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: abstract classes in models

2009-05-15 Thread George Song

On 5/15/2009 10:08 AM, Rusty Greer wrote:
> 
> 
> On Fri, May 15, 2009 at 9:57 AM, George Song  <mailto:geo...@damacy.net>> wrote:
> 
> 
> On 5/15/2009 8:18 AM, Rusty Greer wrote:
>  >
>  >
>  > I have something like this:
>  >
>  > class Class1(models.Model):
>  > // lots of fields here
>  >
>  > class AbstractThing(models.Model):
>  > // lots of fields here
>  > class1field = model.ForeignKey(Class1)
>  > class Meta:
>  > abstract = True
>  >
>  > class ThingType1(AbstractThing):
>  > // lots of fields here
>  >
>  > class ThingType2(AbstractThing):
>  > // lots of fields here
>  >
>  >
>  > in my template, i want to be able to do something like:
>  > class1.abstractthing_set.all
>  >
>  > but that doesn't seem to work, i seem to have to do:
>  > class1.thingtype1_set.all and class1.thingtype2_set.all
>  >
>  > does this make sense?  am i missing something?
>  >
>  > any help would be appreciated.
> 
> The pattern you describe should work fine. What exactly isn't working?
> 
> --
> George
> 
> 
> from within the template, class1.abstractthing_set.all returns nothing, 
> class1.thingtype1_set.all returns exactly what is expected
> 
> from python code, class1.abstractthing_set.all gives me an AttributeError 
> 
> 'class1' object has no attribute 'abstractthing_set'
> 
> 
> class1.thingtype1_set.all returns exactly what is expected
> 
> i was hoping that the abstractthing_set would return all of the objects 
> of both thingtype1 and thingtype2

Oh duh. You're using abstract. What you want is multi-table inheritance, 
if that fits your use case.

-- 
George

--~--~-~--~~~---~--~~
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: Question: What's the best way to denormalize M2M data?

2009-05-19 Thread George Song

On 5/18/2009 8:51 PM, palewire wrote:
> I've stumbled my way into methods for automatically denormalizing
> ForeignKey data -- and now see that better  approaches have been
> packaged up the very cool django-denorm (http://code.google.com/p/
> django-denorm/) -- which is great.
> 
> But I'm curious to ask smarter people than myself about best practices
> for denormalizing M2M relationships. The problem I've bumped into in
> my feeble efforts is the same hurdle described concisely here:
> 
> http://groups.google.com/group/django-users/browse_thread/thread/99680b69d2d4799c/07093d3695163269
> 
> So, rather than wait for ticket 5390 (http://code.djangoproject.com/
> ticket/5390) or another expansion in that direction, I thought I'd ask
> the list since there's probably great concept for getting this done
> that I'm ignorant of. I tried a scrub of Google and the list archives
> without much luck, but please forgive me if I'm overlooking something
> obvious.

You can always explicitly define the m2m model, then you can override 
the save() on that model if you like, or use signals like any other model.

-- 
George

--~--~-~--~~~---~--~~
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: Form Wizard and Saving to Database

2009-05-19 Thread George Song

On 5/18/2009 4:01 PM, geraldcor wrote:
> Hello all,
> 
> I am working on my second Django app and it involves a very long form.
> I successfully used modelForms in my last app to successfully save
> form data to a database.
> 
> With this long form, I have split it up into smaller forms (forms.Form
> not ModelForms) and used the FormWizard to tie it all together. All is
> well so far. However, now I have no idea how to save the form data
> from form_list into my database. It is only one table so I don't have
> any foreign key stuff going on. I just need to save the form data and
> move on with my life :)
> 
> I have searched the Django site and web extensively and haven't found
> anything useful about saving data from regular forms or FormWizards.

Just instantiate a new Model object with the form attributes assigned to 
the proper model attributes, and save the object. If you happen to name 
your form fields the same as your model fields, then you can just use 
cleaned_data directly:

{{{
form_data = {}
for form in form_list:
 form_data.update(form.cleaned_data)
m = Model.objects.create(**form_data)
}}}

-- 
George

--~--~-~--~~~---~--~~
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: ModelForm question

2009-05-19 Thread George Song

On 5/18/2009 12:55 PM, Rusty Greer wrote:
> 
> i have the following:
> 
> a model:
> class MyClass(models.Model):
> otherClass = models.ForeignKey('otherClass')
> someData = models.CharField(max_length=20)
> 
> 
> class MyClassForm(forms.ModelForm):
> 
> class Meta:
> model = MyClass
> fields = ('someData')
> 
> 
> When the user edits or adds a MyClass object with the MyClassForm, the 
> otherClass will always be known.  I don't want the user to ever change 
> the otherClass.  What I want it to be in the MyClassForm is a hidden 
> field.  I know I can do this with a Form instead of a ModelForm, but I 
> like the convenience of the ModelForm.  Is there a way to pass hidden 
> inputs through a ModelForm and still get the convenience of the ModelForm?
> 
> Any help would be appreciated.

Just override otherClass's widget.
See: 


-- 
George

--~--~-~--~~~---~--~~
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 Error: couldn't locate module Http.Isapi

2009-05-19 Thread George Song

On 5/18/2009 6:53 AM, BuckRogers wrote:
> Hi,
> 
> I am using IIS6/Python2.5/mssql 2000 on windows server 2003
> 
> I followed the instructions available here:
> http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer
> 
> PyISAPIe doesn't seem to work, I am getting Import Error: couldn't
> locate module Http.Isapi
> 
> Any idea?

Your PYTHONPATH is probably not set correctly. You'll have to make sure 
the environment variable is set properly for the IIS user. There are 
couple special users if I remember correctly.

I'm not sure if you can set an ISAPI filter to run as a specific user, 
if so, that could be another route.

-- 
George

--~--~-~--~~~---~--~~
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: Question: What's the best way to denormalize M2M data?

2009-05-19 Thread George Song

On 5/19/2009 9:47 AM, Ben Welsh wrote:
> On Tue, May 19, 2009 at 12:18 AM, George Song  <mailto:geo...@damacy.net>> wrote:
> 
> 
> You can always explicitly define the m2m model, then you can override
> the save() on that model if you like, or use signals like any other
> model.
> 
> 
> Perhaps I've fumbled my way past the obvious, but the problem I'm 
> running into with that method is the one described in the link above. It 
> seems the M2M data connections are not inserted into the relational 
> database until a PK has been created and all the signals have already 
> fired.

Can you be more explicit about describing what it is you want to do?

-- 
George

--~--~-~--~~~---~--~~
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: Setting tzinfo for DateTimeFields with Postgresql - workaround

2009-05-21 Thread George Song

On 5/16/2009 10:28 PM, Glenn Maynard wrote:
> This is just a quick hack for anyone else bit by this: tzinfo is never
> set when reading DateTimeFields out of the database, at least with
> Postgresql.
> 
> Now, I have no idea why anyone would want to set TIME_ZONE to anything
> but UTC (and the default of an arbitrary US timezone is rather
> bizarre), but even with UTC, you need a tzinfo set on your datetimes,
> in order to localize them to user time zones with astimezone().  Doing
> this manually is a pain--you need to replace(tzinfo=UTC) before every
> datetime access.

Hi Glenn,

When you get the chance can you review my proposal[1] for fixing 
DateTimeField in Django?

I'm going to try to get this in for 1.2 release.

[1] http://code.djangoproject.com/ticket/10587

-- 
George

--~--~-~--~~~---~--~~
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: Making queries on manytomany tables

2009-05-22 Thread George Song

On 5/22/2009 5:31 PM, Patrick wrote:
> What is the best way to make queries on a manytomany table?
> 
> Given the models below, how can I get a list of all the songs a
> particular artist has?
> 
> class Artist(models.Model):
> name = models.CharField(max_length=128)
> 
>def __unicode__(self):
> return u'%s' %(self.name)
> 
> class Album(models.Model):
> title = models.CharField(max_length=128)
> artists = models.ManyToManyField(Artist)
> 
> def __unicode__(self):
> return u'%s' %(self.title)
> 
> 
> class Song(models.Model):
> title = models.CharField(max_length=128)
> albums = models.ManyToManyField(Album)
> 
> def __unicode__(self):
> return self.title

Probably a compound query:

1. All albums for a given artist
2. All songs where albums in #1

-- 
George

--~--~-~--~~~---~--~~
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: how to load data?

2009-05-22 Thread George Song

On 5/22/2009 5:07 PM, Herta wrote:
> I want to load data to database (sqlite3 ) from file. I have already
> connect django and my database, and build the tables but how can i
> load data from file?

What kind of files are these? If they are existing legacy data files, 
you'll have to write some sort of de-serializer to translate them to fit 
your model(s).

If the file happens to be one of the serialization formats that Django 
already knows how to deal with, you might be able to use Django's 
serialization somehow.

But some more specifics on your data format will allow us to help you more.

-- 
George

--~--~-~--~~~---~--~~
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: Plugin technology

2009-05-23 Thread George Song

On 5/23/2009 5:13 AM, Jani Tiainen wrote:
> I'm designing application (site) that is supposed to rely heavily on 
> pluings.
> 
> i didn't found much of references how I can create plugin that can 
> provide something useful for my main template. something like:
> 
> myplugin.py:
> 
> provide_link = "MyPlugin"
> 
> And then in my "core" application template:
> templates/mycore/mycore.html:
> 
> {% for plugin in allplugins %}{{ plugin.provide_link }}{% endfor %}
> 
> Any pointers to such apps or snippets that uses this (or similiar) 
> tehcnique would be appreciated.

Well, if you break down the problem, it really is just two things:

1. Registry
2. Interface

Registry

The registry takes care of the part that when you create a new plugin, 
it should be registered somehow as a plugin.

Django itself is full of this pattern: models, template tags, filters, 
admin sites, databrowse, serialization, etc. You can look to those for 
ideas and inspirations. The most sophisticated being the models which 
relies on a metaclass to do its implicit registration magic.

Interface
=
This is really internal to the specific plugin domain, so depending on 
your needs, you can enforce it a number of ways: simple documentation of 
the superclass, putting in a stub of NotImplemented, etc.

-- 
George

--~--~-~--~~~---~--~~
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: Plugin technology

2009-05-23 Thread George Song

On 5/23/2009 8:53 AM, Jani Tiainen wrote:
> Kai Diefenbach kirjoitti:
>> Hi Jani,
>>
>> On 23 Mai, 14:13, Jani Tiainen  wrote:
>>> I'm designing application (site) that is supposed to rely heavily on
>>> pluings.
>>>
>>> i didn't found much of references how I can create plugin ...
>> You may look into this article: 
>> http://martyalchin.com/2008/jan/10/simple-plugin-framework/
> 
> I already did. it just didn't (Or I missed somehow) how to make 
> something like "toolbar" buttons in plugin that could be injected to my 
> main template.

If you're using Marty's pattern, why don't you just pass the mount point 
as a context variable to your template, then you can easily loop through 
the plugins that way, right?

-- 
George

--~--~-~--~~~---~--~~
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: use of HttpResponseForbidden(), etc.

2009-05-23 Thread George Song

On 5/23/2009 9:07 AM, ken keller wrote:
> When my view returns:
> 
> return HttpResponseForbidden()
> 
> the browser doesn't show the non-200 status.

How are you determining that the browser is not receiving a 403 status?

-- 
George

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



  1   2   >