django

What's the most efficient way to retrieve objects of many-to-many relationships?

I have the following two models class Author(Model): name = CharField() class Publication(Model): title = CharField() And I use an intermediary table to keep track of the list of authors. The ordering of authors matter; and that's why I don't use Django's ManyToManyField. class PubAuthor(Model): author = models.ForeignKe...

How to make a Template extend another one?

I've got some templates which I'm building from some data I've got stored in my DB: my_template = Template(string_data) Now I want that template to extend another one (also stored as text in the DB). How can I do that? Looking for something like: my_template.base = other_template Or whatever the syntax is. Can't find documentation ...

Django return redirect() with parameters

In my view function I want to call another view and pass data to it : return redirect('some-view-name', backend, form.cleaned_data) , where backend is of registration.backends object, and form.cleaned_data is a dict of form data (but both must be either sent as *args or **kwargs to prevent raising Don't mix *args and **kwargs in call ...

Django form items disappear

Form items disappear (forms.ModelMultipleChoiceField) if forms.CharField is not part of the form. forms.py class Test(ModelForm): name = fields.CharField(max_length=200) events = forms.ModelMultipleChoiceField(queryset=Event.objects.all()... class Meta: model = Events fields = ("events", "name") The abo...

Problem with uploading and saving an image in Django

(13, 'Permission denied') error occurs when trying to upload an image in Django i have checked the access rights of the directory in which image will be saved drwxr-xr-x 2 hsrd hsrd 4096 2010-03-19 15:49 media Please a suggest a solution for this. if request.method == 'POST': if 'file' in request.FILES: file = req...

No module named django.core

Hi, I'm following the step by step guide here and I hit an error at the "Create Django Project" step when I try the command; django-admin.py startproject myproject The error: Traceback (most recent call last): File "/usr/local/bin/django-admin.py", line 2, in from django.core import management ImportError: No module ...

Auto initialization for a django app on apache/fcgi

Hello, We are implementing a web service that is hosted in Dreamhost VS, uses Apache with FCGID running a Django application. Our key issue is that the initialization of our application is extreamly long (10 sec) to enable very fast responces. We would like to be able to have a process running waiting for users at all times in a post...

How to guarantee two related models get saved?

How do I guarantee data only gets saved when the related objects are both filled with data? class A(models.Model): title = models.CharField(max_length=255) slug = models.SlugField() class B(A): author = models.CharField(max_length=255) url = models.URLField() I insert data by accessing model B: b = B() b.title = 'ti...

Rake:task equivalent in Django

I have a django application where i'll like to have a script that i'll run once a day to validate the models in the database, and delete some objects. How cand i make it ? I want something equivalent to rake:task in rails. ...

Django: ImportError: No module named ?z?

Hi I am trying to deploy a django app with uwsgi. I keep getting Import Errors that look like this: ImportError: No module named ?z? -or- ImportError: No module named ?j? -or- ImportError: No module named `?6 So basically the output of the module seems like gibberish and I am unable to figure out the problem. Does anybody have an i...

Web Framework - Ruby on Rails or Django for beginner?

I am still new to web framework and I am thinking of choosing either Ruby on Rails or Django. Which one should I go for as a beginner? ...

empty_form initial value for a modelformset_factory

I try to add initial values to the empty form of a modelformset_factory. FormSet = modelformset_factory(MyModel, extra=2) formset = FormSet(queryset=MyModel.objects.none(), initial=[{'foo': 'bar'}, {'foo': 'bar'}]) I would like to set initial value to the formset.empty_form , how can I achieve this ? ...

Django - Are model save() methods lazy?

Are model save() methods lazy in django? For instance, at what line in the following code sample will django hit the database? my_model = MyModel() my_model.name = 'Jeff Atwood' my_model.save() # Some code that is independent of my_model... model_id = model_instance.id print (model_id) ...

Django download file not working

I'm trying to make a script for downloading uploaded files, on the user's machine. The problem is that the download simply doesn't work (it either downloads me an empty file, or gives me some errors). the last error is: coercing to Unicode: need string or buffer, FieldFile found def download_course(request, id): course = Courses.ob...

Case-insensitive query that supports multiple search words

I'm trying to perform a case-insensitive query. I would generally use __icontains, but since it doesn't support the .split() method, I'm stuck to using __in instead: def search(request): query = request.GET.get('q', '') query = query.lower() product_results = [] category_results = [] if query: product_result...

Django: How to check if there are field errors from within custom widget definition?

I'd like to create widgets that add specific classes to element markup when the associated field has errors. I'm having a hard time finding information on how to check whether a field has errors associated with it, from within widget definition code. At the moment I have the following stub widget code (the final widget will use more co...

form.cleaned_data as a dictionary

Why when I call a function like this : function(request, **form.cleaned_data) I can send form's data as a dictionary, but when I try doing like this : data = **form.cleaned_data I'm getting error ? ...

Admin site registering models

I have those models class A(models.Model): name = CharField(max_length=255) class B(models.Model): name = CharField(max_length=255) relation = ForeignKey(A) And I can register like this: admin.site.register(A) admin.site.register(B) In /admin/ page, I can see A and B registered. and "Add B" admin page, will display a c...

Django: How can I apply the login_required decorator to my entire site ( excluding static media )?

The example provides a snippet for an application level view, but what if I have lots of different ( and some non-application ) entries in my urls.py file, including templates? How can I apply this login required decorator to each of them? (r'^foo/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'), (r'^$', 'django.views.generic.simple.direct...

Django deployment tools

I'm looking for some tool (or set of tools) that could help me automate deploying Django projects with all required dependencies. I googled for some solutions but I am curious what are your favorite ones. ...