Re: How do I make Django evaluate a ForeignKey for json serialization?

2008-12-27 Thread mattimust...@gmail.com



On Dec 28, 10:01 am, "Russell Keith-Magee" 
wrote:
> On Sun, Dec 28, 2008 at 5:32 AM, adambossy  wrote:
>
> > Russ,
>
> > Thanks for the reply. Specifically, I am wondering if there is some
> > feature of the Models API that allows me to retrieve the foreign key
> > object so that it is included in the serialized string. That is,
> > without writing my own serializer (which I suspect I may have to do).
>
> The serializer is decoupled from the Model API, so your question is
> unrelated to the model API. Serialization exploits the model metatdata
> embedded in models; the issue in this case is that the data extracted
> from the model by the serializer doesn't meet your requirements. You
> want to have a different serialization format (i.e., you want to roll
> out serialized objects in a different format to that provided by
> default). This means you will need to write your own serializer.
>
> Looking for deeper solutions to this problem -
>
> Ticket #4656 possibly describes part of your problem - this ticket
> describes an enhancement that would allow the serializer to follow.
> This would be much like the select_related() operator on querysets,
> but for serialization. This ticket hasn't seen any activity for a
> while, but it has been accepted for inclusion as soon as a working
> implementation is available.

The code attacted #4656 can be used as is for achieving the kind of
serialization that Adam requires. I'm am also using it quite
extensively in a large RESTful application. You can register my
serializer classes to replace the default Django json serializer. In
your settings.py add:

SERIALIZATION_MODULES = { 'json' : 'wadofstuff.serializers.json' }

Then in your own code from your example above

from django.core import serializers
print serializers.serialize('json', Template.objects.get(id=1),
relations=('type',))



