Sent via BlackBerry® from Telstra -----Original Message----- From: django-users+nore...@googlegroups.com Sender: django-users@googlegroups.com Date: Wed, 13 Jul 2011 18:37:47 To: Digest Recipients<django-users+dig...@googlegroups.com> Reply-To: django-users@googlegroups.com Subject: Digest for django-users@googlegroups.com - 25 Messages in 8 Topics
============================================================================= Today's Topic Summary ============================================================================= Group: django-users@googlegroups.com Url: http://groups.google.com/group/django-users/topics - Add attributes (css-class) to formfield [6 Updates] http://groups.google.com/group/django-users/t/5e981b9e16ea2b4 - Django piston [2 Updates] http://groups.google.com/group/django-users/t/a01ffdf6094dd6e6 - Django Internals [2 Updates] http://groups.google.com/group/django-users/t/2484b11a33f4e030 - AW: Trouble overriding registration templates [8 Updates] http://groups.google.com/group/django-users/t/599a8f9e4644f6ce - exclude field from SQL insert [3 Updates] http://groups.google.com/group/django-users/t/c3a3b585f671edf6 - old app fails tests, runs ok [1 Update] http://groups.google.com/group/django-users/t/319bda41ab57e75b - Duplicate Key Error in Cache [2 Updates] http://groups.google.com/group/django-users/t/36f8d7797e874757 - Efficiently querying db [1 Update] http://groups.google.com/group/django-users/t/8f09718bb62d56f9 ============================================================================= Topic: Add attributes (css-class) to formfield Url: http://groups.google.com/group/django-users/t/5e981b9e16ea2b4 ============================================================================= ---------- 1 of 6 ---------- From: Andreas Pfrengle <a.pfren...@gmail.com> Date: Jul 13 10:41AM -0700 Url: http://groups.google.com/group/django-users/msg/8176dff0b94dae11 Hello, I know about assigning attributes to widgets, like shown here: <https://docs.djangoproject.com/en/1.3/ref/forms/widgets/#customizing- widget-instances> or here: <http://stackoverflow.com/questions/401025/define-css-class-in-django- forms> However, I want to assign an additional attribute to a formfield, since we want a css class for a div that is wrapped around the presentation of a field. I've tried to assign an attribute in the form's__init__, like: self.fields['my_field'].div_css = "test" If I try to fetch it in the template however, it resolves to an empty string (supposedly the attribute doesn't exist): {% for field in form.visible_fields %} <div class="{{ field.div_css }}" > .... </div> {% endfor %} Any help or explanation what goes on inside Django is appreciated. Regards, Andreas ---------- 2 of 6 ---------- From: Shawn Milochik <sh...@milochik.com> Date: Jul 13 01:47PM -0400 Url: http://groups.google.com/group/django-users/msg/448c3aea3807fb7 Following this as a sample (from the docs you linked to): widget=forms.TextInput(attrs={'class':'special'})) You'd do this: widget=forms.TextInput(attrs={'div_css':'test'})) Or, to not clobber other things set in the form, you could do it in the __init__: #working example I just did in one of my projects to prove it works self.fields['release_date'].widget.attrs["div_css"] = 'test' ---------- 3 of 6 ---------- From: Andreas Pfrengle <a.pfren...@gmail.com> Date: Jul 13 11:00AM -0700 Url: http://groups.google.com/group/django-users/msg/5a31279b06a4129d Hello Shawn, thanks for your answer, however that's not exactly what I wanted. Now the html renders to: <label for="id_n_properties">No. of properties</label> <input value="4" type="text" name="n_properties" div_css="test" id="id_n_properties" /> However, I would want: <div class="test"> <label for="id_n_properties">No. of properties</label> <input value="4" type="text" name="n_properties" id="id_n_properties" /> </div> Additionally, I can't access {{ field.widget.attrs.div_css }} to get the class directly, I get an empty string instead. ---------- 4 of 6 ---------- From: Andre Terra <andrete...@gmail.com> Date: Jul 13 03:05PM -0300 Url: http://groups.google.com/group/django-users/msg/be002e8f71acc736 Write a wrapper function and make it even shorter (ok, go ahead and call it syntax sugar): def css(field, **kwargs): field.attrs.update(**kwargs) use as: css(self.fields['release_date'], div_css="test") DISCLAIMER: not tested on a real Field, but I tested it on a simple class in a python shell and it seemed to work I'll leave it as homework for you to make this a class method and make the syntax even shorter. Maybe even propose a patch! Cheers, André Terra / airstrike ---------- 5 of 6 ---------- From: Shawn Milochik <sh...@milochik.com> Date: Jul 13 02:25PM -0400 Url: http://groups.google.com/group/django-users/msg/c42a60a54f032847 On 07/13/2011 02:00 PM, Andreas Pfrengle wrote: > </div> > Additionally, I can't access {{ field.widget.attrs.div_css }} to get > the class directly, I get an empty string instead. Replace 'div_css' in my example with 'class' and you'll get 'class="test"' in your output. ---------- 6 of 6 ---------- From: Andre Terra <andrete...@gmail.com> Date: Jul 13 03:28PM -0300 Url: http://groups.google.com/group/django-users/msg/1af939075391727a Shawn, He wants the form attribute to be applied to the div, not the field. Andreas, You can't pass an attribute to a field and expect it to show up in a different object altogether. I assume your div isn't handled by django, so you need to fix that first in order to be able to pass extra attributes to it. A few solutions: 1) Use a fieldset (like the admin does) and then define how *that* gets rendered - complex, flexible. 2) Pass a css attribute to the view (not sure where you're going to get that css_class stuff from) and use it in your template's context, then add classes on the fly during template compilation - easy, ugly. Cheers, André ============================================================================= Topic: Django piston Url: http://groups.google.com/group/django-users/t/a01ffdf6094dd6e6 ============================================================================= ---------- 1 of 2 ---------- From: Dipo Elegbede <delegb...@dudupay.com> Date: Jul 13 07:09PM +0100 Url: http://groups.google.com/group/django-users/msg/9f675c1566668495 I'm about to start using django piston. Can anyone please point me to any example? I've looked through the documentation but can't get a hang of it. Regards. ---------- 2 of 2 ---------- From: Shawn Milochik <sh...@milochik.com> Date: Jul 13 02:23PM -0400 Url: http://groups.google.com/group/django-users/msg/aecce2c4050571d1 Try going to github and doing a search for 'django-piston.' That will show you a list of open-source projects that have implemented django-piston. ============================================================================= Topic: Django Internals Url: http://groups.google.com/group/django-users/t/2484b11a33f4e030 ============================================================================= ---------- 1 of 2 ---------- From: Venkatraman S <venka...@gmail.com> Date: Jul 13 10:06PM +0530 Url: http://groups.google.com/group/django-users/msg/f23d115f3d2f7b9a Except for the code, is there any good place to start with to better understand the django structure. As in, i am trying to figure out a way by which django can be much leaner, so that the actual footprint is much smaller. Say, if i just want to have a simple website with a handful of models, with no complex queries, then having something like a 'django-lite' would be awsome. I started cleaning(/removing) up the code sometime back, but soon digressed. -V ---------- 2 of 2 ---------- From: Daniel Roseman <dan...@roseman.org.uk> Date: Jul 13 11:05AM -0700 Url: http://groups.google.com/group/django-users/msg/2117674be44d065d On Wednesday, 13 July 2011 17:36:44 UTC+1, Venkatraman.S. wrote: > I started cleaning(/removing) up the code sometime back, but soon > digressed. > -V For understanding the code, the absolute best place to start is Marty Alchin's great book Pro Django. But if you want a "Django-lite", you'll be better off dropping Django and looking at one of the micro-frameworks like Flask. They usually don't come with ORMs, but you can always use something like SQLObject, which again is much more minimal than Django's or SQLAlchemy. -- DR. ============================================================================= Topic: AW: Trouble overriding registration templates Url: http://groups.google.com/group/django-users/t/599a8f9e4644f6ce ============================================================================= ---------- 1 of 8 ---------- From: Joshua Russo <josh.r.ru...@gmail.com> Date: Jul 13 09:00AM -0700 Url: http://groups.google.com/group/django-users/msg/f4d892da234a5015 Am I wrong about how templates work? ---------- 2 of 8 ---------- From: Andre Terra <andrete...@gmail.com> Date: Jul 13 01:30PM -0300 Url: http://groups.google.com/group/django-users/msg/c3c92c8c5c235997 Or render() which is the recommended shortcut since 1.3. https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render Cheers, André On Wed, Jul 13, 2011 at 3:28 AM, Szabo, Patrick (LNG-VIE) < ---------- 3 of 8 ---------- From: Joshua Russo <josh.r.ru...@gmail.com> Date: Jul 13 09:46AM -0700 Url: http://groups.google.com/group/django-users/msg/fa46da945d000bd7 That's fine, but I was under the impression that the templates could be overridden just by creating the proper path in my template directories. Is that not true? ---------- 4 of 8 ---------- From: Shawn Milochik <sh...@milochik.com> Date: Jul 13 12:50PM -0400 Url: http://groups.google.com/group/django-users/msg/d5d3f00d9e8abff On 07/13/2011 12:46 PM, Joshua Russo wrote: > That's fine, but I was under the impression that the templates could > be overridden just by creating the proper path in my template > directories. Is that not true? It's true. Check the order of your TEMPLATE_DIRS in settings.py. If you don't have them specified and are relying on the automatic detection of a 'templates' dir in your app folders then check the order of your INSTALLED_APPS. If you're having an issue it's probably a good idea to explicitly populate TEMPLATE_DIRS. Hopefully this will help: https://docs.djangoproject.com/en/1.3/ref/templates/api/#the-template-dirs-setting ---------- 5 of 8 ---------- From: Joshua Russo <josh.r.ru...@gmail.com> Date: Jul 13 10:18AM -0700 Url: http://groups.google.com/group/django-users/msg/c83cfb862a0ee978 *light bulb* I forgot about my development vs production settings. I was only changing the TEMPLATE_DIRS in the main settings.py that represents my production settings. I'm not in a place where I can test this but I'm almost certain that's what the problem is. ---------- 6 of 8 ---------- From: Joshua Russo <josh.r.ru...@gmail.com> Date: Jul 13 10:13AM -0700 Url: http://groups.google.com/group/django-users/msg/2b49b533c649618 Cool, thanks for the confirmation. I do have my template directories explicitly listed in TEMPLATE_DIRS. I even made sure that my app's templates came before the admin templates, but for some reason it's not picking up my /registration/logged_out.html and the others that show up in the admin's templates/registration directory. My /registration/login.html works just fine. I'll try playing with the order of the installed apps and see if that makes any difference. ---------- 7 of 8 ---------- From: Shawn Milochik <sh...@milochik.com> Date: Jul 13 01:24PM -0400 Url: http://groups.google.com/group/django-users/msg/6490a43a871c596b To be clear, when you say registration/login, you mean templates/registration/login, correct? Your 'registration' directory should be in a 'templates' dir. ---------- 8 of 8 ---------- From: Joshua Russo <josh.r.ru...@gmail.com> Date: Jul 13 10:43AM -0700 Url: http://groups.google.com/group/django-users/msg/f7807f51968a9c2b Correct ============================================================================= Topic: exclude field from SQL insert Url: http://groups.google.com/group/django-users/t/c3a3b585f671edf6 ============================================================================= ---------- 1 of 3 ---------- From: Slafs <slaf...@gmail.com> Date: Jul 13 08:05AM -0700 Url: http://groups.google.com/group/django-users/msg/f44035ee0ea572bb Hello. I have a model in Django that is based on database view. One of the fields is "virtual" (computed in the view) . I would like to exclude this field in my model from being used in SQL Insert and Update statements. Do You know maybe how can I do that ? Regards ---------- 2 of 3 ---------- From: Tom Evans <tevans...@googlemail.com> Date: Jul 13 04:27PM +0100 Url: http://groups.google.com/group/django-users/msg/59298e229c619617 > and Update statements. > Do You know maybe how can I do that ? > Regards Models based on views are not explicitly supported, but should work well in practice (use managed=False in the meta class). Virtual computed 'fields' are definitely not supported for update/insert. Cheers Tom Cheers Tom ---------- 3 of 3 ---------- From: Venkatraman S <venka...@gmail.com> Date: Jul 13 10:08PM +0530 Url: http://groups.google.com/group/django-users/msg/2f7fa3082bced21a > Models based on views are not explicitly supported, but should work > well in practice (use managed=False in the meta class). Virtual > computed 'fields' are definitely not supported for update/insert. Nice, i didnt know this. ============================================================================= Topic: old app fails tests, runs ok Url: http://groups.google.com/group/django-users/t/319bda41ab57e75b ============================================================================= ---------- 1 of 1 ---------- From: Javier Guerra Giraldez <jav...@guerrag.com> Date: Jul 13 11:35AM -0500 Url: http://groups.google.com/group/django-users/msg/2a05feeb8febda94 Hi, I'm having a very weird problem, hope somebody can shed some light. some time ago, I developed an internal app at my officeIt using Django 1.1 (final), and it has been running with very few issues, on a small virtual machine. Now i have to do some non-trivial changes, so i set up a Virtualenv on my desktop with Django 1.1 and Python 2.6.6 (the server uses 2.6.2). if i try with `manage runserver`, it seems to work pretty well. but it refuses to pass the tests. to be precise, the test client.login() returns True, but the first request to a `@login_required` view responds with a 302 => login, as if it wasn't logged in. the user and password are ok, changing either makes client.login() return False i tried on the server itself, and all tests pass OK. Thinking it might be a different version of the mysql libraries, i changed the settings.py to use sqlite3. much faster, but fails in exactly the same way. Also, using Python 2.6.6 or 2.7 doesn't make any difference. what else can i try? was there any dependency that i might be missing? -- Javier ============================================================================= Topic: Duplicate Key Error in Cache Url: http://groups.google.com/group/django-users/t/36f8d7797e874757 ============================================================================= ---------- 1 of 2 ---------- From: "Cal Leeming [Simplicity Media Ltd]" <cal.leem...@simplicitymedialtd.co.uk> Date: Jul 13 02:55PM +0100 Url: http://groups.google.com/group/django-users/msg/d755422b53eea3de May I ask why you are using a database cache, rather than something like memcache?? Cal ---------- 2 of 2 ---------- From: gamingdroid <gamingdr...@gmail.com> Date: Jul 13 07:59AM -0700 Url: http://groups.google.com/group/django-users/msg/e564e3e9cb929f3b I'm memory constrained and therefore memcache is not an option. The pages makes a lot of independent SQL queries that is better handled through one sql call via the db cache backend. I suppose I could roll my own, but find it odd that somebody hasn't fixed it. I would fix it myself, if I knew what was going on in there, but I'm pretty new to Django. On Jul 13, 9:55 am, "Cal Leeming [Simplicity Media Ltd]" ============================================================================= Topic: Efficiently querying db Url: http://groups.google.com/group/django-users/t/8f09718bb62d56f9 ============================================================================= ---------- 1 of 1 ---------- From: "Cal Leeming [Simplicity Media Ltd]" <cal.leem...@simplicitymedialtd.co.uk> Date: Jul 13 03:14PM +0100 Url: http://groups.google.com/group/django-users/msg/36ed27d9d7042842 > I want to make seperate the lists such that messages in same thread( > The parent message and its child messages } come together . What is > the best way to query the db or a efficient algorithm to do this. How about you tell us what you have thought of so far, and we'll give you some feedback on whether or not it can be improved upon. -- 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. -- 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.