django

django - guide to ORM for SQL users ?

django has this complex ORM built in to it, but after spending much time on it, it is still hard for me to make queries that are remarkably simple in SQL. There are even some simple things that I can't find a way to do through the django ORM (e.g. 'select distinct column1 from tablename'). Is there any documentation that shows "For com...

MS Access backend for django

Hi django users-- I've been working on a modification of the django-pyodbc package so that it could be used with MS Access. I need this for a legacy database we are tied to at my organization, and have been doing a rather hacky job specific to my situation, but have also been making useful, generalizable progress in terms of adapting ...

Creating custom Field Lookups in Django

How do you create custom field lookups in Django? When filtering querysets, django provides a set of lookups that you can use: __contains, __iexact, __in, and so forth. I want to be able to provide a new lookup for my manager, so for instance, someone could say: twentysomethings = Person.objects.filter(age__within5=25) and get back...

Subdomain not included in the "?next=" for Django auth login?

I have a login required page at: http://site1.example.com/widget/52312 If I email someone that link for them to click on, they get sent to the Login prompt. But after they login they end up going to http://example.com/widget/52312. How do you keep the subdomain in the site preserved when a user gets prompted through a login process...

django auth_views.login and redirects

Hello I could not understand why after logging in from address: http://localhost/en/accounts/login/?next=/en/test/ I get refirected to http://localhost/accounts/profile/ So i ran search in django files and found that this address is the default LOGIN_REDIRECT_URL for django. What i did not understand is why it gets redirected to...

Translate a python dict into a Solr query string

I'm just getting started with Python, and I'm stuck on the syntax that I need to convert a set of request.POST parameters to Solr's query syntax. The use case is a form defined like this: class SearchForm(forms.Form): text = forms.CharField() metadata = forms.CharField() figures = forms.CharField() Upon submission, the f...

Is this a bug in Django or what? Logging out of the Django Authentication system...will remove all sessiosn?

I'm using sessions across my application. And using logins. When I do a simple: #log out the user. logout(request) ...the request.sessions get erased. What is this??! ...

Access authenticated user outside of a view

I'm trying to access an authenticated user within a form class. I played with passing the request object from a viewto the class init, but it seemed sloppy. Is there a better way to access the authenticated user or request object outside of a view? class LicenseForm(forms.Form): '''def __init__(self, *args, **kwargs): #self.fiel...

Connecting the login flow between Android/iPhone app and the web.

When the person opens my app, I want to display a button. The user clicks this button, and it opens a browser (embedded, of course) inside the app, allowing the user to LOGIN through that web page. Of course, when the person logs in, it only logs in to that web server. The web service now knows that the user is logged in. As the user ...

Everything is ok, but my 127.0.0.1:8000 can't show anything, why ? I used django-sphinx

from djangosphinx.models import SphinxSearch def xx(request): queryset =File.search.query('test') #return HttpResponse(queryset)#<------1 return render_to_response('a.html',{'a':queryset})#<--------2 and class File(models.Model): name = models.CharField(max_length=200) tags = models.CharField(max_length=200) # We ...

setting help_text for each choice in a RadioSelect

I can set the help_text attribute on any form field, but is it possible to set help_text on the choices used for a RadioSelect()? I'd looking for a clean way to show some help information under each radio button. Below is the code for the model and the form, I can render the name attribute in a template with the label, input element an...

Creating "classes" with Django

I'm just learning Django so feel free to correct me in any of my assumptions. I probably just need my mindset adjusted. What I'm trying to do is creating a "class" in an OOP style. For example, let's say we're designing a bunch of Rooms. Each Room has Furniture. And each piece of Furniture has a Type and a Color. What I can see so ...

How to redirect to a query string URL containing non-ascii characters in DJANGO?

How to redirect to a query string URL containing non-ascii characters in DJANGO? When I use "return HttpResponseRedirect(u'/page/?title=' + query_string)" where the query_string contains characters like "你好", I get an error "'ascii' codec can't encode characters in position 21-26: ordinal not in range(128), HTTP response headers must be...

How do I properly setup my python paths and permissions for Django+mod_wsgi deployment?

The issue I'm having is my wsgi file can't import the wsgi handlers properly. /var/log/apache2/error.log reports: ImportError: No module named django.core.handlers.wsgi Googling this brings up a couple results, mostly dealing with permissions errors because www-data can't read certain files and/or the pythonpath is not correct. ...

how does get the title and content of this code in django-sphinx.

i get this string: {'id': 1, 'weight': 101, 'attrs': {'date_added': 1265274382, 'group_id': 1}}{'id': 2, 'weight': 100, 'attrs': {'date_added': 1265274382, 'group_id': 1}}{'id': 4, 'weight': 100, 'attrs': {'date_added': 1265274382, 'group_id': 2}} i want to get the real data(title and content): and my view is : from djangosphinx.mo...

can i make a field in database use this django code ,and don't use 'python manage.py startapp xx'

from django.db import models class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) can i ??? thanks ...

Python regex problem

What I am trying to do: Parse a query for a leading or trailing ? which will result in a search on the rest of the string. "foobar?" or "?foobar" results in a search. "foobar" results in some other behavior. This code works as expected in the interpreter: >>> import re >>> print re.match(".+\?\s*$","foobar?") <_sre.SRE_Match obj...

global variable from django to javascript

I would like some variables from my settings.py to be available in every javascript running across my project. What is the most elegant way of achieving this? Right now I can think of two: write a context processor and declare those globals in a base template. All templates must extend the base template. declare those globals in a dy...

moving a function out of my method in django

Hay i have a method in my view which uploads an image, the image is then saved to a db object. I want to remove this from my view and either put it in my model or a seperate file. filename_bits = request.FILES['image'].name.split(".") filename_bits.reverse() extension = filename_bits[0] # create filename and open a destination filename...

Imagefield in Inline formset not populated

I have this piece of code: vehicle = get_object_or_404(Vehicle, stock_number=stock_number) if request.method == 'POST': vehicle_form = VehicleForm(request.POST, instance=vehicle) photos = PhotosFormSet(request.POST, request.FILES, instance=vehicle) if vehicle_form.is_valid() and photos.is_valid(): vehicle = vehicle_...