Re: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
Thanks for the suggestion, but the US is not really an option, social- and 
economic security wise and also the distance back to the Netherlands. I'd 
like to be able to afford a flight back to friends and family more then once 
or twice a year :)

Pretty much the same goes for Chile or Argentina. It's just too far away, 
and a bit too extreme a change for me.

Also, I'm happy to report that I got two serious job offers by mail, both 
for Python/Javascript jobs in Reykjavik. Starting my own company up north, 
as someone suggested, is definitely plan b. I would prefer a stable income 
though, so I hope these jobs turn out to be good options.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/RcVmZb98Pg0J.
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: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
I don't think many people will ever understand why I'd want to move to the 
Arctic region. But, I really don't understand how many people would like to 
live in Spain, France or Italy. Me, I like long, cold winters with lots of 
snow. I don't like hot summers. I'm just weird I guess :)

Reykjavik and Tromsø are not that cold by the way. Reykjavik has an average 
low of minus 3 in january, Tromsø minus 7.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/I00h3_up_a8J.
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: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
Finding a position in The Netherlands would be SUPER easy. The problem is 
that I want to immigrate to another country :) Remote working from The 
Netherlands is not what I am looking for.


On Friday, September 30, 2011 2:51:28 PM UTC+2, SleepyCal wrote:
>
> Hmm - CCP would have been a very good company to get in with :/
>
> I'm surprised you have not found any other decent positions in Nederland 
> tbh. 
>
> BoxedIce (owners of ServerDensity) are always on the look out for new 
> developers, they offer remote working, and they already have staff in 
> Nederland.
>
> Hope this helps.
>
> Cal
>
> On Fri, Sep 30, 2011 at 1:47 PM, Kevin Renskers <in...@bolhoed.net> wrote:
>
>> CCP actually wanted me for their UI Programmer position. Did the first 
>> round of interviews, made a usability report for them, all was well. And 
>> then they decided that they don't really need a UI Programmer after all :(
>>
>> Their other positions are not really a great match for me, sadly. Too much 
>> C++, DirectX, GPU stuff, etc.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/1PqrbM7SjkoJ.
>>
>> To post to this group, send email to django...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_OtQN-CLLLEJ.
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: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
Awesome, thanks!

On Friday, September 30, 2011 2:44:45 PM UTC+2, Sumod wrote:
>
> http://www.arcticstartup.com/
>
>
>
> On Fri, Sep 30, 2011 at 6:09 PM, Kevin Renskers <in...@bolhoed.net> wrote:
>
>> Ha, yeah I know that Iceland is not in the Arctic Circle, strictly 
>> speaking. Maybe I should've said the Arctic Circle region. 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/oe7TEqSVgMkJ.
>>
>> To post to this group, send email to django...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> http://spawgi.wordpress.com
> We can do it and do it better.
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Hb5_PgosefIJ.
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: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
CCP actually wanted me for their UI Programmer position. Did the first round 
of interviews, made a usability report for them, all was well. And then they 
decided that they don't really need a UI Programmer after all :(

Their other positions are not really a great match for me, sadly. Too much 
C++, DirectX, GPU stuff, etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/1PqrbM7SjkoJ.
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: Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
Ha, yeah I know that Iceland is not in the Arctic Circle, strictly speaking. 
Maybe I should've said the Arctic Circle region.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oe7TEqSVgMkJ.
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.



Looking for a job in the Arctic Circle

2011-09-30 Thread Kevin Renskers
Hi all,

I am a Senior Python/Django programmer from The Netherlands, and I am on a 
quest to move to the Arctic Circle. Right now my focus is on Reykjavik in 
Iceland and Tromsø in Norway. It's quite hard to find jobs in these regions, 
and it's even harder because I don't have a network of people I know in the 
Arctic.

I know it's a long shot, but I am hoping someone on this group knows someone 
else, and they work at a company that could use a programmer, something like 
that :)

My linkedin account with my skills and experience: 
http://nl.linkedin.com/in/kevinrenskers
My twitter account where I write about my quest: 
http://www.twitter.com/movetoarctic

I also do Javascript and iPhone/Mac development, and have 9 years of 
experience in PHP.

Thanks!

Kevin

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



Re: Form wizard

2011-06-22 Thread Kevin Renskers
The documentation 
on https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/ 
is pretty clear. The part where you're going in the wrong direction is the 
url config. Compare 
with 
https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/#hooking-the-wizard-into-a-urlconf.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/X-XnjUzTYWoJ.
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 EmailMultiAlternatives with Embadded Image in HTML

2011-06-22 Thread Kevin Renskers
If I google on "django html email inline image" I see multiple solutions. 
None of them worked? Seems unlikely to me...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9Q_5CSN5U2kJ.
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: Is multiple inheritance with abstract model classes ok?

2011-06-22 Thread Kevin Renskers
Perfectly fine!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6Vp_0w_sz_cJ.
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: WMD-editor: Where's wmd/urls.py?

