django

Django ModelForm with extra fields

I have done a ModelForm adding some extra fields that are not in the model. I use these fields for some calcualtions when saving the form. The extra fields appear on the form and they are sent in the POST request when uploading the form. The problem is they are not added to the cleaned_data dictionary when I validate the form. ¿How can I...

create a git repo for project skeleton

Hi all I created a custom project skeleton as a start for my django projects, hosted on a public repo at github. Id like to use this as root folder for my new, public and privates projects, also hosted @github. The problem is i cannot use this one as a submodule because as fas ar i know i cannot add submodules inside another submodule...

Dynamic form requirements in Django

Hi, I am about to start a large Django project at work. And the key features are form handling. There is going to be a lot of forms that the users of the app is going to use. And one requirement is that it should be possible to edit the forms in the admin interface of the application. That is, it is not a requirement to add/delete for...

Django: Setting one page as the main page

I'm a newbie at Django and I want to do something that I'm not sure how to do. I have a model SimplePage, which simply stands for a webpage that is visible on the website and whose contents can be edited in the admin. (I think this is similar to FlatPage.) So I have a bunch of SimplePages for my site, and I want one of them to be the m...

Django urlsafe base64 decoding with decryption

I'm writing my own captcha system for user registration. So I need to create a suitable URL for receiving generated captcha pictures. Generation looks like this: _cipher = cipher.new(settings.CAPTCHA_SECRET_KEY, cipher.MODE_ECB) _encrypt_block = lambda block: _cipher.encrypt(block + ' ' * (_cipher.block_size - len(block) % _cipher.block...

How do I make my Django website act as an open id provider? I want logged in users to be able to use my site as an openid provider.

I don't want to let my users login to my site with an openid. I want all of my users who login to my site with their username and password to be able to use my site as an openid server/provider to login to other sites. Is there a Django plugin available to enable this? ...

Open source Django projects

Are there any large django powered sites who has made their source available? I would love to see how a large Django project is built. :) ...

Django: Don't want related manager for two foreign keys to the same model

Hi, I want to get rid of two related managers in a Model because I will never need them. How can I get rid of them? This is my User Profile: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) ... default_upload_container=models.ForeignKey(Container,related_name='idontcare') default_quer...

How to include in code an unique ID related to a mercurial commit?

I'd like to do the same thing that they're doing here in stackoverflow. <link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6274"&gt; <script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6180"&gt;&lt;/script&gt; <script src="http://sstatic.net/so/js/question.js?v=6274" type="text/javascript"></script> D...

Get all related Django model objects

How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE). I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects that have ForeignKeys points to ...

Horizontal (per-row) forms in a Django formset

What's the Django way of presenting a formset horizontally, i.e. one row per form? The as_table method generates multiple forms vertically (with the labels). I need the form fields in table rows (one row per form) and the labels should be on top. I don't see anything out of the box. Is this discouraged for some reason? I should clari...

building dynamic forms in django

I'm trying to build a form dynamically based on the field and its definitions stored in a database. In my db, I have defined 1 checkbox with some label and 1 textfield with some label. How do I build a form dynamically in my view from the data in the db? Thanks ...

Django Group By relation's data

In Django, I can do value(), and then distinct() to group by. A { Foreign Key B } B { String name } However, is it possible to group using a related object's data? I.e. In the above relation, can I group A by B's name? ...

Unicode parsing problem using json.loads

Hi What is the best way to load JSON string in Python. Here is my code which give problem for loading json strings... import json json.loads(str_to_load) I also tried supplying 'encoding' parameter with value 'utf-16', but that didn't work either... Can you please help me solve this problem? Thanks ...

Django db_index issue

Currently, I have 3 models, A, B and C C has foreign key to B B has foreign key to A class C(models.Model): name = models.CharField(max_length=50, db_index=True, unique=True) b = models.ForeignKey(B) class B: ...similar to C class A ...similar to C except for the FK However, the SQL generated by manage.py sqlindexes app doesn...

Using nginx/fcgi/django, I have form posts that give a 504 gateway time-out

I have an app that uses Django with FCGI on nginx. I'm using the third-party apps like James Bennett's django-registration and django-messages from the Pinax Project. Both of these apps have forms that are submitted and save data into the database, then redirect on to a new URL. My issue seems to be that the .save() method on any of the...

GeoDjango, difference between dwithin and distance_lt?

Using geoDjango, what is the difference between myObj.objects.filter(point__dwithin(...etc.)) and myObj.objects.filter(point__distance_lt(...etc.)) ? Are they the same thing, or are they doing subtly different things? ...

adding errors to Django form errors.__all__

How do I add errors to the top of a form after I cleaned the data? I have an object that needs to make a REST call to an external app (google maps) as a pre-save condition, and this can fail, which means I need my users to correct the data in the form. So I clean the data and then try to save and add to the form errors if the save doesn'...

How do I deal with this race condition in django?

This code is supposed to get or create an object and update it if necessary. The code is in production use on a website. In some cases - when the database is busy - it will throw the exception "DoesNotExist: MyObj matching query does not exist". # Model: class MyObj(models.Model): thing = models.ForeignKey(Thing) owner = model...

Django admin different inlines for change and add view

Hi, I need separate views for add and change page. In add page I'd like to exclude some fields from inline formset. I've prepared two TabularInline classes, one of them contains property 'exclude'. I tried to use them as follows: class BoxAdmin(admin.ModelAdmin): def change_view(self, request, obj_id): self.inlines=[ItemCha...