Suppose my model is this:
class Ego(models.Model):
event = models.ForeignKey(Event)
user = models.ForeignKey(User)
As you can see, this table has 2 columns, and they're both foreign keys.
How do I "order by" User.first_name?
Is this it? But it doesn't look like it.
Ego.objects.all().order_by("User.first_name")
...
I'd like to do something like this:
class Task(models.Model):
...
created_by = models.ForeignKey(User, default=[LoggedInUser] blank=True, null=True, related_name='created_by')
Is this possible? I couldn't find what's the proper way to get the logged in user, apart from doing request.user, in a view, which doesn't seem to work here.
PS...
What is the easiest (and fastest) way to migrate (+-) a simple data driven "app" to a Framework that does most of the work for me (like forms, add , remove).
What I have is a simple Excel 2003 for Stock managemment.
Quite simple, 3 tables:
1 for **Information **on the product.
1 with product code, type of movemment (IN ou OUT), quan...
I have been studying unicode and its Python implementation now for two days, and I think I'm getting a glimpse of what it is about. Just to get confident, I'm asking if my assumptions for my current problems are correct.
In Django, forms give me unicode strings which I suspect to be "broken". Unicode strings in Python should be encoded ...
I want to do the below list iteration in django templates:
foo = ['foo', 'bar'];
moo = ['moo', 'loo'];
for (a, b) in zip(foo, moo):
print a, b
django code:
{%for a, b in zip(foo, moo)%}
{{a}}
{{b}}
{%endfor%}
I get the below error when I try this:
File
"/base/python_lib/versions/third_party/django-0.96/djang...
Is there a method one can filter output string in two ways at once:
divide long words into parts (but not like in truncate where the truncated part is not visible, but it should be separated with let's say empty space)
change text links into clickable links
Let's say we have string like this :
"IamareallylongwordandsoIneedToBeSplit ...
Hello
I have 3 forms at the same page and each has a different form submit. Such as:
<h1>Address</h1>
<form method="post" id="adress_form" action=/profile/update/>
{{ form_address.as_p }}
<p><button type="submit">Save</button></p>
</form>
<h1>Email Change</h1>
<form method="post" id="email_form" action=/profile/update/>
{{ form_email...
Very newbie question, but please be gentle with me. Our site uses Django CMS and we're trying to insert some javascript into particular stories, but it appears Django is stripping out any javascript or iframes we put in there as soon as we save the story. How do we allow javascript to be used in stories? Is it being deliberately excluded...
Hi I have an array of checkboxes e.g.
<input type="checkbox" name="checks[]" value="1" />
<input type="checkbox" name="checks[]" value="2" />
<input type="checkbox" name="checks[]" value="3" />
<input type="checkbox" name="checks[]" value="4" />
How do I access these in the view.py if more than one is selected?
I have tried
request...
My client program is sending a gzip-ed http request, which is decompressed by the mod-deflate InputFilter in Apache. This works when I am using mod-wsgi (without any custom configurations) to serve a django site that is receiving compressed requests. However, when I turn on daemon mode via the WSGIDaemonProcess directive, the django site...
I've got a very large SQLite table with over 500,000 rows with about 15 columns (mostly floats). I'm wanting to transfer data from the SQLite DB to a Django app (which could be backed by many RDBMs, but Postgres in my case). Everything works OK, but as the iteration continues, memory usage jumps by 2-3 meg a second for the Python process...
I'm currently developing my Django projects on both:
Mac OS X 10.5, 32 bit
Ubuntu Server 9.10 64 bits (1 CPU, 512MB RAM)
Both of the above OS are using:
Python 2.6.4
Django 1.1.1
MySQL 5.1
Running 12 tests for one of my application take:
Mac: 57.513s
Linux: 30.935s
EDIT:
Mac Hardware Spec:
MacBook Pro
2.2 GHz Intel Core ...
Hi! Is there a way to declare this case so that it works? I hope the code is self-explanatory.
class A(Model):
many_to_one = models.ForeignKey(B)
(...)
class B(A):
(...)
...
Greetings,
I want to draw a graph in my Django-based site (to look like these one http://cssglobe.com/lab/csslinegraph/img.gif)
How can I do this?
...
I would like to create a python script, which will:
Create a django project in the current directory. Fix settings.py, urls.py.
Do syncdb
Install new apache instance listening on specific port (command line argument), with WSGI configured to serve my project.
I can't figure out how to do point 3.
EDIT:
Peter Rowell:
I need the s...
Hi guys,
Sorry to repeat old questions, but I didn't quite understand the answer.
The question was: How to enable auto-complete in Komodo Edit 5.2 for Django
http://stackoverflow.com/questions/1424392/komodo-edit-code-completion-for-django
"It was already on my python path (could import django stuff via plain old python shell), howev...
I am trying to automate the creation of something like this:
<input type='text' name='asdf[]' />
<input type='text' name='asdf[]' />
<input type='text' name='asdf[]' />
By cycling through a range in the form. I've been trying things like this, along with several other variations:
# in a model class
for i in range(1, prim+1):
self...
I'm really sorry if this is a duplicate, but I have been searching, and haven't been able to find the answer.
In Django I want to do something like (see the comments):
# we have a file in our database...
v = create_file_entry(clean_data, ip_address)
# next, start a *background process* to upload the file somewhere else...
p = Proce...
Hi. When I run my django project on apache with mod_wsgi, I receive something like that:
[Wed Mar 10 08:46:43 2010] [error] [client 10.13.1.145] Traceback (most recent call last):
[Wed Mar 10 08:46:43 2010] [error] [client 10.13.1.145] File "/usr/local/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/handlers...
The django admin allows you to specify fieldsets. You properly structure a tuple that groups different fields together. You can also specify classes for certain groups of fields. One of those classes is collapse, which will hide the field under a collapsable area. This is good for hiding rarely used or advanced fields to keep the UI clea...