django

Best way to store user-uploaded files in a webapp

I'm creating a web application (in Django), which needs to allow users to upload files (specifically images, which are later displayed for other users). I'm trying to understand the best way to store these uploaded files. From related questions, I saw some people suggested giving the file a server-generated unqiue id, then creating a DB...

filter queryset based on list, including None

Hi all I dont know if its a django bug or a feature but i have a strange ORM behaviour with MySQL. class Status(models.Model): name = models.CharField(max_length = 50) class Article(models.Model) status = models.ForeignKey(status, blank = True, null=True) filters = Q(status__in =[0, 1,2] ) | Q(status=None) items = Article.o...

While trying to set up Django on Windows: AttributeError: 'Settings' object has no attribute 'DATABASES'

I'm following these instructions in order to set up Django on Windows. I have installed Python 2.6, PostgreSQL 8.4, Psycopg 2.0.14 for Python 2.6 and the latest version of Django from SVN. I'm now following these instructions to run a test project (copied from the page linked to above): C:\Documents and Settings\John>cd C:\ C:\>mkdir d...

How do I pass a lot of parameters to views in Django?

I'm very new to Django and I'm trying to build an application to present my data in tables and charts. Till now my learning process went very smooth, but now I'm a bit stuck. My pageview retrieves large amounts of data from a database and puts it in the context. The template then generates different html-tables. So far so good. Now I wa...

Django: HttpResponseRedirect doesnt pass RequestContext()?

Basically, I'm trying to redirect people who aren't logged in to the login page. What I'm currently using is: return render_to_response('login.html', context_instance=RequestContext(request)) But that leaves the url at the homepage. I'd like to have it redirect to /accounts/login/, but when I use return HttpResponseRedirect('/accoun...

django admin - selecting a single model to publish to site

Hey, I'm making a popup radio player with an attached shoutbox with django and i'm having trouble getting the admin functionality I want. I have two models: 1) A Stream (which represents a certain radio stream that the admin can publish to play on the frontpage - i.e. there are multiple saved streams, but only one is playing on the fr...

Strange behavior with complex Q object filter queries in Django

Hi I am trying to write a tagging system for Django, but today I encountered a strange behavior in filter or the Q object (django.db.models.Q). I wrote a function, that converts a search string into a Q object. The next step would be to filter the TaggedObject with these query. But unfortunately I get a strange behavior. search for onl...

Django "Page not found" error page shows only one of two expected urls

I'm working with Django, admittedly for the first time doing anything real. The URL config looks like the following: urlpatterns = patterns('my_site.core_prototype.views', (r'^newpost/$', 'newPost'), (r'^$', 'NewPostAndDisplayList'), # capture nothing... #more here... - perhaps the perma-links? ) This is in an app's ...

Break nested loop in Django views.py with a function

I have a nested loop that I would like to break out of. After searching this site it seems the best practice is to put the nested loop into a function and use return to break out of it. Is it acceptable to have functions inside the views.py file that are not a view? What is the best practice for the location of this function? Here's the ...

Where should signal handlers live in a django project?

I have just started implementing signal listeners in a django project. While I understand what they are and how to use them. I am having a hard time figuring out where I should put them. The documentation from the django site has this to say: Where should this code live? You can put signal handling and registration code any...

Intersection of two querysets in django

Hello, I can't do an AND on two querysets. As in, q1 & q2. I get the empty set and I do not know why. I have tested this with the simplest cases. I am using django 1.1.1 I have basically objects like this: item1 name="Joe" color = "blue" item2 name="Jim" color = "blue" color = "white" item3 name="John" color =...

Limiting the maximum number of concurrent requests django/apache

Hi, I have a django site that demonstrates the usage of a tool. One of my views takes a file as input and runs some fairly heavy computation trough an external python script and returns some output to the user. The tool runs fast enough to return the output in the same request though. I would however want to limit how many concurrent re...

Django Forms Help needed

Hi All, Im new to django and trying to make a user registration form with few validations. Apart from this I also want a username suggestion code which will tell the user if the username he is trying to register is available or already in use. Then it should give few suggestions that might be available to choose from. Can anyone who migh...

update forms.FileField on django forms

Hi, I have a model with a FileField in it: class DocumentUpload(models.Model): document_name = models.CharField(max_length=100, blank=True) document_path = models.FileField(upload_to='uploads') and a form which uses this model class DocumentUploadForm(forms.ModelForm): class Meta: model = DocumentUpload When I...

Django app for different clients

I want both mobile phones and regular PCs to be able to use my app by navigating to the same URL, but I want them to get different versions of the code. How do I tell Django to give different versions of the code to different clients? ...

PHP frameworks similar to one in Python like Django

Has anyone used Php frameworks just like we have in Python(Django) and Java(Spring). I want to use something which has end to end solutions. ORM tools, transaction mangement, logging etc. I am not sure how Cake is? But, I am looking something very similar to Django in Php. ...

How to Remove or Disable username for users in Django ?

Hi at all, Is there a way to completly remove or disable username in Django ? I want to use only email and password. . Thanks ^_^ ...

django - How to cross check ModelAdmin and its inlines?

I have two models (ModelParent and ModelChild) with same m2m fields on Subject model. ModelChild has a foreign key on ModelParent and ModelChild is defined as inline for ModelParent on admin page. ### models.py ### class Subject(Models.Model): pass class ModelParent(models.Model): subjects_parent = ManyToManyField(Subject)...

Why are my two date fields not identical when I copy them?

I use django, and have two models with a models.DateTimeField(). Sometimes I need a copy of a date - but look at this: >>>myobject.date = datetime.datetime.now() >>>print myobject.date >>>2010-04-27 12:10:43.526277 >>>other_object.date_copy = myobject.date >>>print other_object.date_copy >>>2010-04-27 12:10:43 Why are these two date...

Use Twisted's getPage as urlopen?

Hi folks, I would like to use Twisted non-blocking getPage method within a webapp, but it feels quite complicated to use such function compared to urlopen. This is an example of what I'm trying to achive: def web_request(request): response = urllib.urlopen('http://www.example.org') return HttpResponse(len(response.read())) I...