Key Erro: 'perms' whenever I try and view a table in Admin

2009-02-10 Thread merric

Help! Completely stuck with this one.  Everytime I try to view any
table in the Admin I get an error.

I am getting a KEY ERROR with exception value of 'perms':

Exception Location: C:\Python25\Lib\site-packages\django-trunk\django
\template\context.py in __getitem__, line 43

Anybody have any ideas what might be causing this?

Cheers

MerMer



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



Issues with IE7 and {% for %} {% endfor %} tag

2008-02-21 Thread merric

I have a template that uses  {% for i in prize %}  {{ i.description }}
{% endfor %}

This iterates fine in Firefox, but in IE7 it keeps coming up blank.
I can't see any html issues.  I am working off my localhost.   Is this
a IE7 security issue or something else I have not thought of?

Cheers

MerMer
--~--~-~--~~~---~--~~
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: Issues with IE7 and {% for %} {% endfor %} tag

2008-02-21 Thread merric

I've commented out all the HTML on the template,  so my template now
reads as follows

{% for i in prizes %}  {{i.id }}  {% endfor %}

There is nothing else on the page except the commented out HTML.

In firefox this displays without any problem, in IE7 I get a blank
page, even when looking at the source HTML.

When I make any other changes to the template, IE7 picks it up,
straight away.  It is only the {% for %} tag that seems to be coming
up blank.
I'm completely baffled.


On Feb 21, 3:37 pm, kevinski <[EMAIL PROTECTED]> wrote:
> > This iterates fine in Firefox, but in IE7 it keeps coming up blank.
> > I can't see any html issues.  I am working off my localhost.   Is this
> > a IE7 security issue or something else I have not thought of?
>
> I had a the similar problem once with IE7. It ended up being due to
> CSS incompatibility that caused the text to be hidden in IE. Try
> loading the page without any markup, if you see the text you will know
> this is the problem.
>
> Kin
--~--~-~--~~~---~--~~
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: Issues with IE7 and {% for %} {% endfor %} tag

2008-02-21 Thread merric

It was a cookie issue.   I had looked over this... but missed it on
first glance.  My apologies


MerMer


On Feb 21, 4:17 pm, merric <[EMAIL PROTECTED]> wrote:
> I've commented out all the HTML on the template,  so my template now
> reads as follows
>
> {% for i in prizes %}  {{i.id }}  {% endfor %}
>
> There is nothing else on the page except the commented out HTML.
>
> In firefox this displays without any problem, in IE7 I get a blank
> page, even when looking at the source HTML.
>
> When I make any other changes to the template, IE7 picks it up,
> straight away.  It is only the {% for %} tag that seems to be coming
> up blank.
> I'm completely baffled.
>
> On Feb 21, 3:37 pm, kevinski <[EMAIL PROTECTED]> wrote:
>
> > > This iterates fine in Firefox, but in IE7 it keeps coming up blank.
> > > I can't see any html issues.  I am working off my localhost.   Is this
> > > a IE7 security issue or something else I have not thought of?
>
> > I had a the similar problem once with IE7. It ended up being due to
> > CSS incompatibility that caused the text to be hidden in IE. Try
> > loading the page without any markup, if you see the text you will know
> > this is the problem.
>
> > Kin
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



cannot set cache keys

2008-03-03 Thread merric

I can't get cache to work inside a view.  Can anybody point out where
I'm going wrong

In my settings file I have the following:-
CACHE_BACKEND = 'locmem:///'

The view is as follows:-

def offers(request):
from django.core.cache import cache
cache_time=60*60*24
cache_name = "offers"
object_list = cache.get(cache_name)
   cache_working=" "
if not object_list:
cache_working="No"
offers=Offer.objects.all()
 object_list={'offers':offers}
 cache.set(cache_name,object_list,cache_time)

offers=object_list['offers']
template_name="offer/offer.html"
return render_to_response(template_name,
{'offers':offers,'cache_working':cache_working})

The variable "cache_working" always returns "NO".

Does this have anything to do with me working via localhost?  My
middleware clasess are as follows (though I can't see why this would
make a difference)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)
--~--~-~--~~~---~--~~
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: cannot set cache keys

2008-03-03 Thread merric

On futher testing I am getting some very weird results.

On occasions the cache key seems to get created, but expires almost
immediately, so the next time through the "cache_working" returns to
"NO".




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



Upgrade to development version - Admin no longer works

2008-03-03 Thread merric

I've just tried updating to the latest development version and the
admin no longer works.   I get the following message whenever I try to
access a DB via the admin:

ViewDoesNotExist at /admin/
Tried help_no_cookies in module promotions.views. Error was: 'module'
object has no attribute 'help_no_cookies'
Request Method: GET
Request URL:http://localhost/admin/
Exception Type: ViewDoesNotExist
Exception Value:Tried help_no_cookies in module promotions.views.
Error was: 'module' object has no attribute 'help_no_cookies'
Exception Location: C:\Python24\lib\site-packages\django\core
\urlresolvers.py in _get_callback, line 184
Python Executable:  C:\Program Files\xampp\xampp\apache\bin\apache.exe
Python Version: 2.4.3
Python Path:['C:/', 'C:/hive', 'C:/hive/promotions', 'C:\\Python24\
\lib\\site-packages\\setuptools-0.6c1-py2.4.egg', 'C:\\WINDOWS\
\system32\\python24.zip', 'C:\\Python24\\Lib', 'C:\\Python24\\DLLs',
'C:\\Python24\\Lib\\lib-tk', 'C:\\Program Files\\xampp\\xampp', 'C:\
\Program Files\\xampp\\xampp\\apache\\bin', 'C:\\Python24', 'C:\
\Python24\\lib\\site-packages', 'C:\\hive\\promotions', 'C:\\hive\
\promotions\\tests', 'C:\\', 'C:\\Python24\\lib\\site-packages\\PIL']

There is no VIEW called "help_no_cookies" in the promotions.views
module.  Should there be?

Cheers

MerMer
--~--~-~--~~~---~--~~
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: Upgrade to development version - Admin no longer works

2008-03-03 Thread merric

Thanks James,  I'll have a look.

On Mar 3, 4:50 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On Mon, Mar 3, 2008 at 10:29 AM, merric <[EMAIL PROTECTED]> wrote:
> >  There is no VIEW called "help_no_cookies" in the promotions.views
> >  module.  Should there be?
>
> You apparently have an old URL pattern somewhere in your project which
> tries to reference such a view; previously this was not an error, but
> now it is (since reverse-URL lookups require that all URL patterns be
> valid and resolve to proper views).
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~-~--~~~---~--~~
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: cannot set cache keys

2008-03-03 Thread merric


The problem seems to be with LOCMEM.

I changed the CACHE_BACKEND setting to a DB and cache worked fine.

In LOCMEM the cache seem to get set OK, but then cannot be retrieved
correctly.  I don't get any error messages, it just doesn't want to
work.   I tried this on two different machines, one running
the latest development version of Django and one running the last
release.  The problem was the same on both.


--~--~-~--~~~---~--~~
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 filter with many to many relationship

2007-09-16 Thread merric

I can't get this to work for me.

For example, I have two records which both share the term 'ThemePark",
one of these records also has the additional term "London".
However,  when I run your suggestion I get an empty query set.

Cheers