{
"pk": 1,
"model": "template",
"fields": {
"type": {
"pk": 3,
"model": "type",
"fields": {"name": "TemplateType3"}
}
},


cheers

Matthew

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



dynamic load urls.py problem

2008-12-27 Thread strelnikovdmitrij

hi guys...me again...but now I've done a little step forward, when I
load urls file through request.urlconf it does not append end slash to
any url..:( and urls without trailing slash try map through base
urls.py file (ROOT_URLCONF).
in new url.py file I specify urlpatterns = pattern() not +=. It loads
this file correctly..but url must be exactly the same like in
urls.py..no appending doesnt work.
I think it should be done due the url entered sub.domain.tld/user. I
think there is some bug during parsing sub.domain.tld. I have looked
through django source code and found way it handling. It load default
urls and cached it. So I need to go deeper and deeper in source code .
So if anybody has some experiences with it, I will welcome your
suggests or ideas.
Dmitrij
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: wondering how to do something similar to save_model for inline.

2008-12-27 Thread Timboy

Great link. I was really excited to try it.

Here is my new inline:
class rentalInline(admin.TabularInline):
model= Rent
extra = 3
raw_id_fields = ('movie',)
exclude = ['rented_by']

def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
instance.rented_by = request.user
instance.save()
formset.save()

I am still getting the same issue:
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in root
  157. return self.model_page(request, *url.split('/',
2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in model_page
  176. return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in __call__
  197. return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
_commit_on_success
  238. res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in change_view
  583. self.save_formset(request, form, formset,
change=True)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in save_formset
  382. formset.save()
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
  372. return self.save_existing_objects(commit) +
self.save_new_objects(commit)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_new_objects
  407. self.new_objects.append(self.save_new(form,
commit=commit))
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_new
  473. return save_instance(form, new_obj, exclude=
[self._pk_field.name], commit=commit)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_instance
  59. instance.save()
File "/home/richard/work/svn/moviedb/../moviedb/store/models.py" in
save
  91. super(Rent, self).save(**kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save
  307. self.save_base(force_insert=force_insert,
force_update=force_update)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save_base
  379. result = manager._insert(values,
return_id=update_pk)
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in
_insert
  138. return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
insert_query
  888. return query.execute_sql(return_id)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/
subqueries.py" in execute_sql
  308. cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py"
in execute_sql
  1700. cursor.execute(sql, params)
File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in
execute
  19. return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /admin/store/renter/4/
Exception Value: null value in column "rented_by_id" violates not-null
constraint
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: wondering how to do something similar to save_model for inline.

2008-12-27 Thread alex.gay...@gmail.com

Take a look at the save formset method:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-formset-self-request-form-formset-change

On Dec 27, 6:46 pm, Timboy  wrote:
> I have an admin object where I want to pass in the request.user on
> save. It works fine in my normal admin class but not for the inline
> version.
>
> (works fine here):
> class RentAdmin(admin.ModelAdmin):
>     exclude = ['rented_by']
>     list_display = ('renter', 'movie', 'late', 'owed', 'paid',
> 'due_date', 'rented_by')
>     sort_by = '-due_date'
>     raw_id_fields = ('renter', 'movie')
>
> (but not here):
> class rentalInline(admin.TabularInline):
>     model= Rent
>     extra = 3
>     raw_id_fields = ('movie',)
>     exclude = ['rented_by']
>
>     def save_model(self, request, obj, form, change):
>         if not change:
>             obj.rented_by = request.user
>         obj.save()
>
> Any help would be appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Fastest way to import datas into a database

2008-12-27 Thread Benjamin Sergeant
On Fri, Dec 26, 2008 at 2:34 AM, Russell Keith-Magee  wrote:

>
> On Thu, Dec 25, 2008 at 9:02 AM, bsergean  wrote:
> >
> > Hi all,
> >
> > I'm populating my database manually using a script that create ORM
> > objects and save them... I have a lot of datas and it's fairly slow.
> > I'm wondering what is the best way to speed this up.
> >
> > From
> http://docs.djangoproject.com/en/dev/howto/initial-data/#howto-initial-data
> > I see there are two alternatives.
> >
> >  * Using fixtures
> > I could create a big json files (or several), and then load them. Will
> > it be smart and do the smallest number of query, or a bunch of
> > queries ?
>
> This will essentially be no different to your 'create ORM objects'
> approach. Internally, Django uses ORM objects in the deserialization
> process, so if you are seeing problems manually creating ORM objects,
> the same problems will probably exist with deserialization.
>

OK.


>
> >  * Or using raw SQL ? (I'm using postgres, and I saw you can do an
> > INSERT command with multiple rows. Is it a good way to speedup
> > things) ?
>
> Assuming you can automate the production of the SQL and, this will
> always be the fastest approach. However, the price you pay is the
> convenience of dealing with the ORM. You will need to balance the
> costs for your own circumstances.
>

(I'm using postgres) What I'm gonna probably do is generate the same thing
that pg_restore want, taking for model the output of pg_dump -F t (tar
output is convenient). It uses the COPY statement to bulk load lots of rows
from a file, that should be fast.


>
> A third option that you haven't considered is that you may not be
> using Django properly :-) An often forgotten feature of Django is that
> When DEBUG is enabled, Django logs every command that goes to the SQL
> backend. As a consequence, if you run a long lived script, you will
> see a slowdown as memory gets eaten up by the SQL activity log. If you
> disable DEBUG during your production data load, logging is disabled,
> and you should find that performance improves dramatically.
>

Good to know, but I had it turned off. (I remember noticing a big
performances difference at the app level when I turned DEBUG off).

Thanks for your help,
- Benjamin.


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



wondering how to do something similar to save_model for inline.

2008-12-27 Thread Timboy

I have an admin object where I want to pass in the request.user on
save. It works fine in my normal admin class but not for the inline
version.

(works fine here):
class RentAdmin(admin.ModelAdmin):
exclude = ['rented_by']
list_display = ('renter', 'movie', 'late', 'owed', 'paid',
'due_date', 'rented_by')
sort_by = '-due_date'
raw_id_fields = ('renter', 'movie')

(but not here):
class rentalInline(admin.TabularInline):
model= Rent
extra = 3
raw_id_fields = ('movie',)
exclude = ['rented_by']

def save_model(self, request, obj, form, change):
if not change:
obj.rented_by = request.user
obj.save()

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



Re: How to create middleware that adds context variables?

2008-12-27 Thread Roy

Ah, as a noob I was not aware of context processors! Thanks!

On Dec 28, 5:13 am, bruno desthuilliers
 wrote:
> On 27 déc, 17:42, Roy  wrote:
>
> >  How to create middleware that adds context variables?
> > Hi, anyone have any examples of the above?
>
> What's wrong with context processors ?
>
> http://docs.djangoproject.com/en/dev/ref/templates/api/?#writing-your...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I make Django evaluate a ForeignKey for json serialization?

2008-12-27 Thread Russell Keith-Magee

On Sun, Dec 28, 2008 at 5:32 AM, adambossy  wrote:
>
> Russ,
>
> Thanks for the reply. Specifically, I am wondering if there is some
> feature of the Models API that allows me to retrieve the foreign key
> object so that it is included in the serialized string. That is,
> without writing my own serializer (which I suspect I may have to do).

The serializer is decoupled from the Model API, so your question is
unrelated to the model API. Serialization exploits the model metatdata
embedded in models; the issue in this case is that the data extracted
from the model by the serializer doesn't meet your requirements. You
want to have a different serialization format (i.e., you want to roll
out serialized objects in a different format to that provided by
default). This means you will need to write your own serializer.

Looking for deeper solutions to this problem -

Ticket #4656 possibly describes part of your problem - this ticket
describes an enhancement that would allow the serializer to follow.
This would be much like the select_related() operator on querysets,
but for serialization. This ticket hasn't seen any activity for a
while, but it has been accepted for inclusion as soon as a working
implementation is available.

There is also a lingering ticket idea floating around - it has been
suggested many times that Django's serializers are not flexible enough
- that your use case should be a matter of configuring Django's
serializer, rather than writing a new serializer from scratch. In
principle, I have no objection to this idea - but I am yet to see a
good proposal for what such configuration would look like.

> I'll keep tinkering... Let me know if you have any ideas.

Let me know if you have any :-)

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



How to modify cleaned_data of a ModelChoice field?

2008-12-27 Thread Daniel Bachler

Hi,

I am fairly new to django, so if I missed a piece of documentation
that would describe what I want to do please feel free to redirect me,
I may have missed it in my search.

I have a pretty simple problem that I cannot quite get my head around.
I have a Many To Many relationship between UserProfile and Group (a
custom group class, not the django auth one) that represents which
real life groups my users are members of. The users should be able to
join some of the groups all by themselves, while for others an admin
must do the group join operation for them.

I am currently having a problem with the view that allows the users to
join groups. It uses a ModelForm with a custom filter on the groups
the user can select, like so:

class UserProfileForm(ModelForm):
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.filter
(open_to_all__exact='True'), required=False)

class Meta:
model = UserProfile
exclude = ('member_id', 'member_status', 'year_of_entry',
'course_at_entry', 'user')

The problem is that when I save this form, the group memberships of
the items that were excluded by the filter get deleted.

How can I avoid this?

My attempt was to do this before the form.save() call:
form.cleaned_data['groups'] = form.cleaned_data['groups'] + list
(fixed_memberships)

but cleaned_data['groups'] seems to be a queryset and I have not yet
understood how to modify this queryset to include items from another
queryset or a list.

Any hints would be greatly appreciated!

TIA,
Daniel

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Invalid block tag: 'get_comment_count'

2008-12-27 Thread Russell Keith-Magee

On Sun, Dec 28, 2008 at 12:27 AM, Florian Lindner  wrote:
>
> Hello,
>
> I'm trying to use the comment framework from Django 1.0.2.
>
> I've followed all the steps in 
> http://docs.djangoproject.com/en/dev/ref/contrib/comments/
>
>  (added it to installed apps, added to urls.py and loaded in the
> template) but I get:
>
> TemplateSyntaxError at /blog/1/
> Invalid block tag: 'get_comment_count'
>
> from:
>
> {% get_comment_count for object as comment_count %}

django.contrib.comments is an extension application, so the template
capabilities provided by this application aren't included in the
default template tag set. In order to use {% get_comment_count %} in
your template, you need to direct the template engine to load the
comment template tags. This means putting {% load comments %} at the
start of the template that is using {% get_comment_count %.

This is covered right at the start of the page you referenced:

http://docs.djangoproject.com/en/dev/ref/contrib/comments/#comment-template-tags

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



Django Comments framework

2008-12-27 Thread stereoit

Hi,
I tried to add comments app 
http://docs.djangoproject.com/en/dev/ref/contrib/comments/,
now few things works but Preview sometimes acts as Submit when there
are no errors and I have no idea how to override Posted screen to
include link (or just redirect) to original page.

The documentation is kinda sparse and i had to look into source code
to see there are some templates I can override. Any good tutorial on
new comments framework?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to create middleware that adds context variables?

2008-12-27 Thread bruno desthuilliers

On 27 déc, 17:42, Roy  wrote:
>  How to create middleware that adds context variables?
> Hi, anyone have any examples of the above?

What's wrong with context processors ?

http://docs.djangoproject.com/en/dev/ref/templates/api/?#writing-your-own-context-processors
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I make Django evaluate a ForeignKey for json serialization?

2008-12-27 Thread adambossy

Russ,

Thanks for the reply. Specifically, I am wondering if there is some
feature of the Models API that allows me to retrieve the foreign key
object so that it is included in the serialized string. That is,
without writing my own serializer (which I suspect I may have to do).
Alternatively, I was hoping somebody may be able to offer a technique
for passing messages that I may have overlooked. With queries such as
those in my example, I may be retrieving m Type objects, each of which
may have n unique Class objects with foreign key pointers, leading to
a whole mess of data to be passed in the json, making it a nightmare
to deserialize it on the other end.

Throughout my application, I am using SimpleJSON for some queries, and
serializers.serialize for others. SimpleJSON is useful for python
dictionaries and serializers.serialize is good for QuerySets.
Ultimately, though, all the information I am passing is retrieved from
QuerySets; my choice of serializer is based on whether I am iterating
through the QuerySets and writing the data to python dictionaries
(simplejson) or simply passing them directly to a response object
(serializers.serialize). The reason for this is that the object vary
in complexity and sizel for simple queries, I'll just pass the whole
QuerySet to serialize() and for complex ones I'll break it down and
create a dictionary to pass through simplejson.

I suppose that my overall intent is a cry for help for a simpler, one-
size-fits-all solution that can allow me to easily serialize objects,
yet pass small messages. Perhaps a middle layer between Django and my
front end (the Google Web Toolkit) is necessary. The fact that GWT
only has basic JSON support doesn't help, as every message I pass
requires a custom handler to decode the JSON.

I'll keep tinkering... Let me know if you have any ideas.

Adam


On Dec 27, 4:45 am, "Russell Keith-Magee" 
wrote:
> On Sat, Dec 27, 2008 at 2:11 PM, adambossy  wrote:
>
> > I have a model that refers to a ForeignKey, e.g.:
>
> > class Template(models.Model):
> >  type = models.ForeignKey(Type)
> > ...
>
> > class Type(models.Model)
> >  name = models.CharField(max_length=32)
> > ...
>
> > I can fetch these objects fine using the model API.
>
> > t = Template.objects.get(id=1)
> > print t.type
> >>> 
> > print t.type.id
> >>> 3
> > print t.type.name
> >>> TemplateType3
>
> > If I serialize these, I cannot get 'name.' I know Django lazily
> > retrieves these, but even by iterating or calling t.type.name, they
> > are unavailable during serialization. Is there any way to have Django
> > evaluate the ForeignKey object so that I can retrieve the field,
> > 'name?' I need fields to contain "name": "TemplateType3" (or whatever
> > it may be)! :)
>
> > from django.core import serializers
> > print serializers.serialize('json', Template.objects.get(id=1))
>
> >>>     {
> >        "pk": 1,
> >        "model": "template",
> >        "fields": {
> >            "type": 3
> >        }
> >    },
>
> It isn't entirely clear what you're trying to do. Do you want to
> change the Django serializers so that they output:
>
>   "type": "TemplateType3"
>
> If this is the case, then you will need to write your own serializer.
> Django serializes objects in a specific way, optimized for
> deserialization later on as fixtures. This output format won't suit
> many applications. If you need a different format, you will need to
> write a serializer that outputs in the format you require. Django
> ships with SimpleJSON, so you can build serialized output from
> primitives if need be. You could also use Django's serialization
> library to write your own serializer that outputs in a format of your
> choice. If your desired output format is similar to Django's default
> format, you may find that you can use django/core/serializers/json.py
> as a starting point for this implementation.
>
> Alternatively, are you trying to manipulate a deserialized object in
> some way? If this is the case, you will need to provide more specific
> details on what it is you are trying to achieve.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: front facing poll form issues

2008-12-27 Thread Kevin

No one has offered any help. That's fine, so let me ask my question
differently.

Can anyone point me to an example of form processing for formsets?
Let's say can_delete=True, how do I process that in my code?

I have scoured google and can find no examples, so any examples/links
would be appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django i18n for google

2008-12-27 Thread Antoni Aloy

2008/12/27 Alessandro Ronchi :
> Il 16 dicembre 2008 19.20, Alessandro Ronchi
>  ha scritto:
>> When google spiders our i18n translated django websites, does it try
>> and indicize all languages? is it possible to force the language by a
>> GET var (for example &language_code=en) ?
>
> I think it's a critical problem.
>
> We spend time to make our i18n websites but google bot don't see other
> languages except default.  Is there a way to select language with a
> get url? Any other solution?

You could create a url that links to your localized site so Google
would be able to crawl it, but I suppose that your site depens on
changing the language via POST, isn't it?

I that case, you could write yourselve the code and allow changing the
code using GET.

-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Passing arguments to Admin index in Django 1.0

2008-12-27 Thread raj

Hi all,

I'm new to Django, started out with 0.96 and very soon switched to 1.0
version. Here, I'm facing the following problem.
My Admin index page needs to have a small custom form snippet in
addition to all other usual things. It will be accommodated in the
admin_index page as follows:

{% block reportblock %}


Reports


{{ reportform.as_table }}





{% endblock %}

The above snippet depends on the variables 'reportform' and
'base_url'. I don't know whether it is intelligent or not, but my plan
is to define a form named ReportForm in the forms module and pass an
instance of it to the admin_index page. The base_url may be extracted
from request and passed in the same way.

How can I pass arguments to the admin_index page? It don't accept any
extra argument dictionary from urlConf. Or can the required data be
accessed directly from the template itself?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



urls config and slash append

2008-12-27 Thread strelnikovdmitrij

I have middleware where I dynamically load (request.urlconf) urls.py
for each subdomain (application)..if I used (r'^(?P[a-zA-Z0-9-]
{4,20})/$', 'user'), its work with end slash and without, but (r'^(?
P[a-zA-Z0-9-]{4,20})/new/$', 'new'), works only with end
slash..why? I really dont understand why?
I would like get same output to user/new and user/new/..
 thanks a lot :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



slash append

2008-12-27 Thread strelnikovdmitrij

hi all:)
I have middleware where I dynamically (request.urlconf) load urls.py
for each subdomain (django application)..
if I used (r'^(?P[a-zA-Z0-9-]{4,20})/$', 'user'), its work with
end slash and without,
but (r'^(?P[a-zA-Z0-9-]{4,20})/new/$', 'new'), works only with
end slash..why?
I would like get same response to user/new and user/new/..
I really dont understand why I didnt? thanks a lot:)
Dmitrij

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



Re: displaying correct image url

2008-12-27 Thread garagefan

the ability to edit posts would be nice :)

