This view works when the query is in the database.
def search(request):
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
q_school = Lawyer.objects.filter(last__icontains=q).values_list('school', flat=True)
q_year = Lawyer.objects.filter(last__icontains=q).values_list('year_graduated', flat=Tru...
Hi,
I want to sort a QuerySet of contacts by a related field. But I do not know how.
I tried it like this, but it does not work.
foundContacts.order_by("classification.kam")
Actually in a template I can access the kam value of a contact through contact.classification.kam since it is a OneToOne relationship.
The (simplified) models l...
I am having a problem figuring out how to solve this problem the Django and (probably) the Python way. I am sending a hash to a template that contains the following values
{'date': '2009-12-30', 'locations': [{u'lat': 43.514000000000003, u'lng': -79.844032999999996, u'place': u'1053 Bowring Cres, Milton, ON L9T, CA', u'description': u'...
I have an abstract Django model and I want to define an ImageField inside of it. The problem is that when I do define it, it raises an error because I don't have an "upload_to" attribute. Is there a way to still define it and have a separate folder for each inheriting class?
...
I'm really confused by some errors I'm getting as I'm trying to put an App into production. Everything works fine on the development machine, but I can't syncdb or enter the Django shell on the Production server.
I'm getting an error when forum.models.py is attempts to import forum.managers.py because the models aren't in the namespace y...
I have a many to many relationship between Group and User and also between User and Domain. Also i have one to many relationship between Domain and Group.
I have defined the save_model function of UserAdmin as follows:
def save_model(self, request, obj, form, change):
form.save(False)
obj.save()
form.save_m2m()
...
I would like to generate a TSV file from a list of vehicles....I'll also be making some conversions on the data e.g. if value for transmission is "Automatic" then this value will be rendered as "A" or if mileage is in miles, then multiply this value by 1.6.
What's the best way to go about this?
UPDATE
OK...so I've written the script a...
I'm new to Django and I wonder if there is a way to dump all the variables available to a template for debugging purposes. In Python I might use something like locals(), is there something equivalent for the default template engine?
Note: suppose I don't have access to the view for the purposes of this question.
...
My view code looks basically like this:
context = Context()
context['my_dict'] = {'a': 4, 'b': 8, 'c', 15, 'd': 16, 'e': 23, 'f': 42 }
context['my_list'] = ['d', 'f', 'e', 'b', 'c', 'a']
And what I'd like to do in my Django template is this:
<ul>
{% for item in my_list %}
<li>{{ item }} : {{ my_dict.item }}</li>
{% endfor %}
</u...
My view code looks basically like this:
context = Context()
context['some_values'] = ['a', 'b', 'c', 'd', 'e', 'f']
context['other_values'] = [4, 8, 15, 16, 23, 42]
I would like my template code to look like this:
{% for some in some_values %}
{% with index as forloop.counter0 %}
{{ some }} : {{ other_values.index }} <br/>
...
I have the following view that takes the value of "q" from a template:
from django.http import HttpResponse
from django.shortcuts import render_to_response
from GOTHAMWEB.GRID.models import *
def search(request):
errors = []
if 'q' in request.GET:
q = request.GET['q']
if not q:
errors.append('Enter a...
All..
I have a Django site and to access it all the users have to go through the login page.
My question is when a user is given a access through the login page to enter the site.Does Django logs the username in any of the Django internal tables....
Thanks.......
...
class Content(models.Model):
.....stuff here
class Score(models.Model):
content = models.OneToOneField(Content, primary_key=True)
real_score = models.IntegerField(default=0)
This is my database schema. As you can see, each Content has a score.
How do I do this:
Select all from Content where Content's Score is 1?
...
At present the search form is for last name only and that causes problems where there are more than one last name.
This was noted here by Antony Hatchkin.
To solve the problem I want to add a search form with last name and first name and write a new search function search2().
Will the new function look something like this?
def search...
I am trying to overrride the "admin/includes/fieldset.html" template.
I am rendering "Group", a ModelMultipleChoiceField field as a CheckboxSelectMultiple widget.
However I want to change the display depending on the choices selected.
{% if field.is_checkbox %}
{{ field.field }}{{ field.label_tag }}
{% else %}
...
I have a very basic email app. The forms class is:
class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
subject = forms.CharField(max_length=100)
sender = forms.EmailField()
recipient_list = forms.EmailField()
message = forms.CharField(widget=forms.Textarea)
cc_myself = forms.BooleanField(initial...
Base project structure
baseproject
baseapp
models.py
class BaseModel(models.Model)
...
Other project structure:
project
app
views.py
urls.py
project.app.views.py
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
from django.conf import settings
from baseproj...
Here are a couple of examples taken from django-basic-apps:
# self.title is a unicode string already
def __unicode__(self):
return u'%s' % self.title
# 'q' is a string
search_term = '%s' % request.GET['q']
What's the point of this string formatting?
...
I have a (GoogleAppEngine) Django ModelForm:
class A(db.Model):
a = db.StringProperty()
class MyAForm(djangoforms.ModelForm):
class Meta:
model = A
This creates a form which has one string field a. On my form I'd like to call this something else, say b. So I'd like a form with a field called b and when the form is POSTed we ...
I have some problems with following string while
trying to syntax highlight them:
Example
<code class="php"><? echo "<input type=\"text\">"; ?></code>
The php part is rendered correctly, but the html part breaks.
I use the Markdown and Syntax Highlighting snippet from
http://www.djangosnippets.org/snippets/119/
Any idea how to e...