Re: text in translation strings?
> I'm having a template, where a link shall be inside a translation- > marked text. (...) I've recently run across a similar problem and solved it using some nasty with-tag trickery. In your case the following code should do the trick: {% url login as login_url %} {% with "" as link_begin %} {% with "" as link_end %} {% blocktrans %}Please {{ link_begin }}login{{ link_end }} to proceed. {% endblocktrans %} {% endwith %} {% endwith %} {% blocktrans %} also has a builtin "with" support, but for some reason it does not support escaping special characters. So the following doesn't work: {% blocktrans with "" as link_begin and "" as link_end %}Please {{ link_begin }}login{{ link_end }} to proceeed.{% endblocktrans %} --mp -- 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: JOINs with Django ORM
mp> I'd go for a denormalized database: mp> (...) tz> I'm aware of this solution, in fact I was using it. Unfortunately I tz> had problems with deleting objects with this circular dependency, but tz> maybe I was overlooking something (db we're using is MySQL 5). You're right. You have to make sure to either disable foreign key checks prior to deleting anything, which is kinda hacky, or make sure to set the latest_revision to None prior to deleting a revision. If that circular reference is problematic in your use case you could also just add a boolean field to your Revision: class FooRevision(models.Model): foo = models.ForeignKey() is_latest = models.BooleanField() ... FooRevision.objects.filter(is_latest=True).select_related() will return all latest revisions together with their base then. tz> Anyway, my case is much more complicated so I would have to tz> denormalize more than just one model. Because of that, of because tz> VIEWs + fake models are quick enough for what I'm doing (and has > enough speed reserve for the future), I decided to go this path. Ok. I guess you'll have to stick to some custom SQL then. --mp --~--~-~--~~~---~--~~ 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: "...where field is NULL" in Django ORM
Михаил Лукин wrote: > For some reason, __exact and __isnull are described in documentation > [1], while =None is not. So which of them are historical? Django pre 1.0 generated bogus SQL, when doing nullable_field=None. These days __isnull can be replaced by the expressions: filter(foo__isnull=True) -> filter(foo=None) filter(foo__isnull=False) -> exclude(foo=None) Though I still use the __isnull lookup often as it's more explicit. Besides I rarely use exclude(), so it feels more natural to have all filter rules together in one statement. You're right in one thing. The whole foo=value thing is not documented. When looking at the QuerySet API it only shows the use of foo__exact. I wonder if __exact is the default field lookup. To be true I've never used __exact I always rely on the much less verbose version. --mp --~--~-~--~~~---~--~~ 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: JOINs with Django ORM
> I was unclear, but SQL should explain what I want to do - select > all ObjectRevision-s that are latest in Object-s that they belong to. > Moreover, I want to do this in with one ORM query, without resorting > to SQL or splitting the query too much. I'd go for a denormalized database: class Foo(models.Model): latest_revision = models.OneToOneField('FooRevision', related_name='latest_revision_for') ... class FooRevision(models.Model): foo = models.FogeignKey(Foo) ... That way you can easily query Foo.objects.all().select_related() and be done. It'll be faster than your rather complex DB query and can be handled in the Django ORM. I'd say it's a win win situation. --mp --~--~-~--~~~---~--~~ 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: form problem
> I made the change but now the following error appears: > 'QueryDict' object is not callable Whops. request.GET is a query dict, so it's of course not callable. I ment to call get('user_text', '') on the request.GET: request.GET.get('user_text', '') --mp --~--~-~--~~~---~--~~ 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: form problem
First of all may I recommend you to use Django forms: http://docs.djangoproject.com/en/dev/topics/forms/ > With this method i have the following error: > Key 'user_text' not found in >> def view(request): >> user_text = request.GET['user_text'] >> return render_to_reponse("html",{'user_text':user_text}) When requesting the view for the first time the request.GET dict will not contain a 'user_text'. If you replace request.GET['user_text'] by request.GET('user_text', '') it will not raise an exception, but return '' (empty string) if no 'user_text' is contained in the GET dict. Besides it's good practice to use POST for forms, if they're used to submit new or modify existing data. That's the reason why the example code in the forms documentation always checks for request.method == 'POST' to see if the form is actually being submitted or loaded for the first time. In order to get the idea of POST and GET better you might be best of googeling for it and reading up what the HTTP methods are supposted to be used for. Rule of thumb: Use POST whenever you're modifying data and GET when querying data. --mp --~--~-~--~~~---~--~~ 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: create Index: non-unique, multiple column
> Given the following model, I want to index the fields (sequence,stock) There is a ticket for it, but it hasn't made it into Django, yet. http://code.djangoproject.com/ticket/373 > create index ndx_1 on model_quotemodel(sequence,stock); > Is there any "cleaner" way of doing it? If you ask me, it's the cleanest way of doing it at the moment. --mp --~--~-~--~~~---~--~~ 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: Question about template
> I would like to use if clause to check if a number is nagative or not > with template in my html file. I read related part in Django template > online document however I did not find what I need. > > Is it possilbe to do this with built-in Django filter functions? Or do > I have to install a third-party template library? You could either use the 'smarter {% if %} tag', which might be added to Django 1.2 according to the "Features under consideration" list in the Wiki. Grab it from http://www.djangosnippets.org/snippets/1350/ Or write a custom template filter. Since writing filters is so straight forward and simple I recommend you to look into the docs: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters There is no built-in filter for this in Django as it's a vital sign that you're mixing template logic with view logic. I recommend you to ask yourself the following question: "Does my template really have to figure out x < y itself or shouldn't it just get this information from the view?". If it's a common thing you might be better of writing a filter or template tag specific to your use case. I know it's hard to resist the urge "but I just want...". I can tell from experience that investing that extra bit of time to do things the right way pays off in the long run. Especially as you can later reuse the code more easily. Sometimes even simple stuff like {% ifequals foo 0 %} would fit better into a custom filter. Just think of floating point values that are almost zero. It's {% if foo|abs < 0.001 %} vs {% if foo|is_near_zero %}. The latter provides you with the possibility to configure the threshold in the config file while the former has the logic hardcoded in the template. --mp --~--~-~--~~~---~--~~ 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: check if user has already saved link
> return user.savelink_set.objects.filter(link=object).count() (...) > The error i get now is : Caught an exception while rendering: > 'RelatedManager' object has no attribute 'objects' user.savelink_set is already a Manager and does not have an attribute "objects". Just write "user.savelink_set.filter(link=object).count()". --mp --~--~-~--~~~---~--~~ 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: Showing unescaped HTML in Admin pages
> Is is possible to render unescaped HTML in admin pages? > > (say) A model has a field "text" which contains HTML markup. Is this > something that can be changed on the model (ie __unicode__ method) or > do I have to change the admin templates? If you're only going to render html for lists it's possible to add an 'allow_tags' attribute to a field to be added to list_display: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display In order to display RAW html inside the admin change view you have lots of choices. (a) either write a custom field that returns a different widget http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#formfield (b) or use a standard field and specify formfield_overrides http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides (c) or use a custom form http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form (d) or just provide a custom template http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_form_template I'd probably go for (a) as it looks the cleanest to me and is reusable. A HTMLMarkupField could also provide methods like verify(), tidy(), etc. (b) is a good choice if you generally want to change the way all Char- and TextFields behave. (c) and (d) provide the most flexibility, while coming at the cost of being quite verbose. --mp --~--~-~--~~~---~--~~ 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: sorl thumbnail error
> I'm getting error messages with sorl thumbnail. [...] All works fine, > until I use the following template thumbnail tag: > > You must not put braces around variables passed to a template tag. Just write: {% thumbnail obj 80x80 %} That also explains why your {% thumbnail '/path/to/image' 80x80 %} example works as expected. It's treated as string while {% thumbnail /path/to/image 80x80 %} would cause a /path/to/image variable to be searched inside the current template context which will probably not exist. It highly depends on the template tag you're using. For example is the 80x80 not treated as a variable even though it's lacking quotation marks around it. For more information how template tags actually work check the docs: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ --mp --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---