Etags

2009-02-15 Thread mermer

I am trying to get Etags working in Django - so that if a page has not
been updated (and the client has already seen the page) it is returned
by the client's browser rather than rendered by django.

The code below is proof of concept.   However, it only partially
works, and that's why I'm asking for help.

When the client first connects the code correctly renders the page and
returns an ETAG header.

On the next request, the browser correctly sends the "If None Mach"
request header with the ETAG details. The code correctly returns the
304 respose and the client displays the page from the browser's
caache.

So far so good.

However, on the third request, it seems that the browser does not send
a "If-None_match" request header, so the etag is not found and the
whole page re-renders from the server.

Is there something else I need to configure?  Or something I am doing
wrong?


Cheers

MerMer


def etag_test(request):

etag = "TestEtag12345"
if etag == request.META.get("HTTP_IF_NONE_MATCH"): # Check to see
if request has matching etag
return http.HttpResponseNotModified() # if etag matches  send
a 304 reponse, so browser uses client cache


html="This is a test of ETAG"

   #Finally, add in the ETag to the new response we're returning.
response = http.HttpResponse(html)
response["Etag"] = etag  # add Etag header to respone

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



Re: Etags

2009-02-15 Thread mermer

OK - I've found the problem.  I'm using Firefox (Version 3.06) but the
problem is actually with Firebug, which I've been using to view the
headers.

With Firebug disabled, it works fine (viewing the headers through
another app).



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



Changing the reponse headers & Firefox

2009-02-16 Thread mermer

I am trying to change the Headers in the response.

My frustration, is that I can change the ETAG header and it is
returned by the browser at the next request but  I can't seem to get
the Cache Control or Expire header accepted by the browser

Does anybody have a clue why?  Is this a browser issue and if so does
anybody have a work around?   The Etag is very useful because it
reduces the work on the servers, but still requires the client
(browser) to connect to the server.  I want to add a Cache-Control
header which would remove the need for the client to connect to the
server at all, until the header had expired.

A snippet of code is below:-

response=HttpResponse(status=304)
response["Etag"] = "test Etag"  #  This works. It gets picked up and
returned in the next request by Firefox

response["Cache-Control"]="max-age=120"  #  This does not work.
Firefox keeps returning max-age=0

response["Expires"]= "Mon, 18 Feb 2009 13:36:08 GMT" # This does not
work. Firefox calls the server.

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



Customizing Admin for Large Data Sets

2009-02-17 Thread mermer

Does anybody have any advise on how best to customize the Admin to
cope with large data sets.

We need to deal with 500K plus records - and the loading times are
just too slow.

Is it possible to show a limited number of recently added records ffor
a model, but then use the search facility in athe dmin to look for any
record in the table.   Can someone give me some pointers on what we
would need to do to implement this type of change.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Customizing Admin to display non-editable fields

2009-02-17 Thread mermer

Is there a way to display only the values of certain fields in the
Admin, so that it is clear that those fields are non-editable?



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



Re: Customizing Admin to display non-editable fields

2009-02-18 Thread mermer

Thanks,  that works very well - but as you mentioned is certainly not
intuitive.

Can you use a similar technique to prepopulate fields?  My use case is
this:-

I want to display an INLINE formset.  Though records which already
exist I want to display but make certain fields uneditable
Using the "Extra"  I want to give the adminstrator the ability to add
an inline record, but restrict certain fields, by making sure that
they are prepopulated with data, which are also uneditable.



On 18 Feb, 01:25, Alex Gaynor  wrote:
> On Tue, Feb 17, 2009 at 8:23 PM, Malcolm Tredinnick <
>
> malc...@pointy-stick.com> wrote:
>
> > On Tue, 2009-02-17 at 17:19 -0800, mermer wrote:
> > > Is there a way to display only the values of certain fields in the
> > > Admin, so that it is clear that those fields are non-editable?
>
> > You would have to write a custom form widget to do so. There's nothing
> > out-of-the-box yet. We'll get to it one day, but not yet.
>
> > Malcolm
>
> Writing a custom widget to do it isn't especially easy because the render
> method on widgets doesn't get the initial value, however you can do 
> it:http://lazypython.blogspot.com/2008/12/building-read-only-field-in-dj...
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make a field uneditable in admin site

2009-02-18 Thread mermer

You need to create a custom ReadOnlyField that subclasses the
FileField.
You also need to create a ReadOnlyWidget that subclasses Forms.Widget

The link below, explains how the whole thing hangs together.


http://lazypython.blogspot.com/search?updated-min=2008-01-01T00%3A00%3A00-05%3A00&updated-max=2009-01-01T00%3A00%3A00-05%3A00&max-results=35

On 17 Feb, 07:22, guptha  wrote:
> hi ,
> i need to know how to create a non editable field in admin site .I
> tried , one like  below
>
> acct_number=models.CharField(max_lenght=100,editable=False)
>
> but it doesn't work
> please any other ideas,
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ImageField causing error when rendering with "The Image" attribute has no file associated with it.

2009-02-19 Thread mermer

Since I've upgraded to Django ver 1.00,  I'm suddenly getting the
following error with my ImageFields.

The tag is {{ model.image.url}} and it throws an error if the image
field in the database is null (even if it is set to null in the model)

Am I missing something?  Here is the error message being generated.


TemplateSyntaxError at /offer_detail_ver2/1/

Caught an exception while rendering: The 'image' attribute has no file
associated with it.

