Re: ImageField error

2008-07-06 Thread Milan Andric

On Sun, Jul 6, 2008 at 3:12 PM, Molly <[EMAIL PROTECTED]> wrote:
>
> Millan,
>
> I'm doing this in dev environment with the built in webserver. No it's
> not a mod_python error.
>
> I'm using the static setup and I can get to it fine when I upload my
> photo.
> The problem is when I click the photo it seems to be pointing to
> somewhere else.
>
> In my models:
> ==
> photo = models.ImageField("Photograph", upload_to='images/uploaded',
> blank=True,null=True)
> ==
>
> if i manually go to /images/uploaded my photo is there, but the link
> in the admin site seems to be wrong.
>
> this is the link, it's adding all of the extra information:
> ==
> http://127.0.0.1:8000/admin/base/incident/1/media/images/uploaded/DCP_0326.JPG
> ==

What do you have for MEDIA_URL in your settings.py file?  Should be
something like MEDIA_URL='/media/', my guess is you are missing a
leading slash.  If you can paste your settings.py and model that would
help, http://dpaste.com .

--
Milan

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



Re: Using a Custom Manager for date based generic views??

2008-07-06 Thread Rob Hudson

On Jul 6, 3:53 pm, Christopher Clarke <[EMAIL PROTECTED]> wrote:
> class IssuerManaager(models.Manager):
>
>      def with_aggs(self):
>          from django.db import connection
>          cursor=connection.cursor()
>          cursor.execute("""
>              select i.id,max(i.name), m.dateix AS period_ending,
>              count(*) AS no_funds,
>              sum(vd.total_units_issued_outstanding) as  
> total_units_issued_outstanding,
>              sum(vd.total_unit_holders) as no_unit_holders,
>              sum(vd.tt_total_net_assets_under_management) AS  
> net_assets_under_management,
>              sum(vd.tt_value_redemptions) AS total_redemptions,
>              sum(vd.tt_value_sales) AS total_sales
>              FROM core_fundvolumedata vd, core_fund f, core_issuer i,  
> freqdates_monthly m
>              WHERE f.id = vd.fund_id AND f.issuer_id = i.id AND m.id =  
> vd.period_ending_id
>              GROUP BY i.id, m.dateix, vd.period_ending_id
>              ORDER BY i.id, m.dateix;
>              """)
>          results_list= []
>          for each in cursor.fetchall():
>              p= self.model(id=each[0],name=each[1])
>              p.period_ending=each[2]
>              p.no_funds = each[3]
>              p.units_issued_outstanding=each[4]
>              p.no_unit_holders=each[5]
>              p.net_assets_under_management=each[6]
>              p.redemptions=each[7]
>              p.sales=each[8]
>              results_list.append(p)
>          return results_list
>
> class Issuer(models.Model):
>      name = models.CharField(max_length=100)
>            --
>            --
>            --
>      objects = IssuerManaager()
>
>    The manager works but when i try to use it in the generic view
>
>       return archive_month(
>                           request,
>                           year=year,
>                           month=month,
>                           queryset = Issuer.objects.with_aggs(),
>                           date_field = 'period_ending',
> I get
> list' object has no attribute 'model'
> Am i on the right track and how do i get this to work??
> Thanks for any help
> Regards
> Chris

The thing is, your manager method is returning a list, and the generic
view is expecting a queryset.  If you can get a list of ids from you
custom SQL you could then create a QuerySet object to return by using
the 'in' filter:
http://www.djangoproject.com/documentation/db-api/#in

Or write your own view that expects a list that is similar to the
archive_month view.

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



Re: Using a Custom Manager for date based generic views??

2008-07-06 Thread Milan Andric

On Sun, Jul 6, 2008 at 5:53 PM, Christopher Clarke <[EMAIL PROTECTED]> wrote:
> Hi Guys
> I'm  building a django based system for a company that monitors the mutuals
> funds industry
> We have Mutual Funds Companies (Issuer) who have one or more funds (Fund)
> and every month the funds submit a volume report
> Here is a simplified version
> 
> class Issuer(models.Model):
>name=models.CharField(max_length=100,unique=True)
>--
>--
>--
> class Fund(models.Model):
> issuer = models.ForeignKey(Issuer)
> symbol = models.CharField(max_length=15,unique=True)
> --
> --
> class FundVolumeReport(models.Model):
>
> fund= models.ForeignKey(Fund)
> period_ending=models.DateField()
>
>  
> units_purchased_individuals=models.FloatField(verbose_name="Individuals",blank=True,null=True)
>
>  
> units_purchased_institutions=models.FloatField(verbose_name="Instutions",blank=True,null=True)
> --
> --
> Now we need to produce totals for each Issuer by month   i implemented a
> date based generic view using a model (IssuerVolumeAggregates) which wrapped
> a database view which did the aggregation i.e
> CREATE OR REPLACE VIEW core_issuervolumeaggregates AS
>   select
>   
> trim(to_char(i.id,'999'))||trim(to_char(vd.period_ending_id::int,''))::int
> as id,
>   i.id as issuer_id,
>   max(i.name)as name,
>   m.dateix as period_ending,
>   count(*) as no_funds
>   --
> --
>  from core_fundvolumedata vd,
>   core_fund f, core_issuer i, freqdates_monthly m
>   where f.id=vd.fund_id and f.issuer_id=i.id
>   and m.id=vd.period_ending_id
>   group by i.id,vd.period_ending_id,m.dateix
>   order by i.id,m.dateix;
> This works pretty well but its kind a clunky so i was wondering if i could
> do the same thing with a custom manager
> ==
> class IssuerManaager(models.Manager):
>
> def with_aggs(self):
> from django.db import connection
> cursor=connection.cursor()
> cursor.execute("""
> select i.id,max(i.name), m.dateix AS period_ending,
> count(*) AS no_funds,
> sum(vd.total_units_issued_outstanding) as
> total_units_issued_outstanding,
> sum(vd.total_unit_holders) as no_unit_holders,
> sum(vd.tt_total_net_assets_under_management) AS
> net_assets_under_management,
> sum(vd.tt_value_redemptions) AS total_redemptions,
> sum(vd.tt_value_sales) AS total_sales
> FROM core_fundvolumedata vd, core_fund f, core_issuer i,
> freqdates_monthly m
> WHERE f.id = vd.fund_id AND f.issuer_id = i.id AND m.id =
> vd.period_ending_id
> GROUP BY i.id, m.dateix, vd.period_ending_id
> ORDER BY i.id, m.dateix;
> """)
> results_list= []
> for each in cursor.fetchall():
> p= self.model(id=each[0],name=each[1])
> p.period_ending=each[2]
> p.no_funds = each[3]
> p.units_issued_outstanding=each[4]
> p.no_unit_holders=each[5]
> p.net_assets_under_management=each[6]
> p.redemptions=each[7]
> p.sales=each[8]
> results_list.append(p)
> return results_list
>
> class Issuer(models.Model):
> name = models.CharField(max_length=100)
>   --
>   --
>   --
> objects = IssuerManaager()
>   The manager works but when i try to use it in the generic view
>  return archive_month(
>  request,
>  year=year,
>  month=month,
>  queryset = Issuer.objects.with_aggs(),
>  date_field = 'period_ending',
> I get
> list' object has no attribute 'model'
> Am i on the right track and how do i get this to work??
> Thanks for any help

Hrm, can you include a complete traceback?  Looks like you are on the
right track, just looking at
http://www.djangoproject.com/documentation/model-api/#custom-managers
.

--
Milan

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



Re: home page

2008-07-06 Thread Milan Andric

On Sun, Jul 6, 2008 at 10:52 PM, keegan3d <[EMAIL PROTECTED]> wrote:
>
> Hey everyone,
>
> I am a little foggy on how I would go about making a home page, by
> that I mean the page that people see when they go to the main address:
> www.mysite.com.
>
> Should I make a "home page" app? or does django have a way of dealing
> with this?
>

If your frontpage doesn't change much you can also just use a template
and generic view url config to manage it.

# or also include some forum entries on the homepage as well
object_list = Forum.objects.all()
...
  url(
   r'^$',
   'django.views.generic.simple.direct_to_template',
   {'template': 'home.html', 'extra_context': {
'object_list':object_list } }
   ),
...

http://www.djangoproject.com/documentation/generic_views/#django-views-generic-simple-direct-to-template

--
Milan

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



Re: home page

2008-07-06 Thread Eric Abrahamsen

Hey Dave,

Your homepage, or index view, is nothing more than a (r'^$', 'index',)  
entry in your urlconfs, and an 'index' view somewhere in your codebase  
(obviously it doesn't have to be called index). While I've got several  
apps tied together for any one site, there's usually one app that's  
more 'central' than the others, and I tend to stick the index urlconf  
and view in with that app.

If you'd like it to be a little more separate, you could create a  
separate file (called 'indexview.py', for instance) with one view in  
it, put that in your root project directory, and add a url regex like  
this:

(r'^$', 'myproject.indexview.index')

The key is that r'^$' will pick up a request with no script path (ie  
'/', ie 'http://www.mysite.com/'). Where you put the view it calls  
makes very little difference.

Hope that helps,
Eric



On Jul 7, 2008, at 11:52 AM, keegan3d wrote:

>
> Hey everyone,
>
> I am a little foggy on how I would go about making a home page, by
> that I mean the page that people see when they go to the main address:
> www.mysite.com.
>
> Should I make a "home page" app? or does django have a way of dealing
> with this?
>
> Thanks for the help!
>
> -Dave
> >


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



home page

2008-07-06 Thread keegan3d

Hey everyone,

I am a little foggy on how I would go about making a home page, by
that I mean the page that people see when they go to the main address:
www.mysite.com.

Should I make a "home page" app? or does django have a way of dealing
with this?

Thanks for the help!

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



Re: Django + tiny_mce

2008-07-06 Thread Chatchai Neanudorn
Oh, Fixed me, 404 (File not found!)

I was in situation like you, before. Some instruction or recipe assume you
have basic understanding of django.

There are a lot of django recipe assume that you put js or css under the
same place of admin media.
In this case, you don't need to configure media url by your self. But for
running dev server only.

For example, put js under /django/contrib/admin/media/js/some.js. Then
/media/js/some.js will availale for you.

For now, I'm working with java script and first thing I have to do is making
it available first and do things I want.

Anyway, when you run your web using apache, you will need to use alias to
provide admin media.

For my solution, I use something like this,

*ADMIN_MEDIA_PREFIX = '
http://eestud.kku.ac.th/~u4316562/media/openfrog/media/'*

For this setting, I don't need to setup my admin media and save bandwidth
for my share host account.

For another media, I use,
*
DIR = os.path.dirname(__file__)*
*MEDIA_ROOT = os.path.join(DIR, 'static')
MEDIA_URL = 'http://feedfrog.net/static/'

httpd.conf

Alias /static /home/meledictas/webapps/django/meledictas/static*

I use this for all of my django site.

Have a nice day.

Chatchai.

2008/7/7 LRP <[EMAIL PROTECTED]>:

>
> Many thanks for the help, Chatchai.
>
> > Can you start web server and
> typehttp://localhost/usr/share/tinymce/www/tiny_mce.js
> > and see if it return something rather than 400.
>
> I get 404.
>
> Here's url config:
>
> urlpatterns = patterns('',
># Example:
># (r'^cms/', include('cms.foo.urls')),
>
># Uncomment this for admin:
>(r'^admin/', include('django.contrib.admin.urls')),
>(r'', include('django.contrib.flatpages.urls')),
> )
>
> In addition to Bennett and djangoprogject docs, the approach you
> suggest is yet a third solution to the problem of applying tiny_mce to
> django admin... I'll give it a try tomorrow when my mind is a more
> rested.
>
> But meanwhile, I'm curious...
>
> I've followed the instructions in both Bennett' and the djangoproject
> docs scrupulously; double-checking my work in both cases. And in both
> cases I've failed. It's likely, I'm sure, that my failure is due to a
> misreading, misunderstanding, or mistyping on my part. I'm wondering,
> however, has anyone else achieved success based on either Bennett's or
> djangoproject doc's instructions?
>
> If so, then I'll have to carefully review what I've done.
>
> If not, then there's a chance that either or both of the sources are
> either wrong, or are missing something, and should be corrected.
>
> I do recall that I got it working quite easily once in Karrigell.
>
> Thanks again,
>
> Lloyd
>
>
>
>
> >
>

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



Re: "Eval" in templates?

2008-07-06 Thread Ben Kovitz

Uh!! (Hits hand into forehead.)  Yep, just including a template named
by a variable would have been much simpler.

However, it's all worked out nicely.  Having seen just how easy it is
to write a custom template tag, I replaced the 'eval' tag with a
couple specialized tags, which render from another template (like an
inclusion tag, but with some processing).  This enabled something like
local variables for the "subroutine" template: if you say {% mytag
userGadget %}, the Python code for the tag copies the value of
"userGadget" into "gadget" in the Context that the mytag template
sees.  And that template still gets to see all the variables in the
top-level template's Context.

I pulled the same trick on three messy things, and now our templates
are ridiculously simple.

My hat is off to the designers of Django's templating system!
Beautiful, simple, efficient.

Ben
http://decisionero.com


On Jul 5, 7:34 am, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> Now that you have an eval tag, maybe you don't need this, but I think
> Django already had a simpler solution to your problem:
>
> Context:
> buttonDecidedAtRunTime: 'button4.html'
> thisPage: "/some/path"
>
> blah.html:
> {% include buttonDecidedAtRunTime %}
>
> The argument to the include tag doesn't need to be a literal string, it
> can be a value from the context.  This has the added advantage that the
> common "{% include " in each of your button choices is factored out and
> appears only once, in blah.html.
>
> --Ned.http://nedbatchelder.com
>
> Ben Kovitz wrote:
> > Thanks for the encouragement, Alex.  This was so easy, it should be a
> > first lesson in how to write a custom tag.  It took about 15 minutes
> > and worked the first time!
>
> > from django import template
>
> > register = template.Library()
>
> > @register.tag(name="eval")
> > def do_eval(parser, token):
> >try:
> >   tagName, variableName = token.split_contents()
> >except ValueError:
> >   raise template.TemplateSyntaxError("%r requires a single
> > argument: the name of the variable to evaluate as the body of a
> > template" % tagName)
>
> >return EvalNode(variableName)
>
> > class EvalNode(template.Node):
>
> >def __init__(self, variableName):
> >   self.variableName = variableName
>
> >def render(self, context):
> >   t = template.Template(context[self.variableName])
> >   return t.render(context)
>
> > On Jul 4, 5:51 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> >> I don't think it would be difficult to implement, either as a block
> >> tag, or as a regular tag with context.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: html templates - 'for' cycle without a variable

2008-07-06 Thread Milan Andric

On Thu, Jul 3, 2008 at 10:21 AM, antony_h <[EMAIL PROTECTED]> wrote:
>
> How could I repeat my  20 times?
> I've found how I can repeat it 5 times:
> {% for a in 12345|make_list %}
> 
> {% endfor %}
> But it's not so great for e.g. a hundred
> Usage: my designer wants to test his layout and I don't want to create
> a custom tag for such a simple task
>

You could probably use a generic view for this pretty easily, just
pass in a list with 20 elements in it.  Something like :

list = range(0,20)

   url(
r'^test/$',
'django.views.generic.simple.direct_to_template',
{'template': 'test.html', 'extra_context': { 'list':list } }
),

See generic views documentation:
http://www.djangoproject.com/documentation/generic_views/#django-views-generic-simple-direct-to-template

The django templating language is purposely dumbed down so the work is
done in the view according to the model-view-template pattern.

--
Milan

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



Re: pluggable django ticketing app?

2008-07-06 Thread Milan Andric

On Sun, Jul 6, 2008 at 12:05 AM, chefsmart <[EMAIL PROTECTED]> wrote:
>
> Does anyone know of a pluggable django ticketing app? Something like
> the apps used by webhosts for online support?

I have yet to see something available for Django that does
ticketing/issue tracking.  But I may have missed it, hopefully someone
on this list can enlighten the both of us.  But in the Python world
setting up Trac to integrate Django authentication was not too ugly.
Here's the Trac module I used with the 0.12 (i think) version of Trac.

http://trac-hacks.swapoff.org/attachment/wiki/DjangoAuthIntegration/djangoauth_1.py
http://trac-hacks.org/wiki/DjangoAuthIntegration

But I have heard at least a handful of people interested in developing
this kind of app, me included, but my queue is backlogged as usual.

--
Milan

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



Re: Django + tiny_mce

2008-07-06 Thread LRP

Many thanks for the help, Chatchai.

> Can you start web server and 
> typehttp://localhost/usr/share/tinymce/www/tiny_mce.js
> and see if it return something rather than 400.

I get 404.

Here's url config:

urlpatterns = patterns('',
# Example:
# (r'^cms/', include('cms.foo.urls')),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),
(r'', include('django.contrib.flatpages.urls')),
)

In addition to Bennett and djangoprogject docs, the approach you
suggest is yet a third solution to the problem of applying tiny_mce to
django admin... I'll give it a try tomorrow when my mind is a more
rested.

But meanwhile, I'm curious...

I've followed the instructions in both Bennett' and the djangoproject
docs scrupulously; double-checking my work in both cases. And in both
cases I've failed. It's likely, I'm sure, that my failure is due to a
misreading, misunderstanding, or mistyping on my part. I'm wondering,
however, has anyone else achieved success based on either Bennett's or
djangoproject doc's instructions?

If so, then I'll have to carefully review what I've done.

If not, then there's a chance that either or both of the sources are
either wrong, or are missing something, and should be corrected.

I do recall that I got it working quite easily once in Karrigell.

Thanks again,

Lloyd




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



Re: many-ended relationship retrieval

2008-07-06 Thread Malcolm Tredinnick


On Sun, 2008-07-06 at 22:26 -0400, Michael Hrivnak wrote:
[...]
> The problem is that this is slow, I think because it's executing a new 
> database query for each user.  It's even worse because many objects in my 
> data model have several many-ended relationships.  Using 6 such getters on 
> 1000 users is taking about 8 seconds to return, running on respectable 
> hardware.

Custom SQL is probably your best friend here. The short version is that
Django doesn't do anything with values() or select_related() or anything
that returns many-valued results, even in trunk.

You might be able to cobble together something using in_bulk(),
depending upon how you're using the results, but that doesn't look like
what you want. SQL is the right tool for the job here.

Regards,
Malcolm


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



many-ended relationship retrieval

2008-07-06 Thread Michael Hrivnak
I am using django 0.96.1 mostly for its database API on a large project.  I 
need to retrieve many-ended relationship data.  For example, for every user, 
I need to know what groups they are in.  As expected, there is a many-to-many 
relationship.

The code I've written will get a queryset of users filtered by some arbitrary 
criteria, call the values() method, and then iterate over the results.  For 
each row, it calls a "getter" for the group relationship.  That getter 
receives a parameter current_user_id and does this:

group.objects.filter(user__id__exact = current_user_id).values('id')

It then converts the list of dictionaries into just a list of integers, and 
returns the results.  This way I am augmenting the user.objects.values() 
result set with lists of foreign keys representing the many-end of a 
relationship.  I end up with results looking like this:

[{ 'username' : 'jshmoe', 'first_name' : 'Joe', 'last_name' : 'Shmoe', 'groups' 
: 
[ 3, 5, 6, 14] }]

The problem is that this is slow, I think because it's executing a new 
database query for each user.  It's even worse because many objects in my 
data model have several many-ended relationships.  Using 6 such getters on 
1000 users is taking about 8 seconds to return, running on respectable 
hardware.

Is there an appropriate django way to run only one query to retrieve all of 
these results?  I guess all I really need is the contents of the user_groups 
table, filtered by some collection of user ids.  Then I can do the matching 
myself in code.

Thanks for your help,
Michael


signature.asc
Description: This is a digitally signed message part.


Re: clean_* method for ModelForms?

2008-07-06 Thread Malcolm Tredinnick


On Sun, 2008-07-06 at 13:44 -0700, Rob Hudson wrote:
> So if I understand correctly, you are saying make author a
> not-required field so is_valid() will validate to True.  Then in my
> view do the commit=False on save, check if author is present and if
> not, set the default author, then call save().  Something like that?

That's probably slight overkill, in that you don't need to go as far as
getting back to the view and calling save(commit=False).

You got the cleaning process exactly right the first time. Looks like
the only thing that is going "wrong" (it's going right, actually --
doing exactly what you specified) is that the author field is required
by the model and hence by the ModelForm. Since the field's validation
includes checking "required-ness" and, if that fails, clean_*() isn't
called, you're seeing the problem.

You can set

self.field["author"].required = False

in your form's __init__ method to avoid this.

Regards,
Malcolm



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



Using a Custom Manager for date based generic views??

2008-07-06 Thread Christopher Clarke
Hi Guys
I'm  building a django based system for a company that monitors the  
mutuals funds industry
We have Mutual Funds Companies (Issuer) who have one or more funds  
(Fund) and every month the funds submit a volume report
Here is a simplified version

class Issuer(models.Model):
name=models.CharField(max_length=100,unique=True)
--
--
--

class Fund(models.Model):
 issuer = models.ForeignKey(Issuer)
 symbol = models.CharField(max_length=15,unique=True)
 --
 --

class FundVolumeReport(models.Model):

 fund= models.ForeignKey(Fund)
 period_ending=models.DateField()
  
units_purchased_individuals 
=models.FloatField(verbose_name="Individuals",blank=True,null=True)
  
units_purchased_institutions 
=models.FloatField(verbose_name="Instutions",blank=True,null=True)
 --
 --

Now we need to produce totals for each Issuer by month   i implemented  
a date based generic view using a model (IssuerVolumeAggregates) which  
wrapped a database view which did the aggregation i.e

CREATE OR REPLACE VIEW core_issuervolumeaggregates AS
   select
   trim(to_char(i.id,'999'))|| 
trim(to_char(vd.period_ending_id::int,''))::int as id,
   i.id as issuer_id,
   max(i.name)as name,
   m.dateix as period_ending,
   count(*) as no_funds
   --
--
  from core_fundvolumedata vd,
   core_fund f, core_issuer i, freqdates_monthly m
   where f.id=vd.fund_id and f.issuer_id=i.id
   and m.id=vd.period_ending_id
   group by i.id,vd.period_ending_id,m.dateix
   order by i.id,m.dateix;

This works pretty well but its kind a clunky so i was wondering if i  
could do the same thing with a custom manager

==
class IssuerManaager(models.Manager):

 def with_aggs(self):
 from django.db import connection
 cursor=connection.cursor()
 cursor.execute("""
 select i.id,max(i.name), m.dateix AS period_ending,
 count(*) AS no_funds,
 sum(vd.total_units_issued_outstanding) as  
total_units_issued_outstanding,
 sum(vd.total_unit_holders) as no_unit_holders,
 sum(vd.tt_total_net_assets_under_management) AS  
net_assets_under_management,
 sum(vd.tt_value_redemptions) AS total_redemptions,
 sum(vd.tt_value_sales) AS total_sales
 FROM core_fundvolumedata vd, core_fund f, core_issuer i,  
freqdates_monthly m
 WHERE f.id = vd.fund_id AND f.issuer_id = i.id AND m.id =  
vd.period_ending_id
 GROUP BY i.id, m.dateix, vd.period_ending_id
 ORDER BY i.id, m.dateix;
 """)
 results_list= []
 for each in cursor.fetchall():
 p= self.model(id=each[0],name=each[1])
 p.period_ending=each[2]
 p.no_funds = each[3]
 p.units_issued_outstanding=each[4]
 p.no_unit_holders=each[5]
 p.net_assets_under_management=each[6]
 p.redemptions=each[7]
 p.sales=each[8]
 results_list.append(p)
 return results_list

class Issuer(models.Model):
 name = models.CharField(max_length=100)
   --
   --
   --
 objects = IssuerManaager()

   The manager works but when i try to use it in the generic view

  return archive_month(
  request,
  year=year,
  month=month,
  queryset = Issuer.objects.with_aggs(),
  date_field = 'period_ending',
I get
list' object has no attribute 'model'
Am i on the right track and how do i get this to work??
Thanks for any help
Regards
Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: clean_* method for ModelForms?

2008-07-06 Thread TiNo
You don't have to do the commit=False thing. You can check if author is
present in the clean() method, that will always be called.

On Sun, Jul 6, 2008 at 10:44 PM, Rob Hudson <[EMAIL PROTECTED]> wrote:

>
> So if I understand correctly, you are saying make author a
> not-required field so is_valid() will validate to True.  Then in my
> view do the commit=False on save, check if author is present and if
> not, set the default author, then call save().  Something like that?
>
> On Sun, Jul 6, 2008 at 11:35 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> >
> > Oh, `required=True` of course
> >
> > On Jul 6, 10:31 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> >> Field for `author` created with `required=False`. And `clean` method
> >> doesn't call `clean_author` if `author` data isn't present.
>
> >
>

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



Re: looping through newforms fields in a template

2008-07-06 Thread joshuajonah

Resolved.

A little black magic required:

http://www.zedkep.com/blog/index.php?/archives/85-Iterating-over-a-dictionary-in-Django-templates.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



looping through newforms fields in a template

2008-07-06 Thread joshuajonah

ok, it's actually pretty complicated but I'll give you the specific
issue.

I'm making a dictionary of form fields, views.py:

form = RetailForm()
categories = ['Toys', 'Bird']
checkboxlist = {}

for category in categories:
num = 0
for field in form:
if field.help_text == category:
checkboxlist[category+'%s' % num] = field
num += 1
return render_to_response('RetailForm.html', {'form': form,
'checkdata': checkboxlist})


And then im displaying them on a template, RetailForm.html:

  The dictionary: {{ checkdata }}
  
  
  Dictionary items:
  {% for check in checkdata %}
{{ check }}
  {% endfor %}


Here is the output:

The dictionary: {'Toys0': , 'Toys1': , 'Bird0': }

Dictionary items: Toys0 Toys1 Bird0


The dictionary items are outputting the variable names as strings, but
i would like them to actually output the checkbox input. They are
obviously getting put into the dictionary as objects. Any ideas on how
i can output the value of those variables on the page instead?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: html templates - 'for' cycle without a variable

2008-07-06 Thread Oscar Carlsson
If you only need to repeat a div-tag 20 times, and don't need any data from
any model, you could always do it with javascript.

Oscar

On Fri, Jul 4, 2008 at 6:07 PM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:

>
> Create a 20-elemnt list inside your view and set it as a context
> variable?
>
> On Jul 3, 10:21 am, antony_h <[EMAIL PROTECTED]> wrote:
> > How could I repeat my  20 times?
> > I've found how I can repeat it 5 times:
> > {% for a in 12345|make_list %}
> > 
> > {% endfor %}
> > But it's not so great for e.g. a hundred
> > Usage: my designer wants to test his layout and I don't want to create
> > a custom tag for such a simple task
> >
>

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



Re: clean_* method for ModelForms?

2008-07-06 Thread Rob Hudson

So if I understand correctly, you are saying make author a
not-required field so is_valid() will validate to True.  Then in my
view do the commit=False on save, check if author is present and if
not, set the default author, then call save().  Something like that?

On Sun, Jul 6, 2008 at 11:35 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> Oh, `required=True` of course
>
> On Jul 6, 10:31 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>> Field for `author` created with `required=False`. And `clean` method
>> doesn't call `clean_author` if `author` data isn't present.

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



Re: ImageField error

2008-07-06 Thread Molly

Millan,

I'm doing this in dev environment with the built in webserver. No it's
not a mod_python error.

I'm using the static setup and I can get to it fine when I upload my
photo.
The problem is when I click the photo it seems to be pointing to
somewhere else.

In my models:
==
photo = models.ImageField("Photograph", upload_to='images/uploaded',
blank=True,null=True)
==

if i manually go to /images/uploaded my photo is there, but the link
in the admin site seems to be wrong.

this is the link, it's adding all of the extra information:
==
http://127.0.0.1:8000/admin/base/incident/1/media/images/uploaded/DCP_0326.JPG
==

Thanks a lot for your response. Sorry it took me awhile to respond, I
was out of town for the past few days.

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



Re: Autoupdate field?

2008-07-06 Thread Juanjo Conti

I you want your data to be normalized, telephone_home char(9) should not 
be an attribute of Person.

If mary is a Person you always can do:

mary.family.telephone_home to get her telephone_home.

Juanjo
-- 
mi blog: http://www.juanjoconti.com.ar

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



Autoupdate field?

2008-07-06 Thread Xan

Hi,

I think in family class and person class.

I put in pseudocode:

Class Family
 string name
 telephon-home char(9)
 

Class Person
 string name
 string surname
 telephone-home char(9)
 mobile-phone char(9)

Every Person belongs to a Family.

How can I update Person.telephone-home and automatically updates
Family.telephone-home?

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



Re: Multiple fields without manytomanyfield?

2008-07-06 Thread Xan

Thanks a lot,
Xan.

On Jun 25, 5:49 pm, Joel Bernstein <[EMAIL PROTECTED]> wrote:
> I don't suppose a CommaSeparatedIntegerField would work, would it?
>
> You'd lose some querying options that you'd have with a foreign key
> relationship, but that may not be important to you.
>
> On Jun 25, 10:37 am, Xan <[EMAIL PROTECTED]> wrote:
>
> > sorry models.list(integer, max=unlimited)
>
> > On Jun 25, 5:37 pm, Xan <[EMAIL PROTECTED]> wrote:
>
> > > Yes, I'm looking for that but without defining the ManyToManyField.
> > > Could I wrote something like:
>
> > > > class A(models.Model):
> > > >     integers = models.list(Integer, max=unlimited)
>
> > > Thanks,
>
> > > On Jun 23, 9:10 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
>
> > > > I am a bit confused, are you looking for this:
>
> > > > class IntegerRelation(models.Model):
> > > >     content = models.IntegerField()
>
> > > > class A(models.Model):
> > > >     integers = models.ManyToManyField(IntegerRelation)
>
> > > > -richard
>
> > > > On 6/22/08, Xan <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi,
>
> > > > > Suposing you want a model A with several and indetermined number of
> > > > > integer fields. Is there any possibility of defining A without
> > > > > creating a Integer class and then add ManyToManyField(Integer) in
> > > > > class A?
>
> > > > > Thanks a lot!
> > > > > Xan.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: clean_* method for ModelForms?

2008-07-06 Thread Alex Koshelev

Oh, `required=True` of course

On Jul 6, 10:31 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> Field for `author` created with `required=False`. And `clean` method
> doesn't call `clean_author` if `author` data isn't present.
>
> On Jul 6, 10:14 pm, "Rob Hudson" <[EMAIL PROTECTED]> wrote:
>
> > Is it possible to supply a clean_[fieldname] method to a ModelForm for
> > custom validation rules like you can with a normal Form?  I've got a
> > form with an author column that maps to Django's User class.  I want a
> > default to be set if none is given.  I've tried many ways to
> > accomplish this and haven't found one...
>
> > I don't want to tie it to the model directly as going through
> > different logical paths means slightly different defaults.
>
> > I tried adding a `clean_author` method but that didn't seem to work
> > either.  Simple example (not the actual code):
>
> >     class ClipForm(ModelForm):
> >         class Meta:
> >             model = Clip
> >         def clean_author(self):
> >             if not self.cleaned_data.get('author', None):
> >                 return User.objects.get(pk=1)
>
> > In my view, I have:
>
> >     if request.method == 'POST':
> >         form = ClipForm(data=request.POST)
> >         if form.is_valid():
> >             new_clip = form.save()
> >             # ...
> >         else:
> >             # ...
>
> > My understanding is that the is_valid() method kicks off the
> > Field.clean(), Field.clean_*(), and Form.clean() methods which should
> > call my clean_author method and assign an author if one isn't given.
> > But what happens is that is_valid() returns false with the error that
> > the author field is required.
>
> > Any guidance is appreciated.
>
> > Thanks,
> > Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: clean_* method for ModelForms?

2008-07-06 Thread Alex Koshelev

Field for `author` created with `required=False`. And `clean` method
doesn't call `clean_author` if `author` data isn't present.

On Jul 6, 10:14 pm, "Rob Hudson" <[EMAIL PROTECTED]> wrote:
> Is it possible to supply a clean_[fieldname] method to a ModelForm for
> custom validation rules like you can with a normal Form?  I've got a
> form with an author column that maps to Django's User class.  I want a
> default to be set if none is given.  I've tried many ways to
> accomplish this and haven't found one...
>
> I don't want to tie it to the model directly as going through
> different logical paths means slightly different defaults.
>
> I tried adding a `clean_author` method but that didn't seem to work
> either.  Simple example (not the actual code):
>
>     class ClipForm(ModelForm):
>         class Meta:
>             model = Clip
>         def clean_author(self):
>             if not self.cleaned_data.get('author', None):
>                 return User.objects.get(pk=1)
>
> In my view, I have:
>
>     if request.method == 'POST':
>         form = ClipForm(data=request.POST)
>         if form.is_valid():
>             new_clip = form.save()
>             # ...
>         else:
>             # ...
>
> My understanding is that the is_valid() method kicks off the
> Field.clean(), Field.clean_*(), and Form.clean() methods which should
> call my clean_author method and assign an author if one isn't given.
> But what happens is that is_valid() returns false with the error that
> the author field is required.
>
> Any guidance is appreciated.
>
> Thanks,
> Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: raising HttpResponseBadRequest throws Exception Type error?

2008-07-06 Thread Rob Hudson

On Jul 5, 7:33 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> Having an exception
> for every possible response code is really overkill here, since it means
> you'll be raising status-code-related exceptions instead of more
> semantic ones.

Ah, makes sense.

> > * Shouldn't Django be consistent in its own raising of errors and
> > choose one way to do it (e.g. choose #1 above over #2)?  Out of
> > curiosity I grep'd the code to count how many chose the paren method
> > vs the comma method:
>
> Meh. They're both perfectly valid Python and people should be able to
> read either. It really makes no significant difference at all. I tend to
> use the parenthesised version in my own code (partly because it's easier
> to split across multiple lines), but the other form is just as readable.

Agreed.  Not worth it.

Thanks for the reply Malcolm.  Very informative as always.

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



Re: Storing additional data in ManyToManyField's join table

2008-07-06 Thread Brandon Kelly

On Jul 6, 5:03 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:

> You're looking for ticket #6095. This is scheduled for inclusion in
> v1.0, so it should be in trunk in the near future.

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



Re: Django + tiny_mce

2008-07-06 Thread Chatchai Neanudorn
First thing when you work with Java script is, make sure it is available. In
this case, where is your urls config.

>From these,




Can you start web server and type
http://localhost/usr/share/tinymce/www/tiny_mce.js
and see if it return something rather than 400.

For me, I usually do things like this

Let say I have static folder under project path name "static", under static
I have css, js image.

In settings,
DIR = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(DIR, 'static')

In urls

urlpatterns += patterns('',

(r'^static/(?P.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT,
'show_indexes': True}),
)

I enable show_indexs just in case I want make sure I can see all file via
browser.

After you have it work, you can even grab java script from outside website
or on your media site to improve performance. For example,