i figured out the issue and am now displaying relative urls to the
images.

now, to edit the delete function to remove the thumbnails as well...

On Dec 27, 1:21 pm, garagefan  wrote:
> currently, self.image.name displays the absolute server path...
>
> i want to change this so that when i call it, it either display the
> relative path, or an absolute path for the website itself.
>
> so instead of displaying /home/site/mysite/images/gallery/
> imagename.jpg
>
> it will displayhttp://www.sitename/images/gallery/imagename.jpg
>
> in settings i have:
>
> MEDIA_ROOT = '/home/site/mysite/images'
> MEDIA_URL = 'http://www.sitename.com/images/'
>
> in the models.py:
>
> image = models.ImageField(upload_to='/home/site/mysite/images/
> gallery')
>
> "mysite" being the base level directory for the site itself
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



displaying correct image url

2008-12-27 Thread garagefan

currently, self.image.name displays the absolute server path...

i want to change this so that when i call it, it either display the
relative path, or an absolute path for the website itself.

so instead of displaying /home/site/mysite/images/gallery/
imagename.jpg

it will display http://www.sitename/images/gallery/imagename.jpg

in settings i have:

MEDIA_ROOT = '/home/site/mysite/images'
MEDIA_URL = 'http://www.sitename.com/images/'

in the models.py:

image = models.ImageField(upload_to='/home/site/mysite/images/
gallery')

"mysite" being the base level directory for the site itself


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



How to create middleware that adds context variables?

2008-12-27 Thread Roy

Hi, anyone have any examples of the above?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



parametr selected="selected"

2008-12-27 Thread Buddy

Hi.

I want to have html-code:
3
I do try it with forms.py:

pos = (
(1,1),
(2,2),
(3,3),
)

field1 = forms.CharField( widget=forms.widgets.Select(choices=pos))

but I get strings which not have parametr selected="selected".
How need change it so as to get it?

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



Re: Problem with url tag

2008-12-27 Thread patrick91

Resolved, if I could say so :)

the problem was that I can't use reverse in forms.py 'cause is to
early for doing that :(
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Invalid block tag: 'get_comment_count'

2008-12-27 Thread Florian Lindner

Hello,

I'm trying to use the comment framework from Django 1.0.2.

I've followed all the steps in 
http://docs.djangoproject.com/en/dev/ref/contrib/comments/ 
  (added it to installed apps, added to urls.py and loaded in the  
template) but I get:

TemplateSyntaxError at /blog/1/
Invalid block tag: 'get_comment_count'

from:

{% get_comment_count for object as comment_count %}

object has just been created so probably no comment yet attached.

What could have went wrong there?

Thanks,

Florian

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Dynamic model field

2008-12-27 Thread sergioh

Maybe a better approach for this, can be override the save method for
your model and also exclude that field on your forms.

Actually there is a post from James Bennett at:
http://www.b-list.org/weblog/2008/dec/24/admin/

hope it helps,

regards,

Sergio Hinojosa

On Dec 26, 6:32 pm, eldonp2  wrote:
> I'm writing a library app - would like to find out if it is possible
> to have a dynamically updating (returndate) field in a model?
>
> class Loan...
> ...
>   borrowdate = models.DateTimeField(auto_now_add = True)
>   returndate = models.DateTimeField(timediff(borrowdate+ timedelta
> (days=2))
> ...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Traceback in the ``runserver`` console

2008-12-27 Thread Russell Keith-Magee

On Sat, Dec 27, 2008 at 2:32 AM, Fridrik Mar Jonsson  wrote:
>
> Hi Djangonians,
>
> I recently had an instance where it would have been really convenient
> to see the error and a traceback in the ``runserver`` console instead
> of just a single line telling me that the request returned a 500
> error.
>
> In the event of blind debugging, where a 3rd party tool is performing
> a request that renders in an error, is there a Django mechanism or
> extension that allows you to catch any exceptions that occur during a
> page load and redirect them to the ``runserver`` console in addition
> to displaying them in the template?

There are two options I can think of on an unmodified Django install.

Firstly, write a middleware that implements process_exception(). This
middleware will get invoked whenever an exception is raised as part of
the view; the middleware method will be the exception as one of the
arguments.

http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception

Secondly, write a listener for the got_request_exception signal. This
signal is fired whenever an exception other than 404, Permission
Denied, or SystemExit is raised.

http://docs.djangoproject.com/en/dev/ref/signals/#django.core.signals.got_request_exception

> For an optimistic moment I thought ``--traceback`` was a bit
> promising, but then it turned out that it doesn't really seem to do
> what I expected in the case of ``runserver``.  I even considered
> switching to e-mail tracebacks but ended up writing a client to mimic
> the 3rd party tool's functionality instead.

When I read this I went and had a look at the code, and it appears you
are correct. ``--traceback`` exists as a top-level command option, but
it doesn't appear to be exploited at all in runserver. This actually
surprised me - it seems like a reasonable suggestion for an
improvement. Feel free to open this as a ticket (and if you're really
adventurous, work on a patch :-)

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



Re: Calculate and store the average rating

2008-12-27 Thread Russell Keith-Magee

On Sat, Dec 27, 2008 at 7:48 AM, eldonp2  wrote:
>
> Is there a way to calculate and store the average rating in this
> example:

It's not entirely clear which part of this problem you want help with.

 - Computing the average rating. The brute force approach would be to
iterate over the relevant related objects and compute an average. A
smarter approach would be to use SQL to compute the average.

 - Storing the average in the related model. This could be as simple
as saving an instance of the BookRatings model after computing the
average. You could also use signals or save() overriding to automate
the update of the BookRatings model.

 - Model design. It's not entirely clear why you would want to
denormalize the average values, and then put them into a separate
model.

If you provide a better description of the problem you want help with,
what you have already tried, and what problems you have experienced,
we may be able to provide a more meaningful answer to your problem.

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



Re: How do I make Django evaluate a ForeignKey for json serialization?

2008-12-27 Thread Russell Keith-Magee

On Sat, Dec 27, 2008 at 2:11 PM, adambossy  wrote:
>
> I have a model that refers to a ForeignKey, e.g.:
>
> class Template(models.Model):
>  type = models.ForeignKey(Type)
> ...
>
> class Type(models.Model)
>  name = models.CharField(max_length=32)
> ...
>
> I can fetch these objects fine using the model API.
>
> t = Template.objects.get(id=1)
> print t.type
>>> 
> print t.type.id
>>> 3
> print t.type.name
>>> TemplateType3
>
> If I serialize these, I cannot get 'name.' I know Django lazily
> retrieves these, but even by iterating or calling t.type.name, they
> are unavailable during serialization. Is there any way to have Django
> evaluate the ForeignKey object so that I can retrieve the field,
> 'name?' I need fields to contain "name": "TemplateType3" (or whatever
> it may be)! :)
>
> from django.core import serializers
> print serializers.serialize('json', Template.objects.get(id=1))
>
>>> {
>"pk": 1,
>"model": "template",
>"fields": {
>"type": 3
>}
>},
>

It isn't entirely clear what you're trying to do. Do you want to
change the Django serializers so that they output:

  "type": "TemplateType3"

If this is the case, then you will need to write your own serializer.
Django serializes objects in a specific way, optimized for
deserialization later on as fixtures. This output format won't suit
many applications. If you need a different format, you will need to
write a serializer that outputs in the format you require. Django
ships with SimpleJSON, so you can build serialized output from
primitives if need be. You could also use Django's serialization
library to write your own serializer that outputs in a format of your
choice. If your desired output format is similar to Django's default
format, you may find that you can use django/core/serializers/json.py
as a starting point for this implementation.

Alternatively, are you trying to manipulate a deserialized object in
some way? If this is the case, you will need to provide more specific
details on what it is you are trying to achieve.

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



Re: django i18n for google

2008-12-27 Thread Alessandro Ronchi
Il 16 dicembre 2008 19.20, Alessandro Ronchi
 ha scritto:
> When google spiders our i18n translated django websites, does it try
> and indicize all languages? is it possible to force the language by a
> GET var (for example &language_code=en) ?

I think it's a critical problem.

We spend time to make our i18n websites but google bot don't see other
languages except default.  Is there a way to select language with a
get url? Any other solution?


-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: enumerate in templates

2008-12-27 Thread Alex Koshelev
{% for %} itself

On 12/27/08, Vicky  wrote:
>
> Is there a way to access the previous value of a for loop in
> templates. Can anyone tell the template representation for the python
> code like:
>
>  for i,j in enumerate(item):
> ...
> >
>


-- 
---
Александр Кошелев
daeva...@gmail.com

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



enumerate in templates

2008-12-27 Thread Vicky

Is there a way to access the previous value of a for loop in
templates. Can anyone tell the template representation for the python
code like:

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



Re: Getting value of field from form.

2008-12-27 Thread Antoni Aloy

2008/12/27 evenrik :
>
> So I need to display the data for a form field from the post or from
> the instance if no post.  This works but I am hoping there is a better
> way:
>
> {% if form.is_bound %}
>{{ form.data.foo }}
> {% else %}
>{{ form.instance.foo }}
> {% endif %}
>
> Any suggestions?

I not fully understant what you're trying to do, but with the initial
parameter on the form instance you have the chance to prepopulate the
form with data which is not going to be validated at that moment. So
on the template it's just a matter to write {{form}}

Hope it helps!

-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---