Original Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 71, in render_node
result = node.render(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 535, in resolve
obj = self.var.resolve(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 705, in _resolve_lookup
current = getattr(current, bit)
  File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 58, in _get_url
self._require_file()
  File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 43, in _require_file
raise ValueError("The '%s' attribute has no file associated with
it." % self.field.name)
ValueError: The 'image' attribute has no file associated with it.

Request Method: GET
Request URL:http://localhost/offer_detail_ver2/1/
Exception Type: TemplateSyntaxError
Exception Value:

Caught an exception while rendering: The 'image' attribute has no file
associated with it.

Original Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 71, in render_node
result = node.render(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 535, in resolve
obj = self.var.resolve(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
  File "C:\Python25\Lib\site-packages\django-trunk\django\template
\__init__.py", line 705, in _resolve_lookup
current = getattr(current, bit)
  File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 58, in _get_url
self._require_file()
  File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
\fields\files.py", line 43, in _require_file
raise ValueError("The '%s' attribute has no file associated with
it." % self.field.name)
ValueError: The 'image' attribute has no file associated with it.



C:\Python25\Lib\site-packages\django-trunk\django\template\debug.py in
render_node

  74. e.source = node.source
  75. raise
  76. except Exception, e:
  77. from sys import exc_info
  78. wrapped = TemplateSyntaxError(u'Caught an exception while
rendering: %s' % force_unicode(e, errors='replace'))
  79. wrapped.source = node.source
  80. wrapped.exc_info = exc_info()

  81. raise wrapped  # error highlighted on this line

  82. return result
  83.
  84. class DebugVariableNode(VariableNode):
  85. def render(self, context):
  86. try:
  87. output = force_unicode(self.filter_expression.resolve(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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField causing error when rendering with "The Image" attribute has no file associated with it.

2009-02-23 Thread mermer

Anybody with any advice on this.  Ever since wev'e upgraded to version
1.00 we are having issues with the ImageField

ValueError: The 'image' attribute has no file associated with it.

On 19 Feb, 12:30, mermer  wrote:
> Since I've upgraded to Django ver 1.00,  I'm suddenly getting the
> following error with my ImageFields.
>
> The tag is {{ model.image.url}} and it throws an error if the image
> field in the database is null (even if it is set to null in the model)
>
> Am I missing something?  Here is the error message being generated.
>
> TemplateSyntaxError at /offer_detail_ver2/1/
>
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
>
> Original Traceback (most recent call last):
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
>     result = node.render(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
>     obj = self.var.resolve(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
>     value = self._resolve_lookup(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
>     current = getattr(current, bit)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
>     self._require_file()
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
>     raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
>
> Request Method:         GET
> Request URL:    http://localhost/offer_detail_ver2/1/
> Exception Type:         TemplateSyntaxError
> Exception Value:
>
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
>
> Original Traceback (most recent call last):
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
>     result = node.render(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
>     obj = self.var.resolve(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
>     value = self._resolve_lookup(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
>     current = getattr(current, bit)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
>     self._require_file()
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
>     raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
>
> C:\Python25\Lib\site-packages\django-trunk\django\template\debug.py in
> render_node
>
>   74. e.source = node.source
>   75. raise
>   76. except Exception, e:
>   77. from sys import exc_info
>   78. wrapped = TemplateSyntaxError(u'Caught an exception while
> rendering: %s' % force_unicode(e, errors='replace'))
>   79. wrapped.source = node.source
>   80. wrapped.exc_info = exc_info()
>
>   81. raise wrapped  # error highlighted on this line
>
>   82. return result
>   83.
>   84. class DebugVariableNode(VariableNode):
>   85. def render(self, context):
>   86. try:
>   87. output = force_unicode(self.filter_expression.resolve(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 
django-users+unsubscr...@googlegroups.com
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 MerMer

This is a follow on from my previous email.  Things have got even
stranger and unpredicable.

I dropped the table from the database and then ran syncdb to re-create
a completely new and empty db.  However I STILL
cannot get the new fields to be recognized.  All the previous fields
are available.

The shell confirmed that a new table had been created.   I checked in
the DB and in the Admin and both or these
were working as expected.  I added a new record on all the fields via
the admin.

In the shell I run the following to return the new record and return
all the attributes.

record = Product.objects.get(id=1).
dir(record)

This shows that I cannot access the extra fields that I added to the
model.

This is really shaking my confidence in the system and I'm not sure
what else I can try.




--~--~-~--~~~---~--~~
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-21 Thread MerMer

I was using the same shell.   I also tried shutting down the server,
rebooting the machine and opening everything up again to see if that
would make any difference but it did not.

However,  then a few hours later -  it started to work again.  I still
don't fully understand the reason.  I can only assume that my path was
somehow faulty.  However, that doesn't fully explain why Django was
using my model file perfectly ok in some instances (such as in the
Admin and in the DB), but not in the shell or through my views.

MerMer

On Mar 20, 12:04 pm, "Ramiro Morales" <[EMAIL PROTECTED]> wrote:
> On 3/20/07, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > 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.
>
> Are you opening a new Python shell (with the myproject.promotions import)
> after any of your model/database modifications or have been
> maintaining the same shell session open from before you started
> these mods?.
>
> Regards,
>
> --
>  Ramiro Morales


--~--~-~--~~~---~--~~
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: limit_choice_to option for related Model

2007-03-27 Thread MerMer

Scratch that.  Couldn''t see the wood for the trees.   I was simply
missing the comma after Promotion.

MerMer

On Mar 27, 10:34 pm, Merric Mercer <[EMAIL PROTECTED]> wrote:
> 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
-~--~~~~--~~--~--~---



Re: json and django - couple of questions.

2007-04-18 Thread MerMer

Thanks Russ,

Since my last post I've also discovered the the "values" option which
automatically converts the queery sets into a list of dictionaries.

data=MyModel.objects.values('field1', 'field2')

MerMer



On Apr 18, 12:48 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 4/18/07, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
>
>
> > 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?
>
> Not using the serialization framework. The serializer framework exists
> to serialize database objects; extra attributes on the object are not
> in the database, and so are not serialized.
>
> An alternative approach is to use the SimpleJSON library directly. Set
> up a python dictionary that contains the data structure you want to
> serialize (or write a proxy object that behaves like a dictionary),
> and pass it to the SimpleJSON library. A similar approach will work
> for XML.
>
> > 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?
>
> If you pass a fields=(...) option to the serializer, only the fields
> named will be serialized. e.g.:
>
> txt = serializers.serialize('json', data, fields=('attr1','attr2'))
>
> Yours,
> Russ Magee %-)


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

2007-04-19 Thread MerMer

Many thanks Malcolm. That nailed it.  So simple when you know how!

MerMer

On Apr 19, 2:56 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2007-04-18 at 23:28 +0100, Merric Mercer wrote:
> > 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.
>
> Wtihout seeing your models (what you called the fields, etc) it's hard
> to be precise, but the following should do what you want:
>
> Cash.objects.filter(promotion__category=6)
>
> I'm assuming the one-to-one field in Cash is called "parent" and the
> Category field in Promotion is called "category".
>
> 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
-~--~~~~--~~--~--~---



Re: puzzeled by possible inconsistency in queery set.

2007-04-19 Thread MerMer

Malcolm,  Must be pilot error  and I can't replicate the error any
longer - I do apologize for wasting your time.

However, one additional question.. is there an easy way to a record
from a queery set dynamically (without touching the DB)?  What I'm
looking do do in my view is as follows:-

1.  Create query set using a filter.
2.  Add attributes to query set, via setattr (but not commit these to
the DB)
3.  Dyanmically filter the query set based on these new attributes
4.  Return the qs to the template.

Step 3 is still a slight puzzle.  As a work around I am doing the
following (but I suspect there must be a better way!)

ls=[]
for i in qs:
if i.newattribute == somevalue:
  ls.append(i)

I am then return the list rather than the qs to the template.

cheers

MerMer




> Something more than what you think is going on here. This sort of simple
> example (iterating through a queryset adding an attribute, then
> iterating again to read the attribute) works perfectly for me. I just
> tested it on half a dozen different models without problems.
>
> So you might need to do some looking around to work out what is special
> about your models. Or look at the details you might have trimmed to make
> the example simpler and start putting them back in one by one.
>
> 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
-~--~~~~--~~--~--~---



Re: puzzeled by possible inconsistency in queery set.

2007-04-19 Thread MerMer

Many thanks Macolm that's very clear.

 can't replicate the error any
> > longer - I do apologize for wasting your time.
>
> > However, one additional question.. is there an easy way to a record
> > from a queery set dynamically (without touching the DB)?  What I'm
> > looking do do in my view is as follows:-
>
> > 1.  Create query set using a filter.
> > 2.  Add attributes to query set, via setattr (but not commit these to
> > the DB)
> > 3.  Dyanmically filter the query set based on these new attributes
> > 4.  Return the qs to the template.
>
> Some background information to put my next comment in context:
>
> Because of step 2, what you have at step 3 is no longer a pure QuerySet,
> but a cached list of results -- by iterating through them in step 2, you
> have pulled all the results out of the database and into the cache. So
> further filtering using QuerySet machinery lacks any point. The logic
> behind being able to do
>
> qs1 = MyModel.objects.filter(name='fred')
> qs2 = qs1.filter(date=datetime.now())
>
> is that until you actually access the results of a QuerySet, no database
> query is made. So, in the above example, qs1 never results in a call to
> the database. In you sequence of steps above, there is no saving to be
> made here, because step 2 accesses the members of the queryset.
>
> > Step 3 is still a slight puzzle.  As a work around I am doing the
> > following (but I suspect there must be a better way!)
>
> > ls=[]
> > for i in qs:
> > if i.newattribute == somevalue:
> >   ls.append(i)
>
> That seems logical. You could subclass QuerySet and add your filter as a
> method in the subclass if you wanted to. But it's basically the same
> code. The built-in queryset filter methods won't be able to help you,
> because they are all geared towards querying database table columns.
>
> If memory usage was an issue (and I wouldn't panic too much here -- this
> is only relevant if you've got thousands of results, at a guess), you
> could create an iterator (using itertools.ifilter, from the Python
> standard library, for example) that returned the next result from the
> queryset satisfying the constraint and pass the iterator to your
> template. That way, the results are only stored once in memory.
>
> 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
-~--~~~~--~~--~--~---



1-Many Display in the Admin Area .

2006-10-03 Thread MerMer

As a newbie I'm struggling to get to grips with Django's admin
interface.   I have created two tables (Promoter, Promotions) which
have a straight forward 1-Many relationship.

A couple of unexplained issues:-

1.  The objects are being displayed in the Admin area as "Promoters"
and "Promotionss" - note the added "s".

2.  I have added a core=True parameter to one of the fields in the
Class Promtions.  However, when I try to add a record via Admin I get
messages asking for every field to be completed.I experienced the
same when I went through the tutorial with the Poll/Choices example.  I
understood that core=True only operates on a specific field rather than
a whole record.  If this is true, where am I going wrong?

Finally,  I would like to click on a Promoter in the Admin area and see
a list (rather than the complete record) of all their Promotions, in a
collapsed view.  The Promotions table has alot of fields and I've tried
using the edit_inline parameter.  However, when I do this I get the
Promoter records at the top and then the complete record of each
promotions, instead of a simple list of each record.

Currently, this makes the system ugly and unusable for me as an Admin
function.

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: 1-Many Display in the Admin Area .

2006-10-03 Thread MerMer

Alan,

Thanks for helping out - but I'm more confused than ever.  If Django
fields are required by default why use core=True at all?   What do I
enter into the parameter so a field is NOT required.   I tried null =
True and this didn't work (and as an aside it made the red highlights
on the core=true fields disappear!).

edit_inline= models.TABULAR does not work.   Hopefully this explanation
will make it clear.   When I click on a specific Promoter I want to
display a list of all their related promotions.

Prometer Name
---
Promotion Name 1-  Date Published
Promotion Name 2 - Date Published
Promotion Name 3 - Date Published

Then I want to be able to simply click the name to bring up the
underlying record for editing.

At the moment when I click on a promoters name it displays all the
fields and editable regions straightaway. Imagine a  Promotion Table
with 10 text fields and a Promoter hat thas 10 related Promotions. When
I click on that Promoter I currently get a very long list (either
vertically or tabular) because it displays all the records.  Very ugly.
 I have to scroll down (or vertically) a long way to make any changes.

Hope this is clearer.

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



Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

.
I am trying to create a many to many relationship between two classes
(Promotion and Category).

When I add "categories = models.ManyToManyField(Category)" to the
Promotion class I get an errror saying "Category is not defined".

However, when  I add "promotions = models.ManyToManyField(Promotion)"
to the Category Class it works fine!

This is driving me crazy, as a newbie it's not easy to diagnose where
the problem lies.  I've been very impressed with the documentation,
review etc of Django - but after 24 hours of not getting too far, I'm
getting rather frustrated.

MerMer


from django.db import models
import datetime

class Promotion (models.Model):
promo_headline = models.CharField(maxlength=400, core=True)
promo_sbody = models.TextField(help_text="This is for a short
description about the offer")
promo_lbody = models.TextField(help_text="This if sfor a long
description about the offer")
pub_date = models.DateTimeField()
categories = models.ManyToManyField(Category)
start_date = models.DateTimeField(core=True)
expiry_date = models.DateTimeField()
promoter_name = models.ForeignKey(Promoter,
edit_inline=models.TABULAR)
is_multi_takeup = models.BooleanField(help_text="Tick if the offer
can be taken up by the same person more than once")
takeup_url = models.URLField(help_text="URL where the offer will be
taken up")
question_email = models.EmailField(core=True, help_text="where
questions about this offer will be sent")
terms_conditions = models.TextField(core=True)
def __str__(self):
return self.promo_headline

class Category (models.Model):
category_name = models.CharField(maxlength=400)
def __str__(self):
return self.category_name
class Admin:
pass


--~--~-~--~~~---~--~~
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: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

Thanks Jay and Rajesh,

I've  just discovered this myself by switching the code around.  This
is a real GOTCHA and not immediately obvious for a newbie like me.  I
can't see anything in the documentation that mentions this - so I
presumed it was a bug.


--~--~-~--~~~---~--~~
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: Cannot get Many to Many Relationship To work - "name" not defined error message

2006-10-03 Thread MerMer

Jay,  I did read the documentation before jumping in - but it's not all
necessarily clear for someone who hasn't alot of experience in Python
of Django.

Because of my unfamiliarity I had presumed that all the classes in a
single Models.py were immediately visible to each other.   There is
nothing specific in the link you provided to make this explicit in
relation to a ManyToMany relationship.   However, having read Rajesh's
link I can now see that there is a good example of using a string and
that gives a strong hint.


--~--~-~--~~~---~--~~
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: Mile-high view of Django (was "Re: Cannot get Many to Many Relationship To work...")

2006-10-03 Thread MerMer



> I keep learning little bits here and there as I encounter them,
> but am having trouble fitting all the pieces together into a
> cohesive big-picture.  Like the person to whose post I'm
> responding, I can read the docs, but extracting the big-picutre
> (which in turn would help in knowing where to look in the docs)
> can be tough.
>

Thats' interesting to hear.  As a newbie I'm having a different
experience.  I think the documentation, as a whole, does an excellent
job at giving the bigger picture (though I can see the argument for an
shorter, white document to save).

Where I'm constantly coming unstuck is on the detail.


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



Using some of the admin functionality with ordinary users

2006-10-04 Thread MerMer

list_filter ('field_names') works very well in the admin area.  Is
there an easy way to use this same functionality to display information
to ordinary users visting the site?

Also, in the lists within admin you can sort each list by clicking on
the column header which is very useful.  However, this is only clear
once you have clicked on the header.  Is there a setting to each column
head on automatically so it is visible?

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



Meta Data - How is it used effectively.

2006-10-06 Thread MerMer

I'm trying to get my head around what Meta Data is - and more
importantly how to use it effectively.

I've read that it is "anything in the data model that's not a field,
such as ordering options etc" but I still don't quite get it.

Specifically.

1. Are we constrained to those Meta Options listed in the Model
documentation?  If not, how does one add a custom option? Are there any
tuturials and examples of this?

2. How are the Meta Options used exactly. For example if the option
"order_with_respect_to = question" is set for a specific Model, will
that be enforced every time that Models Manager is called?

3. Many of the Meta Model options seem to be heavily linked to how the
data is to be viewed. Why isn't it in the View.Py instead?  I'm
assuming that I haven't got the big picture 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
-~--~~~~--~~--~--~---



Re: Meta Data - How is it used effectively.

2006-10-06 Thread MerMer

Malcom,

Many thanks.  That's a big help.

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



"choices" option - possible bug?

2006-10-06 Thread MerMer

I have a field inside a model that uses the "choices" attribute:-

rating=models.IntegerField(choices=RATING_CHOICES).

This field is then being shown in the Class Admin list:-

class Admin:

list_display=('rating','promotion','review_headline','review_date','is_viewable')


Using the above code, the data for 'rating', within the Admin list
display is being shown as "(none)".

However, when I remove the choice=RATING_CHOICES, the data shows up.

This looks like a bug - can anybody explain this to me?

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: "choices" option - possible bug?

2006-10-06 Thread MerMer

Ray,

The code is below. The RATINGS_CHOICES are defined inside the Model
Class.

MerMer

RATING_CHOICES=(
('5', '5 stars'),
('4', '4 stars'),
('3', '3 stars'),
('2', '1 stars'),
('1', '1 star'),
)
rating=models.IntegerField("user
rating",choices=RATING_CHOICES)


--~--~-~--~~~---~--~~
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: "choices" option - possible bug?

2006-10-06 Thread MerMer

Many thanks, that sorted it.

Interesting to note that using the string format the data still got
stored in the Database and was getting displayed back in the admin
detailed view, but not in the list view.

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: Ajax

2006-10-07 Thread MerMer

I can't get it to work either.  I've tried both setttings.  I followed
Bill de hÓra  detailed screen shots about where to install TinyMCE.

My admin code inside my model has:-
js = ['tiny_mce/tiny_mce.js', 'js/textareas.js']

Checking the source code from the returned HTML shows that the
Javascript is being parsed correctly to where the files are stored.



 

However,  I'm not getting anything.  Anybody have any ideas where I
might be 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
-~--~~~~--~~--~--~---



Re: Ajax

2006-10-07 Thread MerMer

I'm using a default local installation on a Windows XP machine, running
Firefox 1.5

When I try the following URL
http://localhost:8000/media/js/textareas.js  I get a message saying
that the file cannot be found on the following (notice the slashes)

C:\Python24\lib\site-packages\django_src\django/contrib/admin/media\js/testarea.js

However, when I go to localhost:8000/admin and then look in the source
of the generated web pages it seems clear to that the files are in
correct directory.

It's probably something stupid,  I am doing here ?. I'm very new to
Django and still trying to find my way around.

MerMer







> Ok you've surely checked, but i have to ask anyway. :)
> Are the files really readable, e.g. does
> http://www.yoursite.com/media/js/textareas.js show up in your browser?
>
> Oh and which browser do you use? Konqueror (and probably Safari too) don't
> work with tinyMCE.
>


--~--~-~--~~~---~--~~
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: How do I select where x=a and y=b?

2006-10-08 Thread MerMer

Details are in the Database API document .  The "exact" expression is
defined in the glossary thoough the example uses .get rather than
.filter

MerMer

carlwenrich wrote:
> it worked, thanks. where would i find it if you hadn't been so kind as
> to tell me?


--~--~-~--~~~---~--~~
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 I work out what the Web root is?

2006-10-08 Thread MerMer

This is probably a daft question - but is there a way to find out what
my web root is when I'm using the Django development web server.

With PHP you can see all your configuration settings easily using the
phpinfo() function, including all your web settings.  Is there an
equivalent for 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
-~--~~~~--~~--~--~---



Adding two columns together

2006-10-09 Thread MerMer

Another newbie question!

If I have two  tags {{ objects.cash }} and another {{ objects.cash1 }}
can I add these together in the template?

If not which is the most appropriate way to manage something like 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
-~--~~~~--~~--~--~---



Re: How do I work out what the Web root is?

2006-10-09 Thread MerMer


> Your question doesn't really make sense for the development server,
> since it only ever serves dynamic content.

Does this mean that I will have problems serving Javascript files using
just the development server?

I've been trying to get some Dojo widgets and MCEtiny to work.   I've
installed these and checked that the HTML that is rendered by Django
points to the correct js files, but nothing is working.

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: Adding two columns together

2006-10-09 Thread MerMer

Many thanks -   I did check the docs but didn't see it in the Filter
section.

If I need something similar, which is not covered by a filter (such as
an average of columns) - what's the best way to procede.   Should I:-

a) Do the calculation in the view
b) create a custom tag
c) Do something else

I'm abit unsure about the best way to go an try and solve issues as I
encounter them.

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: How do I work out what the Web root is?

2006-10-09 Thread MerMer

Thanks for all this, though I have to say right now I don't fully
understand many of these settings.   Is this fully covered in the
documentation - if so where?  I've looked in the Settings folder - am I
missing something?

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



When to

2006-10-12 Thread MerMer

Slowly trying to see the light... can anybody put me straight on the
following:-

I have three different templates.  Each template gives a simple list of
a model (table in the database).I now want to create a single
template that displays all three lists.

Can I:-

a)  Combine all three templates into a master template using an Include
statement or a SSI statement.  (My read on this is I can't or its not
recommended but I just want to check)

b) Combine all three lists by creating a new view, (Doesn't this
violate the DRY principle?)

Can anybody outline to this newbie what the basic steps and best
practice are to achieve this.  The tutorial doesn't really go into this
stuff?

Finally, I've tried to test the SSI tag but I get "Didn't have
permission to include file".  I changed my settings file to include:-

ALLOWED_INCLUDE_ROOTS = (

'c:/python24/lib/site-packages/django/bin/juicyoffers/mytemplates/polls/
',
  '/mytemplates/polls/',
)

but this didn't work. Any suggestions?

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



Extending a template - error

2006-10-12 Thread MerMer

I am trying to extend a template.  My parent Template is in
mysite/mytemplates/promotions/
and the child template is in mysite/mytemplates/polls/

I get the following error saying that the template cannot be found when
I try:-

{% extends "mytemplates/promotions/promotion_list.htm" %}

The error reads:-

In template
c:/python24/lib/site-packages/django/bin/mysite/mytemplates\polls/index.html,
error at line 1
Template 'mytemplates/promotions/promotion_list.html' cannot be
extended, because it doesn't exist
1

It's strange that the error message is showing that the slash after
mytemplates ichanges to a  backslash from a forward slash. I'm
wondering if I have something wrong with my setup because I've also
noticed I can't run any javascripts - even though they seem to be
installed in the right directory.   That said, I have other templates
(which are not child templates) which load fine within the promotions
directory and the polls directory.

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: Extending a template - error

2006-10-12 Thread MerMer

I've now moved the parent template into the same directory as the child
template but I'm still getting the same error.

Exception Value:Template 'results.html' cannot be extended, because
it doesn't exist
Exception Location:
C:\Python24\lib\site-packages\django_src\django\template\loader_tags.py
in get_parent, line 58
Template error

In template
c:/python24/lib/site-packages/django/bin/mysite/mytemplates\polls/index.html,
error at line 1


--~--~-~--~~~---~--~~
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: When to

2006-10-12 Thread MerMer

As a follow on.  Can I:-

Combine all three templates by using inheritance between the templates.

Unfortunately, I haven't been able to test this yet - because I can't
get the "extend tag" to work (see other post).I am assuming that it
won't work because of the following. Could someone confirm that this is
right.

1.  The URL points to the View, which in turn points to a child
template.
2.  The view sets the context for the child template so that the child
template is filled with with the correct data.
3.  The child template extends the parent template.  However, I don't
see how the parent template calls a view (isn't this the role of the
URL?),  so the parent template cannot be populated with dynamic data
from a seperate view.   Is this right?

I'm struggling to get the bigger picture.  It would be really helpful
if the tutorial had a slightly more complex example, which showed how
to create templates which draw data from different tables.

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: Extending a template - error

2006-10-12 Thread MerMer

my settings look like the following:-

TEMPLATE_DIRS = (
"c:/python24/lib/site-packages/django/bin/mysite/mytemplates",

When I set up Django I just put in the full path in the belief that
this would make things easier while I was testing stuff.

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: Extending a template - error

2006-10-12 Thread MerMer

Julio,

I not sure what directory you're refering to.  The tutorial is quite
explicit that one should create your own template directory within your
site.  It wouldn't make any sense if these then had to refer to base
templates elsewhere.

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: Extending a template - error

2006-10-12 Thread MerMer

Don,

Thanks for the advice - but it's not working for me.

My full path is
"c:/python24/lib/site-packages/django/bin/mysite/mytemplates" which
works.

I've tried "/mytemplates" and "mysite/mytemplates" as the TEMPLATE_DIR
path but they don't.

The {% extends "promotion_list.htmt"%} is not working even when I moved
the promotion_list template into the same directory as the child
template.

I'm probably making some realy rookie mistake - but I can't see 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
-~--~~~~--~~--~--~---



Re: When to

2006-10-12 Thread MerMer

Frankie,

Thanks for this... I'll take a look.

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: Extending a template - error

2006-10-12 Thread MerMer

 I've now got the TEMPLATE_DIR as 'mytemplates' and that's fixed it.
Your advice on what is an absolute and relative path was very helpful.
Many thanks.

Based on the above, could you give me some examples on what my Media
Root and URL, and Admin Media Prefix should be.  I think I'm also
having issues with those.

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



Re: When to

2006-10-13 Thread MerMer

I can see that I could use inclusion tags or template tags.  I've read
the documentation  however, I'm still unclear when you would use one
over the other.

What would be the appropriate use case for a template tag versus an
inclusion tag?

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



Custom Template Tag - What do I need in my actual template?

2006-10-13 Thread MerMer

I'm steadily working through the excellent custom template tag
tutorial:-

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

I've got the following code to create a template tag.  However,  I'm
unclear as to what
I need to put into my actual template.

The author states, that based on the code below,  I would need to add
{% get_latest_polls 3 %} to the template, where 3 is a variable.
However, while this not not create any errors, it is also not returning
the latest 3 Polls.   What else do I need to add?

MerMer

from django import template
from mysite.polls.models import Poll, Choice

class LatestPollsNode(template.Node):
def __init__(self,num):
self.num = num
def render(self, context):
context['polls'] = Poll.objects.all()[:self.num]
return ''

def get_latest_polls(parser, token):
bits = token.contents.split()
if len(bits) !=2:
raise TemplateSyntaxError, "get latest_latest_polls tag take
exactly one arguement"
return LatestPollsNode(bits[1])

get_latest_polls = register.tag(get_latest_polls)


--~--~-~--~~~---~--~~
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: Custom Template Tag - What do I need in my actual template?

2006-10-13 Thread MerMer

Tim,

Many thanks - that works a treat.  I was getting myself very confused
about where and how to use the context.

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



Returning an average from a Related Field.

2006-10-15 Thread MerMer


I have two Models.

1.  Product
2.  Review -  There can be many reviews for any product (one -to many
relationship)

One of the fields of Review is "Rating". This  holds an integer between
1 and 5.

I want to display a list of Products, and display the average review
rating for each product.

I can see how I can easily display the number of reviews for each
product by using
"review_set.count"  but it's not clear to me how I go about displaying
the average rating.

Could anybody set me on the right path on this?  I'm sure it must be a
common type of requirement.  I'm very new to both Python 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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

Jonathan,

Many thanks for this.

Sorry to be a pain , but I have a couple of follow on questions, so I'm
clear.

1. How should I best implement this code.  As a custom tag or in the
view?

2. Any suggestions on how I should pass the product.id to the code?

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



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

Jonathan,

I don't want to the list to be filtered to only those who have a
Rating.  I need to display ALL the products, while still showing the
average rating for those products which have a rating.

Example Table:

-- Price --- # Reviews  ---Average Rating
Product 1   $24  2  4.5
Product 2   $20  0


Sorry if my orginal post wasn't clear enough on this point.  Will your
solution still work on this basis?  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
-~--~~~~--~~--~--~---



Re: Returning an average from a Related Field.

2006-10-16 Thread MerMer

 Looking at the options, I've also experimented with creating a custom
Model method.
The following almost works ( The division at the end returns an error
and I'm new at Python so need to work that out)

   def av_rating(self):
queryset = self.review_set.all()
x=0
y=0
for rating in queryset:
x=x+rating.rating
y=y+1
return x/y

{{ objects.av_rating }} is the tag that is then put in the template.

Can anybody comment on the disadvantage/advantages of using this type
of custom model method?  Also, if anybody can advise me on how I get
the division to work - that would also be appreciated - Django returns
a Zero Division error.

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: Returning an average from a Related Field.

2006-10-16 Thread MerMer

Tim,

Many thanks - that has helped me understand alittle more about Python.
 I'm sure that there is a faster way.  It's been more of an exercise
for me to try and get to understand Django, Python etc. I'm practically
a complete newbie.

Any suggestions on how would you get the server to calculate and return
the average?


--~--~-~--~~~---~--~~
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: Returning an average from a Related Field.

2006-10-16 Thread MerMer

John,

Excellent.  The requirement to make it easily sortable makes your
solution compelling. Thanks for detailing. Plus Im sure that there will
lots of places where this type of Signals method would be handy.

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: New Django Screencast

2006-10-17 Thread MerMer

Ian,

Great screencast.  As a newbie - very helpful and I'm looking forward
to seeing more content on the site when it launches.


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



Alternate colors - when returing a list.

2006-10-19 Thread MerMer

Does anybody know of a filter/tag that will return a table list with
rows of an alternate color.
I have a hazy recollection that I've seen this somewhere - but I've
relooked through the documentation and can't seem to find 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
-~--~~~~--~~--~--~---



Import issue using signals.py

2006-10-19 Thread MerMer

I've tried to set up a signals.py file in the same directory as my app
("products").

At the top of the signals.py I have the following import statement:

from myapp.products.models import Product, Review

The two model classes (Product and Review) both sit in the models.py in
the products directory.

However, whenever I run this I get an import error.  I just can't
figure out where I could be going wrong.  Any ideas?

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: Import issue using signals.py

2006-10-19 Thread MerMer

Malcom, many thanks.

I have to admit as a newbie to Python and Django and I dont' fully
understand how "import" works.  I just presumed that you put a
reference to any module at the top.

At the top of the product.models.py file I have the following:-

"from mysite.promotions.signals import update_review_average"

update_review_average is the function being run in the signals.py

To further confuse the matter when I run "manage.py validate" from the
command line I get the following

"mysite.promotions:cannot import name Review"
"mysite.products: cannot import name Review"

As soon as I comment out the reference to the signal file
and remove the import statement from the top of the signal
file everything works again.

It's puzzling to me that with the signal.py in place  I am getting
errors
message for two applications.   The app  "products" (which is home to
the models.py file where Product sits and home to signals.py) AND the
promotions app - which has the following import statement:-

from myapp.products.models import Promotion, Review

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



Re: Import issue using signals.py

2006-10-19 Thread MerMer

Apologies but

"from mysite.promotions.signals import update_review_average" should
read "from mysite.products.signals import update_review_average"

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: Import issue using signals.py

2006-10-19 Thread MerMer


> The quick fix here is to replace that line with
>
> from mysite.promotions import signals
>

The quick fix here didn't work.  I would then get
"update_review_average is undefined."

However, many thanks for the explanation, I'll go through it and if I
have further questions come back.  In the meantime, I've resorted to
putting the "update_review_average" into the models.py - which has
created a new set of problems (see new post).

As a newbie, I'm struggling to make much headway - guess it's not my
day!

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



Signal Code Failing - Can anybody see where I've gone wrong.

2006-10-19 Thread MerMer

I am trying to update a Promotion field  through a signal sent when a
Review field is updated.  Review  has a many-to-one relationship with
Promotion.

I must be making some rookie mistake, but I can't work out why its not
working.  The code fails to return anything for the line p_qs=
Promotion.objects.filter(id=promotion_id) and therefore the index on
the next line is out of bounds.

def update_review_average(sender,instance,signal,*args,**kwargs):
"""
updates the average for the review on promotions any time that
a review is updated, or created.

"""
promotion_id = instance.promotion
qs = Review.objects.filter(promotion = promotion_id)
x=0
y=0
for r in qs:
x=x+r.promo_rating
y=y+1
average = y and x/y or 0
# save average to the relevant Promotion
p_qs = Promotion.objects.filter(id=promotion_id,)
p=p_qs[0]
p.av_rating = average
p.save()

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



Type Error __str__returned non-string(type long) - while using Admin

2006-10-19 Thread MerMer

All of a sudden I am getting the following errors (see below), when I
try and select "Promotions" from the admin area.

I've no idea what this means or how to fix it... can anybody provide
any suggestions?   It's turning into a bad day for me and Django.   As
a newbie to Django and Python and and with limited experience in PHP
I'm finding it very slow going... though I'm trying to persevere.

MerMer

TypeError at /admin/promotions/promotion/
__str__ returned non-string (type long)
Request Method: GET
Request URL:http://localhost:8000/admin/promotions/promotion/
Exception Type: TypeError
Exception Value:__str__ returned non-string (type long)
Exception Location:
C:\Python24\lib\site-packages\django_src\django\utils\html.py in
escape, line 27
Template error

In template
C:\Python24\lib\site-packages\django_src\django\contrib\admin\templates\admin/change_list.html,
error at line 17
Caught an exception while rendering: __str__ returned non-string (type
long)
7   {% block coltype %}flex{% endblock %}
8   {% block content %}
9   
10  {% if has_add_permission %}
11  {% blocktrans with
cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans
%}
12  {% endif %}
13  
14  {% block search %}{% search_form cl %}{% endblock %}
15  {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
16  {% block filters %}{% filters cl %}{% endblock %}
17  {% block result_list %}{% result_list cl %}{% endblock %}
18  {% block pagination %}{% pagination cl %}{% endblock %}
19  
20  
21  {% endblock %}
22
Traceback (innermost last)
Switch to copy-and-paste view

*
C:\Python24\lib\site-packages\django_src\django\template\__init__.py in
render_node
   699.
   700. def render_node(self, node, context):
   701. return(node.render(context))
   702.
   703. class DebugNodeList(NodeList):
   704. def render_node(self, node, context):
   705. try:
   706. result = node.render(context) ...
   707. except TemplateSyntaxError, e:
   708. if not hasattr(e, 'source'):
   709. e.source = node.source
   710. raise
   711. except Exception, e:
   712. from sys import exc_info
  ▶ Local vars
  Variable  Value
  context
  [{'block': ]>}, {'block':

'>, ,  '>, ]>, , ]>, , ]>, , ]>,
, ]>,   '>]>}, {}, {'has_add_permission': True}, {'LANGUAGES':
(('ar', 'Arabic'), ('bn', 'Bengali'), ('cs', 'Czech'), ('cy', 'Welsh'),
('da', 'Danish'), ('de', 'German'), ('el', 'Greek'), ('en', 'English'),
('es', 'Spanish'), ('es_AR', 'Argentinean Spanish'), ('fi', 'Finnish'),
('fr', 'French'), ('gl', 'Galician'), ('hu', 'Hungarian'), ('he',
'Hebrew'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'),
('nl', 'Dutch'), ('no', 'Norwegian'), ('pt-br', 'Brazilian'), ('ro',
'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'),
('sr', 'Serbian'), ('sv', 'Swedish'), ('ta', 'Tamil'), ('tr',
'Turkish'), ('uk', 'Ukrainian'), ('zh-cn', 'Simplified Chinese'),
('zh-tw', 'Traditional Chinese')), 'LANGUAGE_BIDI': False,
'LANGUAGE_CODE': 'en-us'}, {}, {'perms':
,
'messages': [], 'user': }, {'cl':
,
'is_popup': False, 'title': 'Select promotion to change'}]
  e
  
  exc_info
  
  node
  
  self
  []
  wrapped
  
*
C:\Python24\lib\site-packages\django_src\django\template\__init__.py in
render
   855. def render(self, context):
   856. resolved_vars = [resolve_variable(var, context) for var in
self.vars_to_resolve]
   857. if takes_context:
   858. args = [context] + resolved_vars
   859. else:
   860. args = resolved_vars
 861.
   862. dict = func(*args) ...
   863.
   864. if not getattr(self, 'nodelist', False):
   865. from django.template.loader import get_template
   866. t = get_template(file_name)
   867. self.nodelist = t.nodelist
   868. return self.nodelist.render(context_class(dict))
  ▶ Local vars
  Variable  Value
  args
  []
  context
  [{'block': ]>}, {'block&

Re: Type Error __str__returned non-string(type long) - while using Admin

2006-10-19 Thread MerMer

I've managed to sort it... I had inadvertantly set one of the classes
to

def __str__(self):
return self.id

which obviously caused the conflict.  Apologies for wasting anybody's
time.

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: Signal Code Failing - Can anybody see where I've gone wrong.

2006-10-19 Thread MerMer

Zak,

Many thanks - exactly what's required.  In hindsight its so obvious - I
don't know why I was making such heavy weather of it!

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



Re: Diamanda Wiki support and some django tutorials :)

2006-10-20 Thread MerMer

Looks very interesting.  Good to see some more information about
deployment with other options.

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



ManyToMany versus creating two one-to-many relationships.

2006-10-20 Thread MerMer

Since a many-to-many relationship is effectively a join table of two
1-many relationships can you implement a many-to-many relationship like
this in django like this?  Any problems associated with this approach?


class A

class B
 foreignkey(A)
 foreignKey(C)

class C


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: ManyToMany versus creating two one-to-many relationships.

2006-10-20 Thread MerMer

Many thanks Aidas,  I'm having a play around to see.   As a follow-on
do you know how I can make table B appear in the Admin - if I use a
many-to-many reference directly from A to C instead.

 If I do this, I understand that Django will automatically create the
join table, but how do I get it to display in the Admin.   I

 presume I have to create a class by hand that maps to the table that
has been created.


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



Combining Unique Columns

2006-10-20 Thread MerMer

I am aware that Unique=True can be used to ensure that a value is
unqiue within a particular column.

Is there any means to ensure that a combination of values from two
columns within a table are unique

If not,  I presume that I would have to write a custom def and then run
that via a Signal via the post.save method.   Would that be right?

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



Trying to Extend User - but system not writing to database.

2006-10-23 Thread MerMer

I am trying to extend the User Model.

I've created a new app (userprofiles) and added this to my settings.
I've then created the models.py (see below)

At first II tried the following (User, unique=True,
edit_inline=models.TABULAR, num_in_admin=1,min_num_in_admin=1,
max_num_in_admin=1,num_extra_on_change=0)
as parameters on the user field.  This created the inline form in the
admin, under USER but would not save any of the details to the
database.

I've paired the model down to the very basics (as below).  However, now
it doesn't even show up in the Admin.

However, I am not getting any errors.   Any ideas?

from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
#relations
user = models.ForeignKey(User,unique=True)
#attributes
street_address = models.TextField()
city_address = models.TextField()
postcode = models.TextField()
year_birth=models.IntegerField()
married_status = models.CharField(maxlength=100)
acc_number=models.IntegerField()


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



Help with List_display in Admin class

2006-10-23 Thread MerMer

In the example below I am trying to get list_display to show the the
"fullname" that was defined in def__str__(self).   It's not working.
Can anybody tell me how I can do it.

Many thanks

MerMer

class UserProfile(models.Model):
  user=models.OneToOneField(User)
  activation_key = models.CharField(maxlength=40)
  key_expires = models.DateTimeField()
  street_address=models.CharField(maxlength=400)
  city_address= models.CharField(maxlength=100)
  postcode=models.CharField(maxlength=50)
  def __str__(self):
   self.fullname = "%s %s" %(self.user.first_name,
self.user.last_name)
   return self.fullname
  class Admin:
  list_display=('self.fullname','city_address','postcode')
  pass


--~--~-~--~~~---~--~~
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: Help with List_display in Admin class

2006-10-23 Thread MerMer


Thanks for the input - but I still can't get it to work. With the code
as above I get an error
saying the attribute "self.fullname" cannot be found.   When I try
"list_display = ('fullname')
I get the following error

"__str__ returned non-string (type instancemethod)".   

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



Admin list not displaying more than one object

2006-10-24 Thread MerMer

Using the following code I am only getting 1 object returned in the
admin list for UserProfile.
So if I have 5 objects - I get 4 blank lines and then 1 line with the
listing.


class UserProfile(models.Model):
  user=models.OneToOneField(User)

  def __str__(self):
  return "%s %s" % (self.user.first_name, self.user.last_name)
  class Admin:
  pass


--~--~-~--~~~---~--~~
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: Admin list not displaying more than one object

2006-10-24 Thread MerMer

Duhhh!  So busy looking for problems that I forgot to look for the
obvious.
My apologies for wasting time.

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: Trying to Extend User - but system not writing to database.

2006-10-24 Thread MerMer

I moved to creating the model with a OneToOne relationship rather than
a foreign key and have it got it to work.  Not sure why I was having
problems as Foreign Key


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



send_mail - how do you set up the SMTP server.

2006-10-25 Thread MerMer

I've looked through the official docs regarding sending an email but I
can't find any explanation on how to point to a particular SMTP server.
  How to I set up the SMTP server so that the send_mail function works?


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



Clarification on Sessions and User Profile.

2006-10-25 Thread MerMer

I want to be able to show a user their account information/stats on
each page in the site, without having to constantly hit the database to
retrieve the information.

I'm alittle unclear as to the best way to do this?  Should  I write
this info into a Session/Cookie and then retrieve it as required on
each view?

Second, will I need to render a dictionary of values - or can I put
session information directly into a template?

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: send_mail - how do you set up the SMTP server.

2006-10-25 Thread MerMer

Thanks Don, I've now found it.   As default, the setting file had not
been set up with an Email_host which is why I missed 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
-~--~~~~--~~--~--~---



Re: status of authentication updates?

2006-10-25 Thread MerMer

I had orginally heard that the book was due out in October - but when I
last looked at the Apress site it mentioned January.   I  also noticed
that the Archives had not been updated.

No criticism mind, I'm well aware that Django is a volunteer effort -
however, it's extremely reassuring to hear this.


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



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

2006-10-27 Thread MerMer

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



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

2006-10-27 Thread MerMer

I need an authenticated user to be able to see some of their personal
details on each page of the site.


I have so far created a UserProfile class (which has a one to one
relationship with the User class) in order to provide more information
on the user.


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?


Assuming that I can't add UserProfile fields directly to the template,
it seems to me I need to write a template tag to get the extra info in
the UserProfile class on every page.  If so, I think I have two ways to
create the tag.


1) Call the DB to retrieve the UserProfile fields directly.


2) Use request.session to retrieve UserProfile fields (having
pre-populated thhe UserProfile session fields  when the user logs on).


What are the pros and cons of each method. By using Sessions will I
avoid hitting the DB as much as method 1?

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



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

2006-10-30 Thread MerMer

Rajesh,

I wanted to see if I could do it for two reasons.

1.  I need to enhance the underlying solution.  I need to do some more
in depth table wide caculations, working out averages etc, but based on
a user-id.   The documentation suggests that the table wide code would
best be placed in a model manager.

2. In trying to learn Django and python - I'm trying to discover how
everything works.  Django seems very powerful but it is not immediately
intuitive which of the possible options (views, template tags, models
and managers etc) one should use.

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: DateTimeField - Value Error - 'Year is out of Range'

2006-10-30 Thread MerMer

Cheers Aidas, that's wokred for me too.

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: How does one pass a variable to a Custom Model Manager for use in an inclusion tag?

2006-10-30 Thread MerMer

Or, list here some of the calculations you are trying to work
> out so you can get more feedback on this.
>

I have a table which shows Points owned by particular users.  These
have an attribute of "type".
I need to display back to the user how many of each type of points they
own.

For instance, taking  the example table below  I would need to show
that UserID 1 has 280 "REG" points and 150 ZZZ points.

User ID-- Points  Points_Type
1 200  Reg
1   80  Reg
1  100 zzz
150 zzz
2  100 Reg
2  100     xyz

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



Creating a Dynamic set of choices in Admin

2006-10-31 Thread MerMer

Is it possible to set up Dynamic set of choices.

Suppose I have a Model which requires two additional fields.  The first
is a foreign key to USER.  The second field needs be dynamically
populated depending on what is entered into the User Field.

I cant see how this can be achieved.  Is there any way?

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: How does one pass a variable to a Custom Model Manager for use in an inclusion tag?

2006-10-31 Thread MerMer

Many thanks, Rajesh.  I'll take a look.

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: How do you nest two loops within a template?

2006-10-31 Thread MerMer

Joe,

My orginal code (see the inclusion tag below ) was returning a Query
Set and an interable list.   I can't understand how I can loop through
the Query set and append the data to the end - as there is no matching
attribute in the Query set.

 I am looking to return a query set and build a table from it.  The
last column in the table is the sum of the all the previous rows.
Here's an example.

credit   Balance
50  50
40  90
50140


Here's my orginal inclusion tag


@register.inclusion_tag('cashtransfer.html')
def show_cash_transfer(username):
balance=[]
x=0
qs=CashTransfer.objects.filter(user=username)
qs1=qs[0]
for cash in qs:
x=cash.credit+x
balance.append(x)
return { 'transfers': qs, 'balance': balance }


--~--~-~--~~~---~--~~
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: How do you nest two loops within a template?

2006-10-31 Thread MerMer

I found out that I needed to change the query set to a list, then I
could append new data to the end and return this.  The following is the
ammeded inclusion tag.

@register.inclusion_tag('cashtransfer.html')
def show_cash_transfer(username):
balance=[]
x=0
y=0
qs=CashTransfer.objects.filter(user=username)
item=list(qs) # convert the queery into a list
for cash in item:
x=item[y].credit+x
item[y].balance=x  #as a list we are able to append the data
y=y+1
return { 'transfers': item }


--~--~-~--~~~---~--~~
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 tag for login screen.

2006-11-04 Thread MerMer

I am thinking about creating a small login form as an inclusion tag, to
display within other pages created by generic views, when the user has
not been authenticated.

Creating a tag that displays a form seems simple enough.  However, I
want to log the user on without them leaving the page they are on.
Anybody,  have a way to do this?

Secondly, is there a way to use a form as an inclusion tag - and still
use custom manipulators.
Do I pass the details of custom manipulator etc back to the template
from the inclusion tag?

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



Retrieving a QSet from a Parent Table.

2006-11-10 Thread MerMer

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

1.  Access a related field 'Brand Name' in the parent table.

2.  Retrieve a query set of records in the Parent table that match the
Brand name.   BUT  I want't to exclude the intial 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 ommitting the 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
-~--~~~~--~~--~--~---



Re: Retreiveing a QSet from a Parent Table

2006-11-12 Thread MerMer

Thanks Zac, that's exactly what I needed.

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



Updating and saving a related record. How does it work?

2006-11-29 Thread MerMer

I was able to save a record like so...

Promotion.total_value=2000
Promotion.save()

However, I recently moveed the "total_value" field into another model
which has a OneToOne relationship with the Promotion Model.

Know I can access total_value like so:-

Promotion.competition.total_value
>> 2000

However, I can't work out how to save a different value to the field
using something like

Promotion.competition.total_value=3000

Can anybody please advice.

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: Updating and saving a related record. How does it work?

2006-11-29 Thread MerMer

Jacob,

I had tried that, but it's not working for me.I get the following:-

Promo=Promotion.objects.get(id=1)
Promo.competition.total_value
>> 2000
Promo.competition.total_value=3000
Promo.competition.save()
Promo.competition.total_value
>> 2000

I must be doing something stupid, but can't see 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
-~--~~~~--~~--~--~---



Re: Updating and saving a related record. How does it work?

2006-11-29 Thread MerMer

I am finding that the following intermediate step is required.

Comp=Promo.competition

This changes the class from Promotion to Competition and I can then
make the changes

Comp.total_value=3000
Comp.save()

However, I'm no wiser why the earlier solution by Jacob is not working
for me. Intuitively,
it should.

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: Hiding Referrer URL

2006-12-04 Thread MerMer

As this is handled by the browser - you might want to revert to
Javascript.  I think there is a plugin for JQuery which handles this.

MerMer

Siah wrote:

> Hi,
>
> I need to hide referrer url on HttpResponseRedirect. I was expecting to
> find something like ReferrerURL in HttpResponseRedirect.headers, but
> did not. I was hopping to change the header information right before
> HttpResponseRedirect sends the user to the other server to hide the
> referrer URL, or even change it to somethings else.
> 
> How can I accomplish that?
> 
> Thanks,
> Sia


--~--~-~--~~~---~--~~
 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: Validation 3 steep complicate form

2006-12-04 Thread MerMer

You may want to check out django.newforms which is going to be the
replacement for forms and manipulators.

According to a recent threads in the development forum it is already
being used by in some production environments.  The formal
documentation is sparse but there is alot of detail in the code base
under tests/regressiontests/forms/tests.py.   

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: Admin 404s on users

2006-12-04 Thread MerMer

I had a similar problem the other day.  I had made a mistake on one of
my fields of another model, which was edited inline via the User Model.

MerMer


[EMAIL PROTECTED] wrote:

> I just know there's a simple explanation for this, but  my brain is
> fried.
>
> My admin area decided today it was going to start throwing a 404 error
> for every user.
>
> When I go to the admin, under "Auth" and click "users" all is well. I'm
> presented with a list of users.
>
> When I try to click one of the users - any of the users - it 404s. Even
> if I click on my own user name.


--~--~-~--~~~---~--~~
 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: Admin 404s on users

2006-12-05 Thread MerMer

Yes, I broke the model that was being edited  by the USER model.   From
memory mine also validated OK, because the problem lay with some of the
data in the DB - not the actual structure of the model.   That's why I
was able to see a complete USER list and only got the error when I
clicked on the individual record.

Merric


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

2006-12-06 Thread MerMer

There was a very recent post on CAS (Central Authentication System).
The author has written the middeware for Django and is making it
publically available.

I've no idea if there are any differences between CAS and OpenID, but
thought it might be worth a mention.

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: Read only fields once created

2006-12-06 Thread MerMer


You can add "editable=False" to you database model.  This prevents it
from showing up in Admin,  though of course it can still be edited
directly in the DB.

MerMer


Ross Burton wrote:

> Hi,
>
> Is it possible to have fields in the model that can be set at object
> creation, but are immutable after that?  I have an "original estimate"
> field that should only be set when creating the object, and never
> edited after that.
> 
> Thanks,
> Ross


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



test client - Keeps returning 301 status code and not sure why.

2006-12-06 Thread MerMer

I am trying to get to grips with the test client
(Django.test.client.Client)

I've done the following

>>from Djano.test.client import Client
>>c=Client()
>>c=c.get('/promotions/',)
>>c.status_code
301

I keep getting 301 or 500 status codes.  I've tried the full URL but
have not got any further.
The URL works fine in a normal browser and in the manage.py runserver
window it shows a status code of 200.

Anybody have any ideas of where I'm going wrong with the Test Client.

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



  1   2   >