django

Database Design: ordered many-to-many relationship

In Django, I have the following models: class Pink(models.Model): ... class White(models.Model): ... pinks = models.ManyToManyField(Pink) ... At some point, I needed to define an ordering of Pinks inside a White (in order to have White1.pinks: P1, P2, P3 instead of a random White1.pinks: P2, P3, P1), so I've created ...

Handling related models in Django for use in Django-Piston

I have setup like so (changed for simplicity) class Author(models.Model) name = models.CharField(max_length=100) ... class Document(models.Model): title = models.CharField(max_length=200) content - models.TextField() author = models.ForeignKey("Author", related_name="documents") date_published = models.DateTimeF...

Issue with Django admin registering an inline user profile admin

I'm currently working on a django project. I'm attempting to add a UserProfile model inline to my User model. In my models.py I have: class UserProfile(models.Model): ''' Extension to the User model in django admin. ''' user = models.ForeignKey(User) site_role = models.CharField(max_length=128, choices=SITE_ROLE) ...

Django Formset populating when it should be blank

My goal is to have a formset that lists 5 versions of the same form. On submit the form should create the filled out forms in the DB. My issue is that the forms come repopulated with data. Which is bad. Any thoughts on what I might be doing wrong? Models.py from django.db import models from django.contrib.auth.models import User PR...

How can I disable a third party API when executing Django unit tests?

I'm trying to build some unit tests against some code I have in Django that runs operations against a third party API. Specifically, I'm synchronizing some user data with MailChimp and using a library that implements the MailChimp API. I have a custom class MailChimpAPI that essentially acts as a thin wrapper around the Python library I...

Equivalent of objects.latest() in App Engine

Hi, What would be the best way to get the latest inserted object using AppEngine ? I know in Django this can be done using MyObject.objects.latest() in AppEngine I'd like to be able to do this class MyObject(db.Model): time = db.DateTimeProperty(auto_now_add=True) # Return latest entry from MyObject. MyObject.all().latest() An...

How do I create a url pattern like controller/action/id in django?

I'm trying to create a url pattern that will behave like controller/action/id route in rails. So far here is what I have : from django.conf.urls.defaults import * import views urlpatterns = ('', (r'^(?P<app>\w+)/(?P<view>\w+)/$', views.select_view), ) Here is my 'views.py': def select_view(request, app, v...

.click() event executed only the first time

I have the next script, "/cashflow/arrow/" calls a django view that gets the data and works with it. Then it returns the data that is loaded in the html. The script works fine in the first click, but when I want to click a link again, nothing happens. <script> $(document).ready(function(){ var prev_months = {{ prev_months }} ...

Python : how to prevent a class variable that is a function to be understood as a method ?

Hi all ! I am currently implementing a django app, for this I try to use a syntax that is consistent with Django's... So here is what I am trying : class Blablabla(Model): #this contains Blablabla's options class Meta: sort_key = lambda e: e sort_key is a key function (for sorting purposes), but of course, it is und...

Is there a ready-to-use form to display lists of objects in the django forms api?

Is there a form(or any other solution) that allows me to quickly build forms that display lists of models(with filtering, ordering etc) like the django admin site does? ...

how to test django registration app process while in development server (no mail)

I am developing a django application on my MAC. The development server that comes with django is great. However, I installed the django-authopenid (combines django-registration app with openID) which follows the 3 step process: user signs up, app sends a confirmation email with link, and user clicks on link to confirm sign-up. Since ...

Django template variable value to string literal comparison fails

I have the following code in my template that supposed to compare the value of watchinstance.shift, which can be either "DAY" or "NIGHT", to a literal string "DAY". The comparisson always fails. {% for watchinstance in watchinstance_list %} {% if watchinstance.shift == "DAY" %} <p>shift is DAY</p> {% endif %} {% endfor %...

how I can get Twitter user email Id in my django web application .

I am using this code to get the userInfo twitter = oauthtwitter.OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token) try: userinfo = twitter.GetUserInfo() except: # If we cannot get the user information, user cannot be authenticated return None screen_name = userinfo.screen_name user, create...

Is there a downside to using ".filter().filter().filter()..." in Django?

Are the following two calls resolved to the equivalent SQL query in Django? Chaining multiple calls Model.objects \ .filter(arg1=foo) \ .filter(arg2=bar) \ ... Wrapping all the args together: Model.objects \ .filter(arg1=foo, arg2=bar) I'd like code to be readable (there are MANY more filter calls than I've shown), but only if the...

Django How to show user's name in his profile in admin console

I attached a UserProfile class to User this way: class UserProfile(models.Model): url = models.URLField() home_address = models.TextField() user = models.ForeignKey(User, unique=True) I have also implemented auto-creating of UserProfile if needed this way: def user_post_save(sender, instance, signal, *args, **kwargs): ...

Django, dynamic apps support.

Hello All, I am about to start a django project, where I need a base deployment, lets say just for admins initially. Later admins can add instances of my main public site. Now, one instance will, obviously be separated by dynamic sub-domains. I need to capture sub-domains from requests, and compute accordingly. It has its own base temp...

Translated strings not showing up when i switch languages in Django site

I have a reasonably simple Django (1.1) site where i need some basic interface and other texts to be translated between two languages. I've created the po files using manage.py makemessages, translated them (using poedit), and compiled the mo files using manage.py compilemessages as outlined in the i18n docs for Django. But the problem...

Django - alert when memcached is down

Is there some ready-made addon that alerts admins about memcached instance being inaccessible from a Django application? I don't mean here monitoring memcached daemon itself, but something that checks if my Django app benefits from caching. My basic idea is to check if cache.get that follow cache.set actually returns something, and if n...

Synch and admin samba users from django?

I want to create and maintain my user database using the default user handling in django, but at the same time synch the samba user profiles so that users can access the django website and the samba shares using the same password. Any hints? ...

How do I test a WSGI application from a script?

I'm debugging a really weird problem with a mod_wsgi-deployed application resulting in Django/Apache (not yet known which) giving status 500 errors to some users instead of the correct 404. I want to exclude Apache from the debugging environment to determine which part of the setup is at fault and send my requests manually to the WSGI ha...