2011-06-22 Thread Kevin Renskers
I think it's an error in the documentation. Since there are no views, it's 
probable that there are no urls as well.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/K66nLy6n6ZAJ.
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: set language from user lang in DB?

2011-06-22 Thread Kevin Renskers
from django.utils import translation
translation.activate(language_code)

See 
also 
http://stackoverflow.com/questions/2336785/set-language-within-a-django-view

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Y2tU6X3sIdAJ.
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 display form data with original values after validation failure?

2011-06-22 Thread Kevin Renskers
If I understand this correctly, then you want something like this?

1) Show a form to edit something
2) User changes fields, submits the form
3) If the form was not valid, not only show the errors and the form with the 
entered values, but also the *old* values, pre-edit.

I think your best bet is to create custom valid_field() validation functions 
in the form class, which access the form instance to show the old values in 
the error message.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Rd8Asi1bGNAJ.
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: updating a user form?

2011-06-22 Thread Kevin Renskers
I'd advise you to 
read 
https://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-information-about-users.
 
So, create a separate model for the profile, which can be edited by the user 
once he is logged in.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VWn5hNS6tXkJ.
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: csrf token driving me crazy

2011-06-22 Thread Kevin Renskers
The documentation about CSRF and AJAX was already 
linked: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax

The note about backwards incompatibility can be found 
here: 
https://docs.djangoproject.com/en/1.3/releases/1.3/#csrf-validation-now-applies-to-ajax-requests

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Kl77ZIVjILQJ.
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: Generic views v.s. shortcuts

2011-03-23 Thread Kevin Renskers
Hi Andre,

Well, it would be much easier if get_context_data only needs to return a 
dictionary. Guess I'll build my own class for that :) 

But apart from that, my real question is why there are generic views *and* 
shortcut functions. Which is recommended in which case?

Cheers,
Kevin

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



Generic views v.s. shortcuts

2011-03-23 Thread Kevin Renskers
Hi,

I am wondering why Django 1.3 has both class-based generic views (like 
TemplateView and RedirectView) and shortcuts like django.shortcut.render and 
django.shortcut.redirect. What is the recommended way to write your views? 
Is a call to render() from within your own view function better then using 
TemplateView, or visa versa? It certainly looks easier...

As a rule I never used generic views directly from urls.py, I always created 
a view function. So it seems that for me, I could just replace 
direct_to_template with render and I'm done.

Old:

def home(request):
return direct_to_template(request, template='home.html', 
extra_context={'foo': 42,'bar': 37})

New:

def home(request):
return render(request, template='home.html', dictionary={'foo': 
42,'bar': 37})

Or the alternative:

class Home(TemplateView):
template_name = 'home.html'

def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
context.update({
'foo': 42,
'bar': 37
})
return context

In the last case, I also have to change my urls config to now use 
Home.as_view(), which needs to be imported, etc. Seems like a lot of code 
and repeating myself.

Thanks,
Kevin

-- 
You received this message because you are subscribed to the Google 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: Input welcome for comments app idea

2010-11-13 Thread Kevin Renskers
A first version has been committed to Bitbucket:
http://bitbucket.org/bolhoed/django_disqus_comments/

Showing your Disqus comments from your templates works, saving them
still needs to be done. Also, getting the comments from code does not
work yet, which breaks (for example) django-blog-zinnia's admin site
where they show the number of comments per blog entry.

If people are interested in this project, feel free to clone the
project, send me a message, etc.

Cheers,
Kevin


On Nov 12, 12:14 pm, Kevin Renskers <i...@bolhoed.net> wrote:
> Hi,
>
> My new Django website is as good as finished, I only have to work on
> the comments section. I know about the comments app that ships with
> Django, but I don't really like it that much. I see three options for
> comments on my website:
>
> 1) Use something like django-threadedcomments
> 2) Use Disqus or IntenseDebate
> 3) Implement my own COMMENTS_APP that extends the default Django
> comments app
>
> Option one doesn't make it a whole lot better. There is still no way
> to register, login, do good spam checking, moderation, delete your own
> comments, etc. At least not without a lot of work.
>
> Option two, use Disqus, is what I used to do on my old website. Drop
> in some javascript, and you're done. However, with django-blog-zinnia
> running the blog, there are advantages when using Django's comments
> app: they show up in the admin interface, you can get the most popular
> blog entries (by comment count), no need for javascript just to show
> how many comments an article got, etc. So that brings me to option
> three:
>
> Disqus offers a REST api. So in theory it should be possible to write
> my own comments app that extends Django's default comments app. That
> way you use all the power of Disqus, and Django's comment system still
> uses the same functions to get comments, so all admin/zinnia functions
> should still work. It just doesn't use your database to get the
> comments, instead making the calls to Disqus.
>
> Some problems I see:
> - If you call the Disqus API from Python functions, it's not a-
> synchronous. So displaying a template would be slower. Even the admin
> would be slower, because the number of comments are shown in the blog
> entries list. However, this could of course be cached, making this
> almost a non-issue.
> - The user needs to be logged in to Disqus to be able to post a
> comment. It would be great if the comments came from my comments app,
> but the form for posting a new comments came from Disqus (using the
> standard javascript "api"). As far as I can see, this is not possible,
> so logging in and getting the user's key could be difficult?
>
> I am kind of stunned that an app like this doesn't already exists. Am
> I missing something? Or is everyone okay with using the javascript way
> of including Disqus? Also, I think this would be quite a lot of work
> to make, so before I start hacking away, I am wondering if this really
> doesn't already exists, and if I am overlooking other big problems.
>
> Thanks in advance for your input,
> Kevin

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