On Sep 15, 2:27 am, r_f_d <[EMAIL PROTECTED]> wrote:
> You are missing Q.
>
> try
> from django.db.models import Q (I think that is where it resides but
> cannot verify right now, a quick check of the documentation should
> confirm)
>
> Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact =
> 'term2') & Q(terms__exact = 'term3))
>
> On Sep 14, 6:46 pm, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
> > I have a model "OFFER" that has has many to many relationship with a
> > model  "TERMS".
>
> > Class OFFER:
> >terms=models.ManyToMany(Terms)
>
> > Assuming I have the following value for 3 records in Term
> > term1=2
> > term2=5
> > term3=8
>
> > I want to return ONLY those offers which have ALL three of these terms .
> > I've tried:
>
> > qs=Offer.objects.all().filter(terms=term1).filter(terms=term2).filter(terms=term3)
> > but this doesn't work - I always end up with an empty query set.
>
> > What am I missing?
>
> > Cheers


--~--~-~--~~~---~--~~
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: Odd behavior of filtering

2007-09-16 Thread merric

Does anybody recommend a good workaround - I'm experiencing the same
problem


On Aug 25, 1:57 pm, Djon <[EMAIL PROTECTED]> wrote:
> Is there a ticket for it on the Trac?
> How/where can I monitor it so that as soon as a fix is available I
> could get the changeset?
>
> Thanks!
>
> On Aug 21, 11:45 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Mon, 2007-08-20 at 22:04 +, Djon wrote:
> > > Hi
>
> > > My model is:
>
> > > class Tag(models.Model):
> > > name = models.CharField(maxlength=30)
>
> > > class Snippet(models.Model):
> > > name = models.CharField(maxlength=30)
> > > tags =
> > > models.ManyToManyField(Tag,filter_interface=models.HORIZONTAL)
>
> > > My aim to filter snippets according to multiple tag constraints
> > > simultaneously.
> > > However, the overlap of two sets just doesn't get filtered properly.
> > > E.g.:
>
> > > In [96]: Snippet.objects.filter(tags__name="home")
> > > Out[96]: [, ]
>
> > > In [97]: Snippet.objects.filter(tags__name="email")
> > > Out[97]: [, ]
>
> > > In [98]:
> > > Snippet.objects.filter(tags__name="home").filter(tags__name="email")
> > > # SHOULD return []
> > > Out[98]: []
>
> > > I tried the exact same idea by using .filter(Q(..),Q(..)) and also
> > > with theQ(..)&Q(..) option, as well as by dividing the process into
> > > stages and inspecting the first filter's result on the way (it's
> > > valid). Everything just ends up with the same empty list...
>
> > It's a known bug. The SQL query that is constructed doesn't work with
> > many to many fields. Work in progress.
>
> > Regards,
> > Malcolm
>
> > --
> > If Barbie is so popular, why do you have to buy her 
> > friends?http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 filter with many to many relationship

2007-09-17 Thread merric

I only want records that have both the terms, "ThemePark" AND "London"

The attribute of Terms that contains 'ThemePark' and 'London is simply
'term'

The full model is:

