django

Django Haystack : search for a term with and without accents

I'm implementing a search system onto my django project, using django haystack. The problem is that some fields in my models have some french accents, and I would like to find the entries which contents the query with and without accents. I think the best Idea is to create a SearchIndex with both the fields with the accents, and the sam...

Django and VirtualEnv Development/Deployment Best Practices

Hi All, Just curious how people are deploying their Django projects in combination with virtualenv More specifically, how do you keep your production virtualenv's synched correctly with your development machine? I use git for scm but I don't have my virtualenv inside the git repo - should I, or is it best to use the pip freeze and t...

Django SELECT (1) AS [a] FROM [my_table] WHERE ([my_table].[id] = ? AND NOT ([my_table].[id] = ? )) (1, 1)

Why is Django executing statements such as this: SELECT (1) AS [a] FROM [my_table] WHERE ([my_table].[id] = ? AND NOT ([my_table].[id] = ? )) (1, 1) This happens when calling is_valid() on a formset created the following way: MyFormSet = modelformset_factory(Table, fields=['my_field'], extra=0) my_form_set = MyFormSet(request.POST...

Django Templates - how do I output the relative path of file when using a FilePathField recursively

I have the following django model: RESOURCE_DIR = os.path.join(settings.MEDIA_ROOT, 'resources') class Resource(models.Model): title = models.CharField(max_length=255) file_name = models.FilePathField(path=RESOURCE_DIR, recursive=True) and I want to give the URL to the file in a template so that the user can view it or downlo...

Apache Django URL problem

I allow users to submit a query at mysite.com/go/QUERY\ If the query contains "/" Apache chokes. From urls.py: (r'^go/(?P<querytext>.*)$', 'mysite.engine.views.go'), Try: http://mysite.com/go/http%3A%2F%2F Result: Not Found The requested URL /go/http:// was not found on this server. Apache/2.2.12 (Ubuntu) Server at ... BUT, ...

Python Shell, Logging Commands for Easy Re-Execution

Say I do something like this in a python shell for my Django app: >>>from myapp.models import User >>>user = User.objects.get(pk=5) >>>groups = user.groups.all() What I'd like to do is stash these 3 commands somehow without leaving the shell. The goal being I can quickly restore a similar environment if I restart the shell session lat...

Django user impersonation by admin

I have a Django app. When logged in as an admin user, I want to be able to pass a secret parameter in the URL and have the whole site behave as if I were another user. Let's say I have the URL /my-profile/ which shows the currently logged in user's profile. I want to be able to do something like /my-profile/?__user_id=123 and have the u...

Django: "TypeError: [] is not JSON serializable" Why?

How can this be that this error was raised? I entered this: def json(self): return json.dumps( { 'items': self.items } ) and got that error (because self.items was an empty queryset (Django) but then, def json(self): return json.dumps( { 'items': [] # Pass in empty list to...

Django, unique time interval for the admin panel

Greetings, Assume I have such model: class Foo(models.Model): type = models.ForeignKey(Type) start_time = models.DateTimeField() end_time models.DateTimeField() For each Foo object that is having the same type, I need this time interval (end_time - start_time) to be unique so that creation of a second Foo with a clashing ...

WSGI/Django: pass username back to Apache for access log

My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful. Is there a way to pass the username back through the WSGI wrapper to Apache after handling the request, so that it...

render_to_response always pass a variable

I'm finding myself always passing a 'user' variable to every call to render_to_response A lot of my renders looks like this return render_to_response('some/template', {'my':context,'user':user}) Is there a way to automatically send this 'user' variable without manually adding it to the context each time a method is called? ...

Using Djangos ImageField to upload an image, rename it to a random filename and create thumbnail

Hay guys, I've wrote a simple upload method for my pictures class Picture(models.Model): path = models.CharField(max_length=200) filename = models.CharField(max_length=200) car = models.ForeignKey('Car') thumb_path = models.CharField(max_length=200) created_on = models.DateField(auto_now_add=True) updated_on = mo...

How do I create a foreign key to the User table in Django?

I'm creating a new model called Tickets which I want to ensure always has a valid userID assigned to it. I'm using AUTH_PROFILE_MODULE to setup the profile which also gives the error NameError: name 'User' is not defined when I try to run syndb. How do I setup a foreign key to make sure this always is the case? ## tickets/models.py c...

fabric python install problem

Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here: Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.py", line 467, in load execfile(fi...

markdown/(X)HTML to BBCode converter python module

Is there any (X)HTML to BBCode coverter python module out there? I'd like to migrate my website forum from markdown to BBCode but I didn't found out any simple way. One option is to convert the markdown text to (X)HTML using the built in django markup module and then convert it again to BBCode. Well, I realized that find a (X)HTML to BB...

How does one run Spawning with Django within a virtualenv?

Because of the way Eventlet, which Spawning depends on, installs itself, it can't be installed into a virtualenv. The following error (wrapped for readability) illustrates: Running eventlet-0.9.4/setup.py -q bdist_egg --dist-dir \ /tmp/easy_install-m_s75o/eventlet-0.9.4/egg-dist-tmp-fAZK_u error: SandboxViolation: chmod('/home/myuser/...

Group form fields in django?

Hello, Is there a way in Django to group some fields from a ModelForm? For example, if there's a model with fields like: age, gender, dob, q1, q2, q3 and a form is created based in such Model, can I group the fields like: info_fields = (age, gender, dob) and response_fields = (q1, q2, q3). This would be helpful to display all fields in ...

ImageField upload_to not working

Hay guys, I'm using an ImageField to upload files, however when i add upload_to to the ImageField it doesnt append the directory to the MEDIA_ROOT MEDIA_ROOT = '/Users/username/Django/site/assests/' picture = models.ImageField(upload_to='uploads') i get an error saying No such file or directory: u'/Users/username/Django/site/assest...

is there a simple to get group names of a user in django

for django.contrib.auth.User and django.contrib.auth.Group i am doing like this for g in request.user.groups: l.append(g.name) Got an error TypeError at / 'ManyRelatedManager' object is not iterable Request Method: GET Request URL: http://localhost:8000/ Exception Type: TypeError Exception Value: 'ManyRelatedManager'...

creating django model for existing database/sql view?

I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb, the db views are created. Can I create in models.py a python class which accesses that view? Is it better practice to just use python's raw sql functionality instead? ---EDIT--- Another problem I ...