django-templates

How do I detect if a formset has any errors at all in a template?

Thanks to the fantastic inline model formsets in django I have a pretty advanced form with 4 inline formsets. In the template I display each formset in a tab. Everything works really slick but I would like to color a tab red if the formset in that tab has any validation errors at all. So I tried this: <div id="tabs"> <ul> <l...

Editor or IDE supporting django templates and HTML/CSS validation?

Is there a IDE that supports editing django templates and that is able to validate HTML and CSS? Requirements: be able to detect and highlight errors in CSS, example: forgot to close "}", or invalid css attribute be able to make it learn new css attributes (like css3 ones or browser specific ones) - we don't want to see them invalidat...

Django: Parse JSON in my template using Javascript

Hello, I have this in my view: string_location = myaddress2 geodata = [] for place, (lat, lng) in g.geocode(string_location,exactly_one=False): geodata.append((place, (lat, lng))) geodata_results = len(geodata) data = {"geodata": geodata, "geodata_results":geodata_results } return render_to_response("busin...

Django template rendering to itself

Hi I am trying to render the dictionary content using Django template like this for example : result contain dictionary X X={a:1, b:1, c:X(dictionary X again) } This could be any many places and at multiple levels template : results.html, says something like following {{a}} {{b}} {% if X.a %} {% include resul...

embedding generated img inside django template

how would I embedded generated image inside django template? something like return render_to_response('graph.html', { 'img': get_graph() }) I don't want this - because it just send image http.HttpResponse(get_graph(), mimetype="image/png") ...

Object not iterable with django's pagination

I have a template showing a list of events. To prepare list of events I'm using generic views, and set 'paginate_by' parameter. Strangely when I load my page I see : TemplateSyntaxError at /event/latest/ Caught an exception while rendering: 'int' object is not iterable in 9th line of pagination.html template : {% if is_paginated %} {...

Django: Reverse URL lookup with arbitrary URL components

Assume a Django app, shop, whose urls.py is included in the main urls.py: # main urls.py urlpatterns = patterns('', (r'^[^/]+/shop/', include('shop.urls')), ) Note, that there is an arbitrary prefix before /shop. This is of no interest for the shop app, it's only interesting to some middleware. The shop.urls could look like this:...

How do I access the properties of a many-to-many "through" table from a django template?

From the Django documentation... When you're only dealing with simple many-to-many relationships such as mixing and matching pizzas and toppings, a standard ManyToManyField is all you need. However, sometimes you may need to associate data with the relationship between two models. For example, consider the case of an application...

Django: user info in template

I have this in my base.html template: {% if user.is_authenticated %} <p style="color:#000;"> Welcome {{ user.first_name }} | <a href="/logout/">Logout</a> </p> {% endif %} After I authenticate, and go to this page, my first name does not show up. Can anybody tell me why? The "Welcome" also does not show up. So, this ...

How to Pass Django form values to a model class method

What is the best way to pass request information to a model class method? I'm wondering whether I have my logic in the wrong place. Maybe I need to move it out of my model. I want to be able to pass in POST variables or a form to filter the model by country or institution. I can't do that from the template, but the question is whethe...

Django - Limit users who view the items

My Models: class PromoNotification(models.Model): title = models.CharField(_('Title'), max_length=200) content = models.TextField(_('Content')) users = models.ManyToManyField(User, blank=True, null=True) groups = models.ManyToManyField(Group, blank=True, null=True) I want to publish there items to templates with some p...

Display unescaped HTML String in Django Admin change list

Hey Guys! I am currently facing a serious problem. I use the standard django admin interface incl. change list to display one of my models. The model has got a field, which includes a link (e.g. in database: link). What I want now is that this string is rendered unescaped and displayed as link. I already tried the following in "change_...

Django template filter to create an list of items that join on commas and end on "and"

I feel like I am writing something that should already exist. Does Django have a template filter that joins a list of items on commas and places and 'and' before the last one? For example: a = ['foo',] b = ['bar', 'baz',] c = a + b d = c + ['yourmom',] The filter I am looking for would display each list in the following ways: a...

Querying Many to many fields in django template

This may not be relevant but just wanted to ask, IF an object is passed from views to template and in the template will i be able to query many to many fields Models code: class Info(models.Model): xls_answer = models.TextField(null=True,blank=True) class Upload(models.Model): access = models.IntegerField() info ...

Django blocktrans error

I am nearing the final stages of a project and have run into a bit of a hiccup with Django. It relates to the {% blocktrans %} tag. How do I enable it to be fully functional in my app, currently if I wrap a piece of text in {% blocktrans %} I get a TemplateSyntaxError message I have the following in my TEMPLATE_CONTEXT_PROCESSORS = ...

Creating a dynamic choice field

I'm having some trouble trying to understand how to create a dynamic choice field in django. I have a model set up something like: class rider(models.Model): user = models.ForeignKey(User) waypoint = models.ManyToManyField(Waypoint) class Waypoint(models.Model): lat = models.FloatField() lng = models.FloatField() ...

Comparison of Date in database against current date

Hi, In my application I have the date of a talk and I want to compare this against the current date to see whether it should display View Attendance Record in my html page. What I am thinking is: if (dateInDB <= currentDate) display View Attendance Record else don't display view attendance record How would i convert this to ...

How to properly i18n a string

This more or less complex phrase to translate in my Django template is: This site is owned by "<a href="url">The Company Name</a>" and is maintained by partner organizations. Is it as simple as: {% trans "This site is owned by "<a href="url">The Company Name</a>" and is maintained by partner organizations." %} Thank you. ...

Django model association, users, profiles and idea model

I have an app that makes use of 'django-registration' a custom built model named 'idea' and also a 'userprofile' Now the Idea class looks as follows class Idea(models.Model): title = ... user = models.ForeignKey(User) The User class is Django's Auth User system. And the UserProfile looks as follow. class UserPro...

Possible to send 2 querysets to response?

Hi, render_to_response Is it possible to pass more variables than just one? For example in my application I have a members model and then i would like to display the members information and also attendance information. Would I have to supply the arguments as a tuple? Thanks in Advance, Dean ...