class Terms(models.Model):
term=models.CharField(maxlength=100,core=True,help_text="search
term")
def __unicode__(self):
return self.search_term

class Offer(models.Model):
searchterms=models.ManyToManyField(Terms,blank=True)




On Sep 17, 1:52 am, r_f_d <[EMAIL PROTECTED]> wrote:
> Couple of things so I understand better,
> What is the attribute of term that contains 'ThemePark' and 'London' ?
> What are you trying to end up with, all records with themePark or only
> records with themepark and London ?
> -richard
>
> On Sep 16, 11:36 am, merric <[EMAIL PROTECTED]> wrote:
>
> > I can't get this to work for me.
>
> > For example, I have two records which both share the term 'ThemePark",
> > one of these records also has the additional term "London".
> > However,  when I run your suggestion I get an empty query set.
>
> > Cheers
>
> > On Sep 15, 2:27 am, r_f_d <[EMAIL PROTECTED]> wrote:
>
> > > You are missing Q.
>
> > > try
> > > from django.db.models import Q (I think that is where it resides but
> > > cannot verify right now, a quick check of the documentation should
> > > confirm)
>
> > > Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact =
> > > 'term2') & Q(terms__exact = 'term3))
>
> > > On Sep 14, 6:46 pm, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
> > > > I have a model "OFFER" that has has many to many relationship with a
> > > > model  "TERMS".
>
> > > > Class OFFER:
> > > >terms=models.ManyToMany(Terms)
>
> > > > Assuming I have the following value for 3 records in Term
> > > > term1=2
> > > > term2=5
> > > > term3=8
>
> > > > I want to return ONLY those offers which have ALL three of these terms .
> > > > I've tried:
>
> > > > qs=Offer.objects.all().filter(terms=term1).filter(terms=term2).filter(terms=term3)
> > > > but this doesn't work - I always end up with an empty query set.
>
> > > > What am I missing?
>
> > > > Cheers


--~--~-~--~~~---~--~~
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 filter with many to many relationship

2007-09-17 Thread merric

Still returns an empty query set.   Checking some of the other posts I
think this is a  failing which is particular to ManyToMany
relationships



On Sep 17, 4:33 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> Ok, the query should then be:
>
> Offer.objects.filter(Q(terms__term__exact = 'ThemePark') &
> Q(terms__term__exact = 'London'))
>
> -richard
>
> On 9/17/07, merric <[EMAIL PROTECTED]> wrote:
>
>
>
> > I only want records that have both the terms, "ThemePark" AND "London"
>
> > The attribute of Terms that contains 'ThemePark' and 'London is simply
> > 'term'
>
> > The full model is:
>
> > class Terms(models.Model):
> > term=models.CharField(maxlength=100,core=True,help_text="search
> > term")
> > def __unicode__(self):
> > return self.search_term
>
> > class Offer(models.Model):
> > searchterms=models.ManyToManyField(Terms,blank=True)
>
> > On Sep 17, 1:52 am, r_f_d <[EMAIL PROTECTED]> wrote:
> > > Couple of things so I understand better,
> > > What is the attribute of term that contains 'ThemePark' and 'London' ?
> > > What are you trying to end up with, all records with themePark or only
> > > records with themepark and London ?
> > > -richard
>
> > > On Sep 16, 11:36 am, merric <[EMAIL PROTECTED]> wrote:
>
> > > > I can't get this to work for me.
>
> > > > For example, I have two records which both share the term 'ThemePark",
> > > > one of these records also has the additional term "London".
> > > > However,  when I run your suggestion I get an empty query set.
>
> > > > Cheers
>
> > > > On Sep 15, 2:27 am, r_f_d <[EMAIL PROTECTED]> wrote:
>
> > > > > You are missing Q.
>
> > > > > try
> > > > > from django.db.models import Q (I think that is where it resides but
> > > > > cannot verify right now, a quick check of the documentation should
> > > > > confirm)
>
> > > > > Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact =
> > > > > 'term2') & Q(terms__exact = 'term3))
>
> > > > > On Sep 14, 6:46 pm, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
> > > > > > I have a model "OFFER" that has has many to many relationship with
> > a
> > > > > > model  "TERMS".
>
> > > > > > Class OFFER:
> > > > > >terms=models.ManyToMany(Terms)
>
> > > > > > Assuming I have the following value for 3 records in Term
> > > > > > term1=2
> > > > > > term2=5
> > > > > > term3=8
>
> > > > > > I want to return ONLY those offers which have ALL three of these
> > terms .
> > > > > > I've tried:
>
> > > > > > qs=Offer.objects.all
> > ().filter(terms=term1).filter(terms=term2).filter(terms=term3)
> > > > > > but this doesn't work - I always end up with an empty query set.
>
> > > > > > What am I missing?
>
> > > > > > Cheers


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



HttpResponseRedirect and IE6

2007-06-19 Thread Merric Mercer

I am having real problems with IE6 and HttpResponseRedirect,  IE keeps 
showing a blank page, while Firefox works absolutely fine.

Has anybody else come across this issue ?

Thanks

MerMer

--~--~-~--~~~---~--~~
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: Hypothetical: Customizable Member Pages

2007-06-21 Thread Merric Mercer

We've taken the approach using cookies.   The value of the cookies is 
returned to the template via a simple context processor.  Each
cookie then simply refers to a stylesheet,  which can change the whole 
look and feel of the site.  Very straightforward.

MerMer

James Bennett wrote:
> On 6/20/07, Bryan Veloso <[EMAIL PROTECTED]> wrote:
>   
>> This feature is a show-stopper, since the market I'll be gearing this
>> to almost requires features like this to be there.  So am I dreaming
>> that this can be done? Has anybody else attempted something like this
>> yet?
>> 
>
> It should be relatively easy; look at Chapter 12 of the Django book,
> which covers extending the auth system with a custom profile model.
> You'll want to develop a model which includes the ability for users to
> specify whatever styles/customizations are needed (along with any
> other information you want to collect), and use that as the profile
> model. Then the 'get_profile()' method on each User will return the
> appropriate object which you can look at to determine how to display
> the user's customized page.
>
>   

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



One-to-one - can't seem to be able to update Model

2007-06-21 Thread Merric Mercer


I have a model called REWARD, which has a one-to-one relationship with a 
model called PROMOTION

I seem to be able to access the attributes of REWARD via PROMOTIONS but 
I can't seem to update them.

promo=Promotion.objects.get(id=10)
promo.reward.user_visits
 >> 10L  

However:-
promo.reward.user_visits=12   #  This does not work.
promo.reward.user_visits
 >> 10L


What am I missing? I was sure that this was working in a previous 
incarnation, but not any more. Has something changed?

MerMer

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



Render_to_response and varying the headers

2007-07-01 Thread Merric Mercer

I want to change the Cache-Control on the HTTP header.  Can anybody 
advise how I do this.  Currently my view returns
a render_to_response like so:-

return render_to_response(template_name,{'code': code 
},context_instance=RequestContext(request))

Thanks

MerMer

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



Debugging production site.

2007-08-13 Thread Merric Mercer

I'm very occasionally getting errors reported to me on our production 
site by our members.   However,  we cannot replicate the problem ourself 
and because debugging is turned off the members are not giving me any 
real clues.

Is there anyway to trap the debug information - so it is logged - but 
not visible to users?

Many thanks

MerMer

--~--~-~--~~~---~--~~
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: Debugging production site.

2007-08-14 Thread Merric Mercer

Just what I was looking for - many thanks

MerMer

Matt McClanahan wrote:
> On Aug 13, 2:11 pm, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
>   
>> Is there anyway to trap the debug information - so it is logged - but
>> not visible to users?
>> 
>
> A good starting point is to use the ADMINS setting, which will give
> you a way to receive error reports via e-mail when debugging is off:
>
> http://www.djangoproject.com/documentation/settings/#admins
>
> Matt
>
>
> >
>
>   


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



Unicode Type Error when adding M2M field

2007-09-05 Thread Merric Mercer





I have the following model:-

class Rank_Advert(models.Model):
    advert = models.ForeignKey(Advert)
    brand = models.ForeignKey(Brand,verbose_name="brand_owner")
    rank= models.IntegerField(default=1,blank=True)
    def __unicode__(self):
    return self.advert
    class Admin:
    save_on_top=True
    list_display=('advert','brand','rank')

Whenever, I try to save a new record to this model I am getting the
following error:-


  

  Request Method:
  POST


  Request URL:
  http://localhost/admin/promotions/rank_advert/add/


  Exception Type:
  TypeError


  Exception Value:
  coercing to Unicode: need string or buffer, Advert found


  Exception Location:
  C:\Python24\lib\site-packages\django\utils\encoding.py in
force_unicode, line 37

  


Can anybody explain what's happening.  I've run out of ideas. 

Cheers

MerMer


--~--~-~--~~~---~--~~
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: iteration of query set appears to fail when running function directly from interpretor

2007-02-15 Thread Merric Mercer

Benedict,

Unfortunately, that is just a typo in my post and not the answer. The 
actual code has 'for i in qset'.

The code runs without displaying any errors.  But when I check the 
"UserPointTypeAggregate" database the field has
only been updated from the first record of the PointTransaction query set.

MerMer




Benedict Verheyen wrote:
> Merric Mercer schreef:
>   
>> Help!  I have a function that is  provided below.   When I try the 
>> individual lines of the function  through the interpretor (Ipython) 
>> everything works as expected.  For example:-
>>
>>  >> qset=PointTransaction.objects.filter etc   this works fine!! 
>>
>> However, when I try to run the function as a whole: Example:-
>>
>>  >> admin_sync_agg(user_id=1,points_type=1)  >>
>>
>> This runs but it seems that is is not iterating through the query set, 
>> so only the first record of qset is getting added to the balance.
>>
>> Can anybody advise..  it's completely baffling me.  Thanks
>>
>> MerMer
>>
>>
>> def admin_sync_agg (user_id,points_type):
>> 
>> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
>> credit=0
>> debit=0
>> for i in qs:
>> credit = credit + i.credit
>> debit = credit + i.debit
>> balance= credit-debit
>> 
>> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
>> pa.total_points=balance
>> pa.save()
>> 
>
> You are iterating over qs instead of qset.
>
> def admin_sync_agg (user_id,points_type):
> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
> credit=0
> debit=0
> for i in qset:
> credit = credit + i.credit
> debit = credit + i.debit
> balance= credit-debit
> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
> pa.total_points=balance
> pa.save(
>
> (indentation of qset & pa line screwed up using Thunderbird)
>
> Regards,
> Benedict
>
>
> >
>
>
>   


--~--~-~--~~~---~--~~
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: iteration of query set appears to fail when running function directly from interpretor

2007-02-15 Thread Merric Mercer

Apologies, for wasting time the problem was with the line.  Couldn't see 
the wood for the trees!

 debit = credit + i.debit

should read

debit = debit + i.debit


MerMer




Benedict Verheyen wrote:
> Merric Mercer schreef:
>   
>> Benedict,
>>
>> Unfortunately, that is just a typo in my post and not the answer. The 
>> actual code has 'for i in qset'.
>>
>> The code runs without displaying any errors.  But when I check the 
>> "UserPointTypeAggregate" database the field has
>> only been updated from the first record of the PointTransaction query set.
>>
>> MerMer
>>
>> 
>
> The way your function is designed, it will only update 1 record:
> you iterate PointTransaction to calculate balance.
> Then you use a get on UserPointTypeAggregate which will give you
> 1 or no objects.
> Then you assign the balance value and save it.
>
>
> If you are running on the development server, you can use print
> statements to check you code.
> If you're on production, you can use the logging package to achieve
> printing debugging messages in a file.
>
> Regards,
> Benedict
>
>   
>> Benedict Verheyen wrote:
>> 
>>> Merric Mercer schreef:
>>>   
>>>   
>>>> Help!  I have a function that is  provided below.   When I try the 
>>>> individual lines of the function  through the interpretor (Ipython) 
>>>> everything works as expected.  For example:-
>>>>
>>>>  >> qset=PointTransaction.objects.filter etc   this works fine!! 
>>>>
>>>> However, when I try to run the function as a whole: Example:-
>>>>
>>>>  >> admin_sync_agg(user_id=1,points_type=1)  >>
>>>>
>>>> This runs but it seems that is is not iterating through the query set, 
>>>> so only the first record of qset is getting added to the balance.
>>>>
>>>> Can anybody advise..  it's completely baffling me.  Thanks
>>>>
>>>> MerMer
>>>>
>>>>
>>>> def admin_sync_agg (user_id,points_type):
>>>> 
>>>> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
>>>> credit=0
>>>> debit=0
>>>> for i in qs:
>>>> credit = credit + i.credit
>>>> debit = credit + i.debit
>>>> balance= credit-debit
>>>> 
>>>> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
>>>> pa.total_points=balance
>>>> pa.save()
>>>> 
>>>> 
>>> You are iterating over qs instead of qset.
>>>
>>> def admin_sync_agg (user_id,points_type):
>>> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
>>> credit=0
>>> debit=0
>>> for i in qset:
>>> credit = credit + i.credit
>>> debit = credit + i.debit
>>> balance= credit-debit
>>> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
>>> pa.total_points=balance
>>> pa.save(
>>>
>>> (indentation of qset & pa line screwed up using Thunderbird)
>>>
>>> Regards,
>>> Benedict
>>>
>>>
>>>
>>>   
>>>   
>> 
>
>
> >
>
>
>   


--~--~-~--~~~---~--~~
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: Newbie Question: If statement in templates help

2007-02-25 Thread Merric Mercer

I may be wrong but I believe that the you cannot use the  If statement 
inside a template to evaluate a  specific value.  You use it to 
determine whether the object or value exists ( has been returned by the 
view).

I think that this is because the developers wanted to maintain a 
distinction between the presentation and the logic.  

I seem to remember that someone has written some code, as a patch, to 
allow the IF statement to evaluate specific values, but cannot remember 
where the code is.

MerMer


>
> Registered Players
> 
> {% for player in object.player_set.all %}
> {{ player.forename }}  {{ player.surname }}
> ({{ player.age }})
> {% endfor %}
> {% if object.player_set.all == "" %}
> No players currently registered
> {% endif %}
> 
>
>
> Request Method: GET
> Request URL:http://duncanm.webfactional.com/teams/1/
> Exception Type: TemplateSyntaxError
> Exception Value:'if' statement improperly formatted
> Exception Location: /home2/duncanm/lib/python2.4/django/template/
> defaulttags.py in do_if, line 608
>
> I know this is a very stupid question but from my code above I get
> that error (also above).  What is the correct way of using an if
> statement to display some text if object.player_set.all is empty??
>
> Thanks
>
>
> >
> >
> 
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.1.410 / Virus Database: 268.16.11/627 - Release Date: 
> 15/01/2007
>
> 
>


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



Template Tags

2007-03-08 Thread Merric Mercer

I have a template that loops through a simple query set and displays the 
data in a table.

I now need to add another column to my table.  However,  the data in the 
new column is a calculation based on two of the other fields
in that record.   

I presume that this can be done using a template tag, but I can't work 
out how it can be done.  I can't see how I can pass the values of the 
other fields into
a tag.  Can anybody please advise the best way to do this.

MerMer

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



Designing for Speed - conditionals inside the view versus the template

2007-03-12 Thread Merric Mercer

I have  view that returns a whole bunch of different variables and 
boolean flags.The state of these flags determine what the user 
actually sees on their screen.

 From a design perspective I seem to have two options:-


1.   Design a template with lots of {% if %} conditional statements to 
check the status of various flags, in order to display the appropriate 
information to the user.

OR

2.   Do the bulk of the work in the view,  by doing something like:-
  if  conditions A:
 template = "template_a.html"
  elif conditions B:
 template = "template_b.html"
  else conditions C:
 template = "template_c.html"

 return render to response(template name,{dictionary_of_variables},)


3.  Do a combination of the two above

Option number 2 lacks the flexibility of doing stuff in the template, 
but would it make a big difference in speed?  I am concerned that having 
a lot of conditional statements in the template might be slower than 
doing the work in the view.

Can anybody shed some light on this and the trade off (if any) of speed 
versus flexibility.

MerMer


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



Changing the database - attribute errors

2007-03-20 Thread Merric Mercer

When I want to add a new field to a database, with existing data, I 
normally don't have a problem as long as I follow these steps.

1.  Alter the django model.
2.  Manually adjust the database table ( mySQL)
3.  Run syncdb

However,  I used these steps this morning and it has not worked. The new 
fields are working fine in the Admin but I cannot access them 
elsewhere.  When I try to access them via the shell they are not 
recognized as attributes.   I've checked and double checked the 
settings, but nothing seems to help. 

What makes this even stranger is my colleague, working on a replica 
model, has created the extra fields without any problem. 

This has got me completely stumped.  Any ideas appreciated!

MerMer


--~--~-~--~~~---~--~~
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: Changing the database - attribute errors

2007-03-20 Thread Merric Mercer

Another observation after more investigation.

I decided to do the following:-

1. Drop the table (again) from the DB.
2. Alter the Model in Django.  This time I deleted one of the original 
fields named "rrp".

Then:-

1.  I re-ran syncdb.  This confirmed  the creating of a new table in the db
2.  I checked  the db and the admin - again both of these showed up 
correctly with all the fields  from my Model.
3.  In the shell I then tried to run a query set on the table.   I got 
the following error

" OperationError: (1054, "unknown column 'promotions_product.rrp' in 
field list)"

This was the field that I deleted from the model.

This is making me conclude that django is using two versions of the 
information in my Models.  The updated version is being used to 
correctly update the database and the admin - but the older version is 
being used to run the query sets. 

MerMer

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



limit_choice_to option for related Model

2007-03-27 Thread Merric Mercer


Can somebody provide some guidance for how to use limit_choices in a 
Model.   I am trying to
only display the records in the related field that contain 4.

I've tried a number of ways but keep getting a syntax error.

MerMer

promotion=models.OneToOneField(Promotion limit_choices_to={ 
'promo_type':4})

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 Order-by with dynamic attribute

2007-03-28 Thread Merric Mercer

I am currently creating a query set of a Model.  I'm then iterating 
through the query set to create a calculation called "total". 
At the end of each loop I am adding "total" to the query set.  Example:-

qs= Cash.objects.all()
for i in qs:
   # calculate total
   i.total = total

Note:  The Cash object has no data field called "total".   I don't want 
to save this to the database because it is different for each user, so 
its created dynamically
for each view.

So far so good.  This works very well and allows me to iterate over the 
query set and the dynamically created attribute "total" in the template.

However,  I would now like to sort the qs using "total.".  Since there 
is no record in the DB I'm guessing that order_by will not work.   Can 
anybody advise on a way.

Thanks

MerMer

 

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



Django scaling and Database replication

2007-04-08 Thread Merric Mercer

The django book's chapter on deployment mentions  the use of Database 
replication as a means to scale using MySQL.

My understanding with Database replication is it uses  a MASTER DB and a 
number of SLAVES.
The master updates the slaves, asynchronously.  This means that the 
slaves are used for reading data only and only the master is used for 
writing data.
As the number of reads typically exceed the number of writes replication 
is supposed to work well.

However, I can't figure out how Django handles it.  I can't see anything 
in the documentation or the settings that would allow writes to be 
handled by a different host to the reads.

Is there a way to do this? 

MerMer


--~--~-~--~~~---~--~~
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 scaling and Database replication

2007-04-09 Thread Merric Mercer

Thank Kemuri,

MySQL cluster seems very cool, but I'm not sure it is the best solution 
if the DB is split over different networks . Latency might be an issue 
with the synchronous setup that MySQL cluster provides.

Having looked at it a bit further since my post I am considering 
"circular replication" with a master on each  network and slaves under 
each master (based on what Julio mentioned).   Using this type of setup 
I am hoping to test out Amazon's EC2 as a way to scale Django apps.

There's an interest article on setting up circular replication at 
http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html

MerMer

kemuri wrote:
> hey Merric,
>
> On Apr 9, 4:10 am, Merric Mercer <[EMAIL PROTECTED]> wrote:
>   
>> The django book's chapter on deployment mentions  the use of Database
>> replication as a means to scale using MySQL.
>>
>> 
>
> If you want to try something cool, try MySQL Cluster, and better 5.1
> since it has disk-based support instead of only in-memory. You will
> need to do some modifications to the CREATE TABLE if you want to go
> that way, but well..
>
> Basically if comes to this that you have 2 data nodes which store data
> and in the MySQL servers you have tables using the NDB engine. This
> means that you can add like 40 MySQL servers all using the same data,
> at the same time.
>
> Anyway, this is a bit advanced MySQL.. And it's not really a Django
> matter indeed.
>
> Best regards,
>
> Geert
>
>
> >
>
>
>   


--~--~-~--~~~---~--~~
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 scaling and Database replication

2007-04-09 Thread Merric Mercer

Julio,

In this scenario am I right in thinking that in MySQL the Master 
automatically acts as a load balancer and that  I therefore don't need 
any other software
to automatically delegate reads between slaves and MySQL knows to send 
all writes to the Master?

I'm slightly confused,  I've been reading an article at on Scaling MySQL 
with replication at  http://docs.hp.com/en/5991-7432/ar01s05.html - to 
quote:-

"There should be two data sources configured in any application that is 
accessing the replicated database. One is the LVS, which acts as a load 
balancer for any read queries to the slave servers, and the other is the 
master server for any write queries.

Why would you need LVS to balance the load between the slaves if this is 
already handled by the Master?

MerMer

>   Yes, there's a way, but it's not in Django that you do this, but on
> the database. You don't need to configured Django (or any application
> accessing the database) to "talk" to slave hosts. It's the job of the
> database server software to abstract this step for you.
>
>   You're going to setup slaves to a master host, and in most cases,
> the former will be used for SELECT and the latter to I/U/D.
>
>   What happens is something like this: Master M and slaves S1 and S2
> are configured. Application asks M for row id 15. M sends query to S1.
> S1 answers to M who answers to application. Application asks for row
> id 20. M sends to the next slave, S2, and so on. As new queries keep
> coming, so M keeps rotating between its slaves.
>
>   


--~--~-~--~~~---~--~~
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 scaling and Database replication

2007-04-09 Thread Merric Mercer

The official documentation on MySQL 5.1  "Using Replication for 
ScaleOut" is explicit and states that it is the application (Django) 
that needs to send the writes to the Master and the Reads to the 
Slaves.Unless I'm wrong this would rule out using replication with 
Django.  

The quote from the MySQL document is below.  According to quote changing 
Django to handle replication should be relatively trivial (but beyond my 
skill set at present),  - does anybody know whether any work has been 
done on this?

MerMer

"If the part of your code that is responsible for database access has 
been properly abstracted/modularized, converting it to run with a 
replicated setup should be very smooth and easy. Change the 
implementation of your database access to send all writes to the master, 
and to send reads to either the master or a slave. If your code does not 
have this level of abstraction, setting up a replicated system gives you 
the opportunity and motivation to clean it up. Start by creating a 
wrapper library or module that implements the following functions:

*

  |safe_writer_connect()|

*

  |safe_reader_connect()|

*

  |safe_reader_statement()|

*

  |safe_writer_statement()|

|safe_| in each function name means that the function takes care of 
handling all error conditions. You can use different names for the 
functions. The important thing is to have a unified interface for 
connecting for reads, connecting for writes, doing a read, and doing a 
write."



Julio Nobrega wrote:
>   Yes, there's a way, but it's not in Django that you do this, but on
> the database. You don't need to configured Django (or any application
> accessing the database) to "talk" to slave hosts. It's the job of the
> database server software to abstract this step for you.
>
>   You're going to setup slaves to a master host, and in most cases,
> the former will be used for SELECT and the latter to I/U/D.
>
>   What happens is something like this: Master M and slaves S1 and S2
> are configured. Application asks M for row id 15. M sends query to S1.
> S1 answers to M who answers to application. Application asks for row
> id 20. M sends to the next slave, S2, and so on. As new queries keep
> coming, so M keeps rotating between its slaves.
>
> On 4/8/07, Merric Mercer <[EMAIL PROTECTED]> wrote:
>   
>> The django book's chapter on deployment mentions  the use of Database
>> replication as a means to scale using MySQL.
>>
>> My understanding with Database replication is it uses  a MASTER DB and a
>> number of SLAVES.
>> The master updates the slaves, asynchronously.  This means that the
>> slaves are used for reading data only and only the master is used for
>> writing data.
>> As the number of reads typically exceed the number of writes replication
>> is supposed to work well.
>>
>> However, I can't figure out how Django handles it.  I can't see anything
>> in the documentation or the settings that would allow writes to be
>> handled by a different host to the reads.
>>
>> Is there a way to do this?
>>
>> MerMer
>>
>>
>> 
>
>
>   


--~--~-~--~~~---~--~~
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 scaling and Database replication

2007-04-09 Thread Merric Mercer

James,

The issue with Cluster is that it is designed to work synchronously. 
This is fine when the all the DB is on a fast, local network but not 
when the DB needs to be replicated to geographically different networks, 
where latency becomes a major issue. 

Django already cares and knows about the DB it uses - so I not sure I 
agree that this can be abstracted out of Django and  I can see a bunch 
of reasons why Django needs to know more about the DB for large scale 
projects.

1. Replication with MySQL
2. Using multiple databases
3. Partitioning tables across multiple servers.

James Bennett wrote:
> On 4/9/07, Merric Mercer <[EMAIL PROTECTED]> wrote:
>   
>> The official documentation on MySQL 5.1  "Using Replication for
>> ScaleOut" is explicit and states that it is the application (Django)
>> that needs to send the writes to the Master and the Reads to the
>> Slaves.Unless I'm wrong this would rule out using replication with
>> Django.
>> 
>
> If you're using MySQL, you want MySQL Cluster, which distributes the
> data over "data nodes" in a cluster and controls access through a "SQL
> node".
>
> Failing that, you want a dedicated connection-pooling utility between
> the application and database layers which can route queries
> appropriately; this is not logic that belongs in the application
> layer, because the application should not need to know or care how
> many databases are actually behind it.
>
>   


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



Testing Framework and Fixtures

2007-04-11 Thread Merric Mercer

Being a relative newbie I don't really understand how to create a 
fixture for the testing framework.  Could someone provide an example of  
the format of a
fixture ?

I tried to run the dumpdata command because I'd read that this did much 
of the work for me but I received the following error message

 >>C:\>manage.py dumpdata promotions
Unable to serialize database: Table_Code matching query does not exist.
None

My models have several 1:1 relationships and I think I remember seeing 
something about this causing a problem in the test framework - but I 
can't relocate the post that mentioned this.   Does anybody know the 
status on this?

MerMer


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



json and django - couple of questions.

2007-04-17 Thread Merric Mercer

First Question:-

In my view  if I do:-

qs=Model.objects.all()
for i in qs:
  setattr( i, "firstname", firstname )  # add a new attribute 
("firstname") with correponding value

import django.core serializers
data=serializers.serialize('json',data)
render_to_response(template,{'data':data,'qs':qs,})

Via 'qs I can access the attribute and  its value.  However, 'data' does 
not provide this extra attributes and value.  Can anybody explain this - 
is there a way I can do this?

Second Question.
Using json or xml is there a simple to only return the fields that I 
need in a query set, rather than all the data?

MerMer


--~--~-~--~~~---~--~~
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: json and django - couple of questions.

2007-04-17 Thread Merric Mercer

The above should read

data=serializers.serialize('json',qs)

If I do qs[0].firstname  I get the value of firstname, but this doesn't seem to 
be bundled in 'data'

MerMer


Merric Mercer wrote:
> First Question:-
>
> In my view  if I do:-
>
> qs=Model.objects.all()
> for i in qs:
>   setattr( i, "firstname", firstname )  # add a new attribute 
> ("firstname") with correponding value
>
> import django.core serializers
> data=serializers.serialize('json',data)
> render_to_response(template,{'data':data,'qs':qs,})
>
> Via 'qs I can access the attribute and  its value.  However, 'data' does 
> not provide this extra attributes and value.  Can anybody explain this - 
> is there a way I can do this?
>
> Second Question.
> Using json or xml is there a simple to only return the fields that I 
> need in a query set, rather than all the data?
>
> MerMer
>
>
> >
>
>
>   


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



puzzeled by possible inconsistency in queery set.

2007-04-18 Thread Merric Mercer

I'm getting, what seems to me, an inconsistency.
Here's a simplified example:


 >>qs=Mymodel.objects.all()
 >>for i in qs:
 setattr(i,"firstname","merric")

This  works on:-

 >>qs[0].firstname
 >>merric

It also works in the template:-

{% for i in qs %} {{ i.firstname }}  {% endfor %}

so I don't understand why this doesn't seem to work after I've set the 
new attribute:-

 >> for i in qs:
   print i.name
 >> Attribute Error 'QuerySet' object has no attribute 'merric'.

Am I doing something fundamentally wrong?   If not this seems rather 
inconsistent.   If I can iterate through an altered QuerySet in my 
template why can't I do
so in the code?

My problem is this:-

I have a query set that I need to filter, but only after I've done a 
bunch of dynamic calculations on other related data.  Is there an easy 
way to alter the query set dynamically and effectively?

Thanks

MerMer

--~--~-~--~~~---~--~~
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: puzzeled by possible inconsistency in queery set.

2007-04-18 Thread Merric Mercer

The line of my previous post
" print i.name" should read "print i.firstname

This is just a correction to my post, not to my problem! Thanks

MerMer



Merric Mercer wrote:
> I'm getting, what seems to me, an inconsistency.
> Here's a simplified example:
>
>
>  >>qs=Mymodel.objects.all()
>  >>for i in qs:
>  setattr(i,"firstname","merric")
>
> This  works on:-
>
>  >>qs[0].firstname
>  >>merric
>
> It also works in the template:-
>
> {% for i in qs %} {{ i.firstname }}  {% endfor %}
>
> so I don't understand why this doesn't seem to work after I've set the 
> new attribute:-
>
>  >> for i in qs:
>print i.name
>  >> Attribute Error 'QuerySet' object has no attribute 'merric'.
>
> Am I doing something fundamentally wrong?   If not this seems rather 
> inconsistent.   If I can iterate through an altered QuerySet in my 
> template why can't I do
> so in the code?
>
> My problem is this:-
>
> I have a query set that I need to filter, but only after I've done a 
> bunch of dynamic calculations on other related data.  Is there an easy 
> way to alter the query set dynamically and effectively?
>
> Thanks
>
> MerMer
>
> >
>
>
>   


--~--~-~--~~~---~--~~
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 to Many - struggling with the syntax.

2007-04-18 Thread Merric Mercer

I'm have the following three Models.

1.Category Model

2. Promotion Model
- Has a many to many relationship with Category.
-  Is the Parent of the Cash Model.

3.Cash Model
  - Has one to one relationship with Promotion.


I want to create a query set of  Cash Objects, filtered by a specific 
Category.id

I'm sure that there must be simple solution - but having looked through 
the forums I just can't figure how to do it.

Can anybody please advise.

MerMer


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



Pagination causing mySQL error

2007-05-04 Thread Merric Mercer

I have a template that has 3 non-contiguous areas.   I need to display 
the results of a query set across these three areas.
My initial solution was to split up the query set in the template using 
"slice". For example:

{% for object in object_list|slice:"1:6" %}area one {% endfor %}
{% for object in object_list|slice:"6:9" %}area two {% endfor %}
etc

My problem is that this is not working with pagination correctly when 
the pagination returns less than the initial slice ( in this case 6).  I 
get the following errors (see below).

Can anybody suggest how to avoid this? Many thanks

MerMer



Caught an exception while rendering.{% for object in 
object_listslice:"3:6" %}
Exception Type: ProgrammingError
Exception Value: (1064, "You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right 
syntax to use near '-1' at line 1")
Exception Location: C:\Python24\Lib\site-packages\MySQLdb\connections.py 
in defaulterrorhandler, line 35

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



django and Dreamweaver CS3

2007-05-22 Thread Merric Mercer

Does anybody know if it is possible to set up Dreamweaver CS3 to edit 
web pages, dynamically created by Django.Dreamweaver works with PHP 
and various other scripting tags - anybody have any experience with it 
and Django?

MerMer

--~--~-~--~~~---~--~~
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 filter with many to many relationship

2007-09-14 Thread Merric Mercer

I have a model "OFFER" that has has many to many relationship with a 
model  "TERMS".  

Class OFFER:
   terms=models.ManyToMany(Terms)


Assuming I have the following value for 3 records in Term
term1=2
term2=5
term3=8

I want to return ONLY those offers which have ALL three of these terms . 
I've tried:

qs=Offer.objects.all().filter(terms=term1).filter(terms=term2).filter(terms=term3)
but this doesn't work - I always end up with an empty query set.

What am I missing?

Cheers



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



Specifiying content-type for JSON

2007-12-16 Thread Merric Mercer

I've have a VIEW, which can return either a JSON file or an html template.

Does anybody know how I can use javascript, so the browser can determine 
whether the response is either JSON or html text?

I presume that there is something in javascript that can determine the 
content-type of the response,  but I struggling to find out what it is.

One final question  - is there any other reason to tell the browser that 
the response is of "application/json"  content-type -  does it make the 
browser quicker or something?

Cheers



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



Major Concern - Edit Inline is Deleting ALL the records when I try to save ONE record.

2006-10-27 Thread Merric Mercer

I'm having a problem which is causing me real concern.

When I try to save a new record to a table, via the Admin (editing 
inline),  ALL of the records within that table are being deleted!

Here's a brief description of what I have:-

class A  # This is a user profile table that extends USER
OneToOneKey(USER)

class B
ManyToManyKey(Table D)

class  C
ForeignKey(Table A, edit_inline)
ForeignKey(Table B)
class Admin
   pass

I can add records without any problem to Table C using the list for 
Table C.   I've also confirmed this by checking the database (mySQL) 
However, when I try to add/modify records to Table C, via Table A then 
ALL of the records for Table C get deleted.
I don't get any error messages.

MerMer

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



Re: Major Concern - Edit Inline is Deleting ALL the records when I try to save ONE record.

2006-10-27 Thread Merric Mercer

An amendment to the below.  Editing inline (via Table A) is deleting ALL 
of the records in Table C that belong to the related  profile in table 
A. It is not deleting every record in the DB.

Also, apologies for having hijacked the original subject.  I'm not sure 
how that happened.  My posts via the web are not appearing on the board, 
so I tried to
email directly.

MerMer



Merric Mercer wrote:
> I'm having a problem which is causing me real concern.
>
> When I try to save a new record to a table, via the Admin (editing 
> inline),  ALL of the records within that table are being deleted!
>
> Here's a brief description of what I have:-
>
> class A  # This is a user profile table that extends USER
> OneToOneKey(USER)
>
> class B
> ManyToManyKey(Table D)
>
> class  C
> ForeignKey(Table A, edit_inline)
> ForeignKey(Table B)
> class Admin
>pass
>
> I can add records without any problem to Table C using the list for 
> Table C.   I've also confirmed this by checking the database (mySQL) 
> However, when I try to add/modify records to Table C, via Table A then 
> ALL of the records for Table C get deleted.
> I don't get any error messages.
>
> MerMer
>
> >
>
>
>   


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



Re: Major Concern - Edit Inline is Deleting ALL the records when I try to save ONE record.

2006-10-27 Thread Merric Mercer

Patrick,

Many thanks - you put me on the right path.

I had the core=true in the Foreign Key like so:-

class  C
ForeignKey(Table A, core=true, edit_inline)
I didn't have core=true on any other fields.

So I tried it on another field at this cured the problem. I presume that by 
placing core=True only in the Foreign Key field it was the same effect as 
having none at all.  In which case it had the following effect as per the 
documentation:-

"If the core fields in an in-line edited object are cleared, the object will be 
deleted".

This looks like what has happened.  However, it raises a couple of things:-

1)  The documentation perhaps could be explicit on this.

2)  At the moment the object is deleted when you click on the save button, 
without explanation or any error message, which surely can't be right.  