Input welcome for comments app idea

2010-11-12 Thread Kevin Renskers
Hi,

My new Django website is as good as finished, I only have to work on
the comments section. I know about the comments app that ships with
Django, but I don't really like it that much. I see three options for
comments on my website:

1) Use something like django-threadedcomments
2) Use Disqus or IntenseDebate
3) Implement my own COMMENTS_APP that extends the default Django
comments app

Option one doesn't make it a whole lot better. There is still no way
to register, login, do good spam checking, moderation, delete your own
comments, etc. At least not without a lot of work.

Option two, use Disqus, is what I used to do on my old website. Drop
in some javascript, and you're done. However, with django-blog-zinnia
running the blog, there are advantages when using Django's comments
app: they show up in the admin interface, you can get the most popular
blog entries (by comment count), no need for javascript just to show
how many comments an article got, etc. So that brings me to option
three:

Disqus offers a REST api. So in theory it should be possible to write
my own comments app that extends Django's default comments app. That
way you use all the power of Disqus, and Django's comment system still
uses the same functions to get comments, so all admin/zinnia functions
should still work. It just doesn't use your database to get the
comments, instead making the calls to Disqus.

Some problems I see:
- If you call the Disqus API from Python functions, it's not a-
synchronous. So displaying a template would be slower. Even the admin
would be slower, because the number of comments are shown in the blog
entries list. However, this could of course be cached, making this
almost a non-issue.
- The user needs to be logged in to Disqus to be able to post a
comment. It would be great if the comments came from my comments app,
but the form for posting a new comments came from Disqus (using the
standard javascript "api"). As far as I can see, this is not possible,
so logging in and getting the user's key could be difficult?

I am kind of stunned that an app like this doesn't already exists. Am
I missing something? Or is everyone okay with using the javascript way
of including Disqus? Also, I think this would be quite a lot of work
to make, so before I start hacking away, I am wondering if this really
doesn't already exists, and if I am overlooking other big problems.

Thanks in advance for your input,
Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Raw sql bug? Or am I doing something wrong?

2010-06-01 Thread Kevin Renskers
Update: weirdly enough, this does work:

