I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model:
Ca...
Hi,
I'm doing query like that:
SomeObject.objects.annotate(something=Avg('something')).order_by(something).all()
Now, I normally have an aggregate field in my model that I use with Django signals to keep in sync, however in this case perfomance isn't an issue so I thought I'd keep it simple and just use subqueries.
This approach, h...
Hey,
When this one runs everything goes fine:
(r"^newobject$", "views.myobjects.newobject"),
All the CSS + JS files are properly fetched from:
static/css/...
static/js/...
When this one runs:
(r"^mybjects/(([a-z]|[A-Z]|[0-9])+)$","views.myobjects.loadobject"),
All the css and JS files that are being fetched, are run trough the ...
I have a form that edits an instance of my model. I would like to use the form to pass all the values as hidden with an inital values of username defaulting to the logged in user so that it becomes a subscribe form. The problem is that the normal initial={'field':value} doesn't seem to work for manytomany fields. how do i go about it?
...
If I were to have two different QuerySets in Django, both representing a ManyToMany relation with the same model, how would I find the intersections?
...
Hi, all.
I have a model class like this:
class Note(models.Model):
author = models.ForeignKey(User, related_name='notes')
content = NoteContentField(max_length=256)
NoteContentField is a custom sub-class of CharField that override the to_python method in purpose of doing some twitter-text-conversion processing.
class NoteCon...
Simply put I want what http://www.reddit.com/ and http://news.ycombinator.com/ have to the left of every link. A numerated link starting with 1 and continuing to the next page by means of pagination.
I really enjoy using generic views and their built-in pagination for Django and it seems to allow me access to these values if I was on p...
I'm using django and realized that when the filename that the user wants to access (let's say a photo) has the pound sign, the entry in the url.py does not match.
Any ideas?
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':
MEDIA_ROOT},
it just says:
"/home/user/project/static/upload/images/hello" ...
model.py:
class Tribes(Group):
members = models.ManyToManyField(User, related_name='tribes', verbose_name=_('members'))
i want to store a number in a int field ,and a user can has many this number.
how to write this model ??
thanks
(i hate sql :( )
updated
this is my code:
class Position(models.Model):
LatLng = models...
When I run python manage.py shell I get an error about the last app I've added to INSTALLED_APPS, namely django_evolution, saying it's an undefined module. This is despite the fact that I've added the path to django_evolution to the system path. In fact right after this error I can run python and do an import on django_evolution and ever...
I have a small app I'm working on where I'm trying to use Django's built in filesizeformat. Currently, the format looks like this: {{ value|filesizeformat }} I understand I need to define this in my view.py file but, I can't seem to figure out how to do that. I've tried to use the syntax below:
def filesizeformat(bytes):
"""
...
I have template that displays object elements with hyperlinks to other parts of my site. I have another function that displays past versions of the same object. In this display, I don't want the hyperlinks.
I'm under the assumption that I can't dynamically switch off the hyperlinks, so I've included both versions in the same template....
I have two similar codes. The first one works as expected.
urlpatterns = patterns('',
(r'^(?P<n1>\d)/test/', test),
(r'', test2),
{% url testapp.views.test n1=5 %}
But adding the second parameter makes the result return empty string.
urlpatterns = patterns('',
(...
OK, I have the following directory structure (it's a django project):
-> project
--> app
and within the app folder, there is a scraper.py file which needs to reference a class defined within models.py
I'm trying to do the following:
import urllib2
import os
import sys
import time
import datetime
import re
import BeautifulSoup
sys...
Hello, I'm really new to Python and Django. I created a class in Python that I would like to use in a Django application. It doesn't seem like it belongs in it's own application, how can I include it in my django app?
Thank you!
...
I'm designing a gallery application for viewing vehicle pictures and there are two parameters:
Manufacturer
Vehicle type
Right now you can view either, but not both. Urls go like so:
/manufacturer/#
/type/#
Where # is an ID number. How/can I format my URLs so it can accept both? My current solution is to do: /both/#/# but this...
Even after obj.save(), the obj still does not have an id,
so I cannot access or manipulate the m2m records. Just keep getting a "instance needs to have a primary key value before a many-to-many relationship can be used" error.
def save_model(self, request, obj, form, change):
obj.save() # this doesn't work
super(Table2Admin, sel...
There is a form ,which is submitted and then the page is redirected to another page.But if the user hits the refresh button again on the new page .the following message is displayed
To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.
And on...
The object user has a foreign key relationship to address. Is there a difference between samples 1 and 2? Does sample 1 run the query multiple times? Or is the address object cached?
# Sample 1
country = user.address.country
city = user.address.city
state = user.address.state
# Sample 2
address = user.address
country = address.count...
TOPIC_COUNT_SQL = """
SELECT COUNT(*)
FROM topics_topic
WHERE
topics_topic.object_id = maps_map.id AND
topics_topic.content_type_id = %s
"""
MEMBER_COUNT_SQL = """
SELECT COUNT(*)
FROM maps_map_members
WHERE maps_map_members.map_id = maps_map.id
"""
maps = maps.extra(select=SortedDict([
('member_count', MEMBER_COUNT_SQL),
...