Suppose I have 2 models.
The 2nd model has a one-to-one relationship with the first model.
I'd like to select information from the first model, but ORDER BY the 2nd model. How can I do that?
class Content(models.Model):
link = models.TextField(blank=True)
title = models.TextField(blank=True)
is_channel = models.Boole...
I have a dictionary
data = {'sok': [ [1, 10] ], 'sao': [ [1, 10] ],'sok&sao':[ [2,20]] }
How Can I (Loop trough Dictionary ) present My data as (HTML) table to Django template.??
This format that as table
author qty Amount
sok 1 10
sao 1 10
sok...
Basically, i've created a view to populate my database with Serial models from 0000 to 9999. below is the code i'm using for the view.
def insert_serials(request):
for i in range(0,10000):
serial = Serial(i,False)
serial.save()
else:
print 'The for loop is over'
what is the right way to do this, and i'm getting an ...
Hello,
I am currently using Django Users model.
Very simple. However, I'd like to add one feature: Adding friends!
I would like to create 2 columns in my table:
UID (the ID of the User)
friend_id (the ID of his friend! ...of course, this ID is also in Django's User model.
The UID-friend_id combination must be unique! For example, if ...
to_friend = User.objects.filter(username=friend_q)[0:1]
If 'friend_q' is NOT inside the User.username...it will give error.
What is the recommended tactic?
Thank you
...
Trying to add django-registration to my app. I have installed setup tools to use easy_install. I think that works..
I run easy_install django-registation and a cmd prompt window flashes up, does something and closes. I don't think it's an error. But when I look in my app folder, theres nothing relation to django-registration.
Anyone kn...
I have the following models:
class Topping(models.Model):
...
class Pizza(models.Model):
toppings = models.ManyToManyField(Topping)
I then have a topping object:
cheese = Topping.objects.get(name='cheese')
I then find all pizzas with the cheese topping with the following query:
Pizza.objects.all().filter(toppings=cheese)
...
In my admin, I have a text area where the user can input html:
<ul>
<li>blah</li>
</ul>
<p>
Stuffs
</p>
When I push the above to my template and I view the source of the page, I get:
<ul>
<li>blah</li>
</ul>
<p>
Stuffs
</p>
What should I do with my output so that I see actual html in the ...
I've created a custom Manager for a Django model which returns a QuerySet holding a subset of objects.all(). I need this to be the model's default Manager, since I am also creating a custom tag which will retrieve content from any model (specified by an argument), and needs to use the default Manager for the specified model. All that wor...
This seems like it should be dead simple, so I must be missing something. I just want to set the value of a field in my model instance by name. Say I have:
class Foo(Model):
bar = CharField()
f = Foo()
I want to set the value of bar by name, not by accessing the field. So something like:
f.fields['bar'] = 'BAR"
instead of
f.bar...
I basically want to take an existing mysql database structure created and used by a php app (codeigniter framework) and reverse engineer it to a django app. is there some tool to do this? south migrations maybe?
...
how to know if checkbox is checked (True, 1) having just the {{ form.checkbox }} form-tag?
activo is True, 1 in db.
my template is:
{{ form.activo }}
RESULTS:
<input id="id_activo" type="checkbox" name="activo" checked="checked"/>
{{ form.activo.data }}
RESULTS:
False
{{ form.activo.value }}
RESULTS:
""
No 1 or True's :S
Any hint...
I want to transform photos in python to look like this:
taken from doctype.com
I will use it in django, PIL is installed.
How can I achieve this?
...
In the django admin, when a user successfully saves (after my clean method) a new or changed related object which was edited in a popup, I'd like the popup to close instead of going to a different view.
I believe I could use response_change or response_add to get it to go to a different view, but is there a way I can get the window to c...
Hi StackO,
Long time fan, first time posting. Hi!
Anyone notice slowness from a django dev server running on Mac OS and connecting to a remote (postgres) db? It doesn't seem to be the DNS problem referenced elsewhere. We've got a staging instance running the exact same code on the same remote staging box that's hosting the db, and the ...
I'm looking for some input on how others would architect this. I'm going to provide class (django group) based views.
For example, a user's group will determine what views/templates he or she will have access to. I'm thinking of perhaps storing paths to view functions in a table to determine what a user's link bar will consist of. Filt...
Hello,
My problem is a if condition.
I would like somethings like that but cannot figure out how to do it.
{% if restaurant.is_favorite_of(user) %}
<img src="{{MEDIA_URL}}images/favorite_on.png" alt="This restaurant is one of your favorite (Click to undo)" />
{% else %}
<img src="{{MEDIA_URL}}images/favorite_off.png" alt="Th...
I have a form that allows users to upload text AND a file. However, I'd like to make it valid even if the user doesn't upload the file (file is optional). However, in Django, it is not allowing me to get past "clean(self)". I just want it simple--if text box, pass. If no text , return error.
class PieceForm(forms.Form):
text = ...
class Friendship(models.Model):
from_friend = models.ForeignKey(User, related_name='friend_set')
to_friend = models.ForeignKey(User, related_name='to_friend_set')
I'd like to SELECT all to_friends that have from_friend = a certain User.
Then, I'd like to pass to_friends to inside filter in another .objects.filter(). Is this th...
Hi guys, i did it with twitter, update status, but now, i need to do with facebook, just i want to public a "link" on "Facebook Pages", i would like to send my title post from my django app to my Facebook Pages....
any tutorial?
Thanks
...