for r in Model.objects.raw('SELECT model.* FROM model INNER JOIN
othermodel ON othermodel.model_id = model.id'):
print r

But model.id does not.

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



Raw sql bug? Or am I doing something wrong?

2010-06-01 Thread Kevin Renskers
Hi,

I love the new raw() function to write custom sql and get back ORM
objects. However, when using joins, things get weird.

As long as you use "select *", everything works fine:

for r in Model.objects.raw('SELECT * FROM model INNER JOIN othermodel
ON othermodel.model_id = model.id'):
print r

However, this can result in a LOT of columns that you don't need, and
possible duplicate column names.

Solution would seem to be this:

for r in Model.objects.raw('SELECT model.id, model.name FROM model
INNER JOIN othermodel ON othermodel.model_id = model.id'):
print r

Sadly, this doesn't work. I get an "type() argument 1 must be string,
not unicode" error from django/db/models/query_utils.py in
deferred_class_factory, line 274.

Is there another way to get this to work? The "id" column is required
for the raw() function to work, but just using "id" doesn't work
because othermodel also has an "id" column. Using "model.id" gives the
error. I also tried "model.id AS id", but same error.

Or is this a bug that I should put in trac?

Thanks,
Kevin

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

2010-04-27 Thread Kevin Renskers
Works like a charm, thanks!

> The issue with the custom field is that it does not implement a
> 'validate' func
>
> I believe all I did to get it working was add:
>
>     def validate(self, value, model_instance):
>         return

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

2010-04-26 Thread Kevin Renskers
I also used the multiple select field found on 
http://www.djangosnippets.org/snippets/1200/
with success, until I updated Django to the 1.2 beta release. It now
longer works, always giving the validation error. I have no clue how
to fix this, so I was hoping you found the answer to your problem and
can share it?

I have a tuple with (string, not integer) choices, and want to show
the user a multiple select field. The choices should be saved as a
comma separated string in the database.

Cheers,
Kevin

On Apr 3, 5:30 pm, ben  wrote:
> Either I don't understand how CheckboxSelectMultiple works or there is
> a bug in Django 1.2. I have tried the following custom multi select
> fields I have found around the web.
>
> http://www.djangosnippets.org/snippets/1200/http://www.davidcramer.net/code/181/custom-fields-in-django.html
>
> Out of desperation I tried using a ManyToMany field and all produce
> the same validation error when used with either CheckboxSelectMultiple
> or SelectMultiple.
>
> 'Select a valid choice. [u'1', u'2', u'3', u'4'] is not one of the
> available choices.'
>
> This happens regardless of the number of choices, types of the choices
> tuple values, or the model field type.
>
> Can anyone point me to an example that demonstrates how to properly
> use these fields.
>
> Thanks,
> Ben
>
> On Apr 2, 5:19 pm, Bill Freeman  wrote:
>
>
>
> > I know that I used (some revision of) that snippet a while back.
>
> > Realize that what it stores is a string, containing digits and commas.
>
> > The to_python and get_db_prep_value methods are responsible for
> > converting between that database single string and a list of strings,
> > not integers.  You can use any string (that doesn't contain comma) to
> > represent a choice (db value).  I had two character ID flags (easier to
> > read in pgadmin).  It did work, but I forget the details (I eventually went
> > to multi to multi and the one end of many to one relationships).  So I
> > expect that the DB side of your choice tuples must be strings.
>
> > Bill
>
> > On Fri, Apr 2, 2010 at 3:37 PM, ben  wrote:
> > > Sorry. I pasted code that I was experimenting with. I thought maybe
> > > the validation code was looking for strings because that is what the
> > > error code said it was looking for. Before that I had been using
> > > integers and that doesn't seem to work either. I am wondering if this
> > > is a bug in Django 1.2. I hunted around on Django snippets as Bill
> > > Freeman suggested and found the following 
> > > codehttp://www.djangosnippets.org/snippets/1200/
> > > for a custom multiple selection field.
>
> > > I inserted it into my app and it doesn't want to validate the
> > > selection either. In fact it returns a validation error message
> > > similar to what I received from CommaSeperatedIntegerField and
> > > CheckboxSelectMultiple. "Value [u'1'] is not a valid choice."
>
> > > Not sure what is going on. Any insights would be appreciated.
>
> > > On Apr 2, 3:06 pm, orokusaki  wrote:
> > >> The problem is that you're using '1' instead of 1. The comma
> > >> separated integer list is expecting integers not strings. The reason
> > >> you're seeing u'1' is because it's being turned from a string to a
> > >> unicode object.
>
> > >> Try this instead:
>
> > >> SOME_CHOICES =  ((1, 'ch1'),(2, 'ch2'), (3, 'ch3'),(4, 'ch4'))
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Primary key in queryset even when using only()

2010-03-22 Thread Kevin Renskers
Thank you very much, this works perfectly!

On Mar 22, 12:01 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 22 mar, 11:08, Kevin Renskers <i...@bolhoed.net> wrote:
>
> > Hi,
>
> > I am using a combination of the only() and distinct() functions on a
> > model to get the unique values of one column. Sadly, the only()
> > function also includes the primary key (even though I only give one
> > column name), which has the effect that all rows are seen as unique.
>
> only() is only (no pun) a complement to defer() - it still loads the
> Model instances, so you'll indeed have the primary key included.
>
> The method you want is values_list:
>
>
>
>
>
> >> results = YourModel.objects.values_list('power_meter', 
> >> flat=True).distinct()
> > This is the result I want:
> > power_meter
> > 1
> > 2
> > 3
>
> > This is the result I get:
> > id      power_meter
> > 80      1
> > 81      1
> > 82      1
> > 83      2
> > 84      2
> > 85      3
> > 86      3
>
> > So I am wondering why the primary key is included in the query, even
> > though I used only('power_meter') in my query.
>
> cf above. Querysets default behaviour is to yield Model instances -
> not raw data -, and Model instances neeed to have their primary key
> loaded to work correctly. If you want raw data, use either values() or
> values_list()
>
> HTH

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



Primary key in queryset even when using only()

2010-03-22 Thread Kevin Renskers
Hi,

I am using a combination of the only() and distinct() functions on a
model to get the unique values of one column. Sadly, the only()
function also includes the primary key (even though I only give one
column name), which has the effect that all rows are seen as unique.

This is the result I want:
power_meter
1
2
3

This is the result I get:
id  power_meter
80  1
81  1
82  1
83  2
84  2
85  3
86  3

So I am wondering why the primary key is included in the query, even
though I used only('power_meter') in my query. I could just do a GROUP
BY, but alas, that's impossible with the ORM...

I am not using an ORDER BY, so that should not be the reason the
primary key is included.

Thanks,
Kevin Renskers

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

2010-03-05 Thread Kevin Renskers
For those interested:

In my base template I've added this:

{% load custom_tags %}
{% if form %}
{% formerrors request form %}
{% endif %}

In my custom_tags template tags library:

@register.simple_tag
def formerrors(request, form):
for field, errors in form.errors.items():
for error in errors:
if field == '__all__':
messages.error(request, error)
else:
messages.error(request, field+': '+error)

return ''


Works perfectly for me: now all form errors are shown in exactly the
same way as all other messages in my application.

Cheers,
Kevin


On Mar 4, 4:33 pm, Kevin Renskers <i...@bolhoed.net> wrote:
> I'll explain a bit more what precisely it is what I want to do: Django
> 1.2 comes with a new messages framework that allows for each message
> to have a different "level" (succes, error, warning, etc). I want to
> see if a form has errors, and if so, make a message for each error so
> all my notices and errors are displayed in the same way in my
> application.
>
> But I think I just came up with a solution: make a new template tag in
> my base template, always give it the form variable (whether it exists
> or not), and from there create the new messages.

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

2010-03-04 Thread Kevin Renskers
I'll explain a bit more what precisely it is what I want to do: Django
1.2 comes with a new messages framework that allows for each message
to have a different "level" (succes, error, warning, etc). I want to
see if a form has errors, and if so, make a message for each error so
all my notices and errors are displayed in the same way in my
application.

But I think I just came up with a solution: make a new template tag in
my base template, always give it the form variable (whether it exists
or not), and from there create the new messages.

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

2010-03-04 Thread Kevin Renskers
Well yes, but I do not want to change all of my views. I want a
generic solution to change template variables before they get
rendered.


On Mar 4, 4:14 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> Write your own view instead of using direct_to_template.
>
>
>
> On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers <i...@bolhoed.net> wrote:
> > Hi,
>
> > I am wondering if it is possible to change template variables before
> > they get rendered in a template.
>
> > For example, I use something like this in my template:
> > return direct_to_template(request, template='index.html',
> > extra_context={'form':form})
>
> > I would like to extend this form variable before the index.html
> > template gets rendered.
>
> > My first though was making a template context processor, but I can't
> > seem to be able to access template variables from it. My next thought
> > was creating a piece of middleware with a process_response function,
> > but also from this function it seems impossible to access the template
> > variables.
>
> > Anyone got an idea on how to do this?
>
> > Thanks in advance,
> > Kevin
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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

2010-03-04 Thread Kevin Renskers
Hi,

I am wondering if it is possible to change template variables before
they get rendered in a template.

For example, I use something like this in my template:
return direct_to_template(request, template='index.html',
extra_context={'form':form})

I would like to extend this form variable before the index.html
template gets rendered.

My first though was making a template context processor, but I can't
seem to be able to access template variables from it. My next thought
was creating a piece of middleware with a process_response function,
but also from this function it seems impossible to access the template
variables.

Anyone got an idea on how to do this?

Thanks in advance,
Kevin

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

2009-12-29 Thread Kevin Renskers
First of all, in your template include jQuery:
http://ajax.googleapis.com/ajax/</a>
libs/jquery/1.3/jquery.min.js">

Create a new javascript file, and put the following code in it:

// This is automatically run when the document has been completely
loaded
$(function() {
// Find all tr's in your table (give your table an id)
$('#your_table_id tr').each(function() {
// Give your tr's an id like {{v.publisher_id}}_
{{v.country_id}}
// We now split that id on the underscore and get the parts we
need.
temp = this.id.split('_');
publisher_id = temp[0];
country_id = temp[1];

// Call your function however you like
showDomainTable(publisher_id, country_id);
});
});

Include this new javascript in your template too, and give your table
an id.
This code is just from the top of my head, but it should work alright.


On Dec 28, 11:24 pm, "gilbert F." <gilber...@gmail.com> wrote:
> Hi Kevin,
>
> Sorry I could not make progress therefore I am considering to use
> jQuery. As I never used it, can I have your jQuery code for reference?
> You may send to my e-mail gilber...@gamil.com
>
> Thanks so much.
>
> On Dec 28, 9:19 am, "gilbert F." <gilber...@gmail.com> wrote:
>
> > Hi Kevin,
>
> > Thanks so much for your replies. Following your suggestions I have
> > moved tag  out of <tr>.
>
> > <tr class="odd" id="{{v.publisher_id}}">
> >   <script type="text/javascript">
> >     showDomainTable('{{v.publisher_id}}', '{{v.country_id}}');
> >   
> > 
>
> > Sorry I do not know jQuery. For the moment let me follow your
> > suggestions and move forward. If I can not succeed then I will
> > consider jQuery.
>
> > Thanks again. Appreciated.
>
> > On Dec 28, 2:31 am, Masklinn <maskl...@masklinn.net> wrote:
>
> > > On 28 déc. 2009, at 10:26, Kevin Renskers <i...@bolhoed.net> wrote:
>
> > > > But even then, inline javascript is something better avoided.
>
> > > Especially, in this case, because there is no garantee whatsoever that  
> > > the element has already been created and added to the document's DOM.- 
> > > Hide quoted text -
>
> > - Show quoted text -
>
>

--

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

2009-12-28 Thread Kevin Renskers
What you are doing is not valid html, you can't put a script tag
inside a tr tag. Try something like this:


  
showDomainTable('{{v.publisher_id}}', '{{v.country_id}}');
  


But even then, inline javascript is something better avoided. I would
just create a function that is run as soon as the document is loaded,
find all tr's inside your table, and use their id's to call your
showDomainTable function. If you also need the country id, something
like this could work:



And then in your javascript code just split on the underscore.

I have no clue if you know jQuery? But this would be very easy if you
would use jQuery. If you need it, I could give you some mockup code to
help you along.


On Dec 27, 7:42 pm, "gilbert F."  wrote:
> Hello,
>
> I just wonder if somebody has met this problem. I need to call a
> javaScript function within "".
>
>                       {% for v in data %}
>                              id="{{v.publisher_id}}"
>                                      language="JavaScript">
>                                         showDomainTable
> ('{{v.publisher_id}}', '{{v.country_id}}');
>                                     
>                             >
>
> This works well with Firebox but not with IE 8. IE just prints
> "showDomainTable(...)" instead of calling it.
>
> Any help? Thanks so much.

--

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

2009-12-28 Thread Kevin Renskers
I am using http://code.google.com/p/python-twitter/ on my own Django
website, works like a charm. Are you sure you are using the API
correctly?

api.PostUpdate(username, password, 'I love python-twitter!')

By the way, updating a tweet is impossible, as Twitter doesn't support
that. You can delete and insert a new one though.


On Dec 27, 10:15 pm, Mario  wrote:
> Thank you for you suggestions. Btw, I created a mocked-up app and was
> testing the functionality of the python-twitter.  I read the docs as
> posted athttp://media.jesselegg.com/syncr/syncr.app.tweet.html.
>
> I did a small unit testing and could see the results immediately, but
> I could not create or update a twitt via Django. As I pointed out in
> my early email, I want to create/update/delete a twitt in django in
> lieu of the Twitter front-end.
>
> I guess my choices at this point in time are either:
>
> 1. Twyt
> 2. Write a wrapper within the model.
>
> Thanks again. _Mario
>
> _Mario
> On Dec 27, 3:37 pm, Christophe Pettus  wrote:
>
> > On Dec 27, 2009, at 12:31 PM, Mario wrote:
>
> > > Thank you for replying. Yes, I reviewed python twitter API, but the
> > > model or the app is designed to pull down the "twitt". I would like to
> > > upload a twitt via Django in lieu of using the Twitter front-end. Any
> > > thoughts or suggestions?
>
> > Perhaps I'm misunderstanding your issue, but the code running in  
> > Django is just Python.  There's nothing magic about it.  If you want  
> > your view functions to access Twitter via a Python Twitter API, it's  
> > no problem to do so; you can also wrap your calls to Twitter inside of  
> > a Model class, if that's a better fit.
>
> > --
> > -- Christophe Pettus
> >     x...@thebuild.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-us...@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 Meta inner class accessing its parent

2009-12-18 Thread Kevin Renskers
Thanks for the information, I will look into your suggestions. The
getLanguage design did seem to work though, as changing the language
did have an effect on the __unicode__ function: in the admin interface
the correct values (for that language) were shown. At least it did so
on the local runserver environment. I can see though that even though
__unicode__ is called every time, the ordering is probably called only
at import time, and my little plan won't work.

Have to find a solution for that problem first I guess, before I even
start to tackle the problem of how to set the ordering...


On Dec 18, 5:00 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> I can't promise that it will do what you want, but your problem is
> that at the time
> you try to set the value of Meta.ordering, class Substrate does not yet exist.
> You can dig into the Substrate.objects._meta later to add ordering, probably.
>
> Your design wouldn't have worked anyway, since getLanguage would only
> have been called once, at import time, and even if that worked, it wouldn't
> follow current language as it changes (I presume) from request to request.
>
> Oh, and since you're not calling getLanguage on a class instance, it would
> have to be declared a staticmethod or classmethod, and not get the self
> argument or replace it with cls (for classmethod).  Static method would be
> the choice here (and no self)
>
> It's mildly possible that ordering is allowed to be a callable.  If
> so, you could
> assign it to a function (not a method of the not yet defined Substrate).  
> That's
> the function itself, no parentheses.  The function would return the list.
>
> If ordering can't be a callable, you could create a class that implements 
> enough
> of list behavior to satisfy the framework (a subject for research or
> experimentation,
> but iteration might be enough) and set ordering to an instance, whose apparent
> content depends on the current language.
>
> It still might not work, if the __metaclass__ processes Meta.ordering at clas
> definition time.  You have the source code.
>
> Bill
>
> On Fri, Dec 18, 2009 at 6:07 AM, Kevin Renskers <i...@bolhoed.net> wrote:
> > Hi,
>
> > I am having a bit of a problem. I have a model with 3 name fields,
> > each for a different language. By creating an __unicode__ function
> > like below, I always get the correct name for the current language.
> > Works fine.
>
> > But, I want to change the default ordering for this model, so that in
> > each language, the correct order is used. Sadly, this doesn't work, as
> > I get the error "NameError: name 'Substrate' is not defined". Also
> > "self" and "super" don't seem to work. I just can't seem to be able to
> > access the parent class from within the Meta class.
>
> > I can't even repeat the getLanguage function into the Meta class,
> > because then I get an the error "TypeError: 'class Meta' got invalid
> > attribute(s): getLanguage".
>
> > class Substrate(models.Model):
> >    name_en = models.CharField(max_length=255)
> >    name_de = models.CharField(max_length=255, blank=True)
> >    name_nl = models.CharField(max_length=255, blank=True)
>
> >    def getLanguage(self):
> >        from django.utils import translation
> >        current_language = translation.get_language()
> >        if not current_language:
> >            current_language = 'en'
> >        return current_language
>
> >    def getName(self):
> >        current_language = self.getLanguage()
> >        name = getattr(self, 'name_'+current_language, self.name_en)
> >        if not name:
> >            name = self.name_en
>
> >        return name
>
> >    def __unicode__(self):
> >        return self.getName()
>
> >    class Meta:
> >        ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']
>
> > If anyone has an idea how on to do this, I would be very happy.
> > Thanks!
>
> > Cheers,
> > Kevin
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

--

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




Problem with Meta inner class accessing its parent

2009-12-18 Thread Kevin Renskers
Hi,

I am having a bit of a problem. I have a model with 3 name fields,
each for a different language. By creating an __unicode__ function
like below, I always get the correct name for the current language.
Works fine.

But, I want to change the default ordering for this model, so that in
each language, the correct order is used. Sadly, this doesn't work, as
I get the error "NameError: name 'Substrate' is not defined". Also
"self" and "super" don't seem to work. I just can't seem to be able to
access the parent class from within the Meta class.

I can't even repeat the getLanguage function into the Meta class,
because then I get an the error "TypeError: 'class Meta' got invalid
attribute(s): getLanguage".

class Substrate(models.Model):
name_en = models.CharField(max_length=255)
name_de = models.CharField(max_length=255, blank=True)
name_nl = models.CharField(max_length=255, blank=True)

def getLanguage(self):
from django.utils import translation
current_language = translation.get_language()
if not current_language:
current_language = 'en'
return current_language

def getName(self):
current_language = self.getLanguage()
name = getattr(self, 'name_'+current_language, self.name_en)
if not name:
name = self.name_en

return name

def __unicode__(self):
return self.getName()

class Meta:
ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']



If anyone has an idea how on to do this, I would be very happy.
Thanks!

Cheers,
Kevin

--

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




Make the makemessages command more open

2009-12-14 Thread Kevin Renskers
Hi,

I am using Jinja2 instead of the Django template system in a test
project. Everything is working fine, but I am running into a small
problem regarding i18n:

The command "django-admin makemessages" doesn't find the translation
strings, because the Jinja2 format differs from the Django format.

Django syntax:
{% trans "Hello" %}
{% blocktrans %}Hello{% endblocktrans %}

Jinj2 syntax:
{{ _('Hello') }}
{% trans %}Hello{% endtrans %}

The underscore syntax work fine, but the trans/endtrans doesn't: the
regular expressions used by makemessages don't account for a different
syntax. As far as I can see there is no possible way to configure the
system so it can work with different i18n syntaxes. It seems like a
good idea to open this up, so different template systems can be used
more easily.

Would it be a good idea suggest this in a ticket?

Cheers,
Kevin Renskers

--

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

2009-11-29 Thread Kevin Renskers
I am using the Google Visualization API myself, it's pretty nice. I
wrote a blog post with a little how to:
http://www.bolhoed.net/blog/using-the-google-visualization-api-in-django/
However, I also used FusionCharts in the past and that's got my vote
too :)

On Nov 25, 9:07 pm, "S.Selvam"  wrote:
> Hi all,
>
> This is my first post here andi  am new to django.
>
> I need to show some data as a chart.
>
> I would like to achieve a high quality rendering.
>
> Is reportlab or matplotlib enough ?
>
> I hope you can direct me on track.
>
> --
> Yours,
> S.Selvam
> Sent from Bangalore, KA, India

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
Hi Matthias ,

Thank you, I went for option 1 and it works perfectly!

Funny, the add_to_class function basically does "setattr(cls, name,
value)". So I had the right solution, only you have to do this after
class creation, not inside its __init__ function. Good to know, will
blog about this :)

Again, thank you very much.

Cheers,
Kevin


On Nov 26, 10:14 am, Matthias Kestenholz
<matthias.kestenh...@gmail.com> wrote:
> On Thu, Nov 26, 2009 at 9:56 AM, Kevin Renskers <i...@bolhoed.net> wrote:
> > Just a small update: the DynamicModels way as described on the wiki
> > doesn't work (it also says that it only works in Django 0.96, so
> > yeah..).
>
> > If anyone has any idea how to do this, I would be very thankful!
>
> > On Nov 24, 2:35 pm, Kevin Renskers <i...@bolhoed.net> wrote:
> >> Hi all,
>
> >> In my Django project I want to have a model that is dynamically
> >> created. I tried using the __init__ function for this,  something like
> >> so:
>
> >> fields = ['field_a', 'field_b', 'field_c']
>
> >> class MyModel(models.Model):
> >>     def __init__(self, *args, **kwargs):
> >>         for field in fields:
> >>             setattr(self, field, models.DecimalField(decimal_places=4,
> >> max_digits=10))
>
> >> Sadly, this doesn't work. The columns don't get created when you run
> >> the syncdb command, and even something like
> >> MyModel._meta.get_all_field_names() doesn't return the dynamic fields.
>
> >> So, is there a way I can create a "dynamic" model? I did come 
> >> acrosshttp://code.djangoproject.com/wiki/DynamicModelsbutI don't really
> >> get that. It looks so much different then normal models, it seems like
> >> I would loose a lot of functionality or would have to change a lot of
> >> code somewhere else in my application?
>
> >> Hopefully there is an easy way to do this :)
>
> I can see two ways to achieve what you seem to want:
>
> 1. Add fields after the model has been created
>
> This method uses an only unofficially documented feature[1] of
> Django's model field classes.
>
> class MyModel(models.Model):
>     # a few fields
>
> for field in fields:
>     MyModel.add_to_class(field, models.DecimalField(decimal_places=4,
> max_digits=10))
>
> 2. Construct a new type dynamically
>
> class Meta:
>     verbose_name = _('my model')
>
> attrs = {
>     '__module__': 'mymodule',
>     'Meta': Meta,
>     'method1': method1,
>     # ... more fields and methods
>
> }
>
> for field in fields:
>     attrs[field] = models.DecimalField(...)
>
> MyModel = type('MyModel', (models.Model,), attrs)
>
> Of course, the usual caveats apply. It might make your code harder to
> read and understand, and harder to debug too, because it is not clear
> what model fields exist by simply looking at the model code (that
> applies especially to method 1)
>
> Matthias
>
> [1]: It's documented in Marty Alchin's excellent Pro Django book. I
> think we can assume that this method won't go away without very good
> reasons(tm).

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
Just a small update: the DynamicModels way as described on the wiki
doesn't work (it also says that it only works in Django 0.96, so
yeah..).