patrickk wrote:
> can you give the exact model-definition?
> where is "core=True"?
>
> patrick
>
> Am 27.10.2006 um 14:15 schrieb Merric Mercer:
>
>   
>> I'm having a problem which is causing me real concern.
>>
>> When I try to save a new record to a table, via the Admin (editing
>> inline),  ALL of the records within that table are being deleted!
>>
>> Here's a brief description of what I have:-
>>
>> class A  # This is a user profile table that extends USER
>> OneToOneKey(USER)
>>
>> class B
>> ManyToManyKey(Table D)
>>
>> class  C
>> ForeignKey(Table A, edit_inline)
>> ForeignKey(Table B)
>> class Admin
>>pass
>>
>> I can add records without any problem to Table C using the list for
>> Table C.   I've also confirmed this by checking the database (mySQL)
>> However, when I try to add/modify records to Table C, via Table A then
>> ALL of the records for Table C get deleted.
>> I don't get any error messages.
>>
>> MerMer
>>
>> 
>
>
> >
>
>
>   


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



Re: Logout method returning "maximum recursion depth exceeded" - Help!

2006-10-27 Thread Merric Mercer

Thanks for all your points.  I'm having real problems with Google 
groups.  I figured out what was wrong - but was not able to post in.  
Now, these posts are obviously coming in - 24 late.