If anyone has any idea how to do this, I would be very thankful!


On Nov 24, 2:35 pm, Kevin Renskers <i...@bolhoed.net> wrote:
> Hi all,
>
> In my Django project I want to have a model that is dynamically
> created. I tried using the __init__ function for this,  something like
> so:
>
> fields = ['field_a', 'field_b', 'field_c']
>
> class MyModel(models.Model):
>     def __init__(self, *args, **kwargs):
>         for field in fields:
>             setattr(self, field, models.DecimalField(decimal_places=4,
> max_digits=10))
>
> Sadly, this doesn't work. The columns don't get created when you run
> the syncdb command, and even something like
> MyModel._meta.get_all_field_names() doesn't return the dynamic fields.
>
> So, is there a way I can create a "dynamic" model? I did come 
> acrosshttp://code.djangoproject.com/wiki/DynamicModelsbut I don't really
> get that. It looks so much different then normal models, it seems like
> I would loose a lot of functionality or would have to change a lot of
> code somewhere else in my application?
>
> Hopefully there is an easy way to do this :)
>
> Cheers,
> Kevin

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: even and odd numbers within a template

2009-11-24 Thread Kevin Renskers
{% for o in some_list %}

...

{% endfor %}


On Nov 24, 2:39 pm, Juan Hernandez  wrote:
> Hey there people...
>
> I've been coloring html tables using javascript for a while and now, we need
> to color our tables just with html. The CSS has been made to use one color
> for even rows and another one for odds. How can I know if a current template
> loop is odd or even? I've been trying many different things and none of them
> work
>
> Thanx
> jhv

--

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




Creating dynamic models?

2009-11-24 Thread Kevin Renskers
Hi all,

In my Django project I want to have a model that is dynamically
created. I tried using the __init__ function for this,  something like
so:

fields = ['field_a', 'field_b', 'field_c']

class MyModel(models.Model):
def __init__(self, *args, **kwargs):
for field in fields:
setattr(self, field, models.DecimalField(decimal_places=4,
max_digits=10))

Sadly, this doesn't work. The columns don't get created when you run
the syncdb command, and even something like
MyModel._meta.get_all_field_names() doesn't return the dynamic fields.

So, is there a way I can create a "dynamic" model? I did come across
http://code.djangoproject.com/wiki/DynamicModels but I don't really
get that. It looks so much different then normal models, it seems like
I would loose a lot of functionality or would have to change a lot of
code somewhere else in my application?

Hopefully there is an easy way to do this :)

Cheers,
Kevin

--

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