MerMer
>
> Karen
>
> p.s. Is google groups acting up?  I just got a bunch of old mails 
> (like this one), and my first attempt to post this via the groups 
> page gave me an "oops, we're sorry, can't do, please try again later" 
> kind of message?  (Gah, as did my 2ndI'll try again with real mail...)
>
> At 06:24 AM 10/26/2006, you wrote:
>
>   
>> I am trying to get the Logout Method to work, but I keep
>> getting"Exception Value:maximum recursion depth exceeded!".
>>
>> The view is very straightforward, so I can't understand where I'm going
>> wrong.
>>
>> 
> >from django.contrib.auth import logout, authenticate, login
>   
>> def logout(request):
>> logout(request)  # debug shows it fails on this line
>> return render_to_response('promotions.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
-~--~~~~--~~--~--~---



Re: Template Tag - Using Sessions versus Direct DB access - pros and cons

2006-10-27 Thread Merric Mercer

Many thanks Don.  I figured it out, but because of issues with google 
have had problems posting back.

It turns out that I don't even have to use get_profile.  Something like 
{{ user.userprofile.postcode }} works fine, where userprofile is the 
name of the one-to-one class.

MerMer


> On Oct 26, 2006, at 6:12 AM, MerMer wrote:
>   
>> 1)  I am able to add fields from the User class directly to a  
>> template.
>> e.g. {{ user.email }}. However, I can't see a way to add the extra
>> fields from the UserProfile class directly to the template, even  
>> though
>> it has a one-to-one relationship with User.  Have I missed something
>> here?
>> 
>
>
>
> Did you set the AUTH_PROFILE_MODULE setting? Once set, your User  
> object uses the get_profile() method to access the extra fields. In  
> your template you access those profile values like this:
>
> {{ user.get_profile.extra_field }}
>
> Don
>
>
>
> >
>
>
>   


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



How does one pass a variable to a Custom Model Manager for use in an inclusion tag?

2006-10-30 Thread Merric Mercer

Is it possible to pass a variable to a Customer Model Manager?  
I want to pass a variable to the Customer Manager and then use this 
Manager within an inclusion Tag.  Example below.

class UserPoint(models.Manager):
  def get_query_set(self):
  return super(UserPoint,self).get_query_set().filter(user=username)


@register.inclusion_tag('points.html')
def show_points(username):
qs=PointTransaction.objects.filter(user=username)   # This works 
fine without using Custom Model Manager
#qs=PointTransaction.userpoint.all()#  This 
does not work. 'username' is not defined.
return { 'points': qs }


MerMer

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



DateTimeField - Value Error - 'Year is out of Range'

2006-10-30 Thread Merric Mercer

I'm am having a problem with the DateTimeField when I save the data 
through the related class.

Example

class Transaction:
user = 
ForeignKey(UserProfile,edit_inline=models.TABULAR,num_extra_on_change=0)
DateTimeField(auto_now_add=True, blank=True)

When I add data to Transaction, through the Admin, everything seems 
fine. I can view the the individual transactions without a problem.

I can see the transaction when I first go to a related UserProfile.  
However, as soon as I save the UserProfile I get the following error
"Value Error - Year out of Range".

Looking at the database it is clear that when I do a save through the 
UserProfile, the DateTimeField is being changed for related transaction 
field.   I had understood from the documentation that auto_now_add only 
changed the datefield when the object was first created.   Can anybody 
explain where I'm going wrong.

MerMer


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



How do you nest two loops within a template?

2006-10-31 Thread Merric Mercer

As a newbie to Python, I can't see how one can nest two loops within a 
template.  Taking the template below, I have an additional list which I 
need to iterate over  in order to display a single figure for the last 
cell in each table row.

Currently, if I add a for loop to the last cell (eg.  {% for b in 
balance %} {{ b }} {% endfor %} ), I get all the values of the list in 
the cell - which is not want I want.

The documentation mentions a forloop.parentloop but I'm not sure  how to 
apply this or whether it is the solution.   Can anybody help?

MerMer


{% for cash in transfers %}

{{ cash.date }}
{{ cash.source }}
{{ cash.credit }}
{{ cash.debit }}
  {{ b }} 

{% endfor %}




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



Inclusion Tab for Log in form

2006-11-01 Thread Merric Mercer

I am thinking of using an Inclusion Tag on each of my generic views, as 
a log on form, visible only to unauthenticated users.

It's very straight foward to create an inclusion tag that returns a 
bland login form, but is it possible to create one that can uses the 
manipulators/validators that Django provides (provide the field widgets 
etc). 

Also, can anybody advise on how can I get a user to log on, using a form 
which is part of a generic page, and return them to the same page, once 
they have been authenticated

MerMer

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



Can I pass a Request object within "extra_context" of a Generic View.

2006-11-02 Thread Merric Mercer

Assuming I have a generic view.  Can I used the "extra_context" 
parameter to pass  a request object to a function elsewhere or resolve 
request.path directly?

Example of what I am trying to do is below:-

from django.http import HttpResponse, HttpRequest
from jmyapp.blog.views import test

info_dict = {
'queryset': Entry.objects.all(),
'paginate_by': 10,
'extra_context':{'test_response': test(request), 'path': request.path, }

Mermer

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



Re: Can I pass a Request object within "extra_context" of a Generic View.

2006-11-02 Thread Merric Mercer

That looks like a very good way.  Many thanks.  For the sake of 
completeness - does that mean my earlier example wouldn't work? Or is 
just not preferred?

As a newbie to Django and Python I'm sort of testing out stuff  and its 
nice to know for sure what works and what doesn't, particularly as 
Django seems to have many different ways to achieve a particular task.

Cheers

MerMer

James Bennett wrote:
> On 11/2/06, Merric Mercer <[EMAIL PROTECTED]> wrote:
>   
>> Assuming I have a generic view.  Can I used the "extra_context"
>> parameter to pass  a request object to a function elsewhere or resolve
>> request.path directly?
>> 
>
> Why not use RequestContext instead of Context, and enable the
> 'request' context processor?
>
> http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext
>
>   


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



Retreiveing a QSet from a Parent Table

2006-11-10 Thread Merric Mercer

Starting with specific record in a child table I need to do the the 
following.

1.  Access a related field 'Brand Name' in the parent table.  ( No problem)

2.  Retrieve a query set of records in the Parent table that match the 
'Brand Name'.  (No Problem)  BUT  I want to exclude the initial record I 
started with.

Can anybody recommend an elegant way to achieve point this.  I can 
retrieve the qs with all the related brand records but  I cannot work 
out how to retrieve the query set whilst omitting the related initial 
record.

Currently I have.

1. qs=Child.objects.get(id= record_id)  
2. brand = qs.parent.brand
3. related_brands = Parent.objects.filter(brand=brand)

MerMer

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



How do you iterate over a dictionary of objects within a template?

2006-11-10 Thread Merric Mercer

As part of  my render_to_response I have returned  the following:-
'campaigns':dict1  - where dict1 is a dictionary of objects from a model 
called "Campaigns".

In my template I can do things like {{ campaigns.0.id }} and {{ 
campaigns.1.id }} to access the dictionary.

But, how do I iterate over a dictionary like this within the template?  

Cheers

MerMer

--~--~-~--~~~---~--~~
 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: How do you iterate over a dictionary of objects within a template?

2006-11-10 Thread Merric Mercer

Kamil, many thanks but your suggestion does not work. I should have 
mentioned that I had already tried that.

I  am returning a dictionary nested inside the main dictionary like so:-

return render_to_response ('myapp/detail.html', { 'key1': value1, 
'key2': value2, 'campaigns':dict1}), so I presume that is why it is not 
working in the prescribed manner.

dict1 is populated by the view and looks like this {'0': value1, '1': 
value2, '3':value3, etc }.  The values in dict1 are class objects from 
my "myapp.models.campaign".

As mentioned,  I can access theese values directly in the template using 
the following syntax {{ campaigns.. }}. For 
example, {{ campaigns.0.id }} works fine for that particular instance.  
However, I  can't seem to iterate through the whole dictionary.

MerMer


> {% for item in campaigns %}
> {{ item.id }}
> {% endfor %}
>
>
> 2006/11/10, Merric Mercer <[EMAIL PROTECTED]>:
>   
>> As part of  my render_to_response I have returned  the following:-
>> 'campaigns':dict1  - where dict1 is a dictionary of objects from a model
>> called "Campaigns".
>>
>> In my template I can do things like {{ campaigns.0.id }} and {{
>> campaigns.1.id }} to access the dictionary.
>>
>> But, how do I iterate over a dictionary like this within the template?
>>
>> Cheers
>>
>> MerMer
>>
>> 
>
> >
>
>
>   


--~--~-~--~~~---~--~~
 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: How do you iterate over a dictionary of objects within a template?

2006-11-10 Thread Merric Mercer

Jay,

Many thanks for this.  As a recent newbie to Django and Python could you 
give me a steer what I would need to do to make this tag. (I familiar 
with making tags and filters, but can't see how I can use a tag to solve 
this problem.)

MerMer

Jay Parlar wrote:
> On 11/10/06, Jay Parlar <[EMAIL PROTECTED]> wrote:
>   
>> When you iterate over a dictionary, you're iterating over the *keys*
>> in the dictionary, not the values.
>>
>> ie.
>>
>> In [1]: x = {"a":1, "b":2}
>>
>> In [2]: for each in x:
>>...: print each
>>...:
>>...:
>> a
>> b
>>
>> According to a comment by Adrian on the template documentation page,
>> what you want isn't possible without writing a simple tag or filter.
>>
>> Jay P.
>>
>> 
>
> And after posting, it occurred to me you could try this:
>
> {% for item in campaigns.values %}
> {{item.id}}
> {% endfor %}
>
> >
>
>
>   


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: How do you iterate over a dictionary of objects within a template?

2006-11-10 Thread Merric Mercer

Jay, that works!   Many thanks. Though I don't quite understand why - or 
where 'values' come from.  Could you explain.

MerMer
>
> {% for item in campaigns.values %}
> {{item.id}}
> {% endfor %}
>
> >
>
>
>   


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: How do you iterate over a dictionary of objects within a template?

2006-11-10 Thread Merric Mercer

Very helpful and instructive.  Thanks.

MerMer

Jay Parlar wrote:
> On 11/10/06, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
>   
>> On 11/10/06, Merric Mercer <[EMAIL PROTECTED]> wrote:
>> 
>>> Jay, that works!   Many thanks. Though I don't quite understand why - or
>>> where 'values' come from.  Could you explain.
>>>   
>> .values is a standard method on dictionary objects which returns a
>> list containing the values in the dictionary in an undefined order.
>> 
>
> An infact, I'd say that it's bad design to make your template author
> know about .views. Instead, you should just be passing a list from the
> view, not a dictionary, unless you actually need a dictionary, ie:
>
> return render_to_response ('myapp/detail.html', { 'key1': value1,
> 'key2': value2, 'campaigns':dict1.values()})
>
> Then, in your template, you can do
>
> {% for item in campaigns %}
> {{item.id}}
> {% endfor %}
>
> Try playing around in the Python interpreter, to see the differences.
>
> In [4]: x = {"a":1, "b":2, "c":3}
>
> In [5]: x.keys()
> Out[5]: ['a', 'c', 'b']
>
> In [6]: x.items()
> Out[6]: [('a', 1), ('c', 3), ('b', 2)]
>
> In [7]: x.values()
> Out[7]: [1, 3, 2]
>
> In [8]: for each in x:
>...: print each
>...:
>...:
> a
> c
> b
> In [9]: for each in x:
>...: print x[each]
>...:
>...:
> 1
> 3
> 2
>
>
> The Python interpreter is one of the best weapons in any Pythonistas
> arsenal, learn to make it your best friend when coding.
>
> Jay P.
>
> >
>
>
>   


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



Wrapper around a Generic View

2006-11-13 Thread Merric Mercer

I'm still a little uncertain of how to put a wrapper around a generic 
view.  Given the following code below how does one handle pagination and 
other
work that generic views does automatically.

from django.views.generic.list_detail import object_list

def generic_wrapper(request):
   qs = Articles.objects.filter(user = request.username)
   return object_list(request, qs)

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



Template_context_Processor - Does it create an overhead on every template?

2007-02-12 Thread Merric Mercer

By using TEMPLATE_ CONTEXT_PROCESSOR (by adding a path to a function, 
example -  Function X) I understand that I can access the variables of 
Function X in any template.

What I would like to know is does this function get run in every 
template - even if I don't need it in a template.

For example,  Let's presume I need variables from Function X in 10 out 
of 15 templates. By adding the path to Function X in 
TEMPLATE_CONTEXT_PROCESSOR,  do I suffer the overhead of Function X in 
the 5 templates which  do not need it.

MerMer


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



iteration of query set appears to fail when running function directly from interpretor

2007-02-14 Thread Merric Mercer

Help!  I have a function that is  provided below.   When I try the 
individual lines of the function  through the interpretor (Ipython) 
everything works as expected.  For example:-

 >> qset=PointTransaction.objects.filter etc   this works fine!! 

However, when I try to run the function as a whole: Example:-

 >> admin_sync_agg(user_id=1,points_type=1)  >>

This runs but it seems that is is not iterating through the query set, 
so only the first record of qset is getting added to the balance.

Can anybody advise..  it's completely baffling me.  Thanks

MerMer


def admin_sync_agg (user_id,points_type):

qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
credit=0
debit=0
for i in qs:
credit = credit + i.credit
debit = credit + i.debit
balance= credit-debit

pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
pa.total_points=balance
pa.save()

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