django

Proper way to catch KeyError in Django?

I am creating an API where a URL is sent to the server. I want to get the username, etc from the URL. I use the following code to do that: try: username = request.REQUEST['username'] message = request.REQUEST['message'] time = request.REQUEST['time'] except KeyError: ... However, there are times when the URL does...

Why does adding these constants to my template vars keep me logged in?

I wrote a wrapper around render_to_response that looks like this from app import constants def response(request, template, vars={}): if '.' not in template: template += '.html' template_vars = {} for constant in dir(constants): if constant[:2] == '__': continue template_vars[constant] = getattr(cons...

How do I translate the output of a filter in Django

I have some template code that looks like: <input type='submit' value='{{ need.satisfied|yesno:"Resend this document now,Send this document now" }}' /> I'd like to be able to translate it but that appears to be difficult to accomplish. http://code.djangoproject.com/ticket/3804 mentions {{ _("Some String") }} which appears to work...

Django - how to specify a database for a model?

Is there a way to specify that a model (or app, even) should only ever use one particular database? I am working with a legacy database that I don't want to change. I have two databases - the 'default' is an sqlite one that could be used for admin etc, and the legacy one. I used inspectdb to create a model for (part of) the legacy datab...

Django South problem

Hello I have an already existing app with alot of database entries. class Foo(models.Model): value = models.TextField(u"Value") For this I do this: python manage.py schemamigration myapp --initial python manage.py migrate myapp I change the model to such: class Foo(models.Model): value = models.TextField(u"Value") liv...

Check whether object is in QuerySet of related objects

I am building an application having to do with game achievements, and I want to display for each game, a page that lists the related achievements. That is done. However, I also want each user to be able to see in that list which achievements they have completed. My model is like this: class Achievement(models.Model): game = mode...

Get first item of QuerySet in template

In my blog app I want to display a list of blog posts and the first image connected to this post. Now I do it this way: {% for image in entry.image_set.all|slice:"1" %} <img src="{{ image.get_absolute_url }}"> {% endfor %} Is there a template shortcut I don't know about, or maybe I should just write my own Manager? ...

Creating a django signal for user details updation

Hi All, I am working on a django project, where I want to implement a signal which should be called when some user address is changed. I have seen the built-in signals but they do not seem to work in my case, because if i use save that will be called in other save events as well and though I am able to create a custom signal, I could no...

Django-like data model in ASP.NET MVC

Is there anything similar to Django data models in ASP.NET MVC where I can easily manipulate my classes and objects and don't worry about SQL realization of it? ...

Django how to modify database records by template

I want to delete the records which i select, and run.html will refresh, how can i do that? Since i use function run in views.py to send records in database, and run need one parameter build which can be got by using run.name, so i think i need to pass "run.name" and "run.id" when i click the submit button. urls.py urlpatterns = pattern...

How to: create .doc files using templates with django/python

Hello, I am writing a django application and there is something I don't know how to do. Say you have a database with users and several .doc files you might want to send to those users (postal letters, not electronicaly). I am wondering if there is a way to automatically create those letters from templates using my user database to fill ...

Django mod-python error

Can someone please tell what this strange error is Mod_python error: "PythonHandler django.core.handlers.modpython" Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch log=debug) File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 464, in imp...

Which framework is the most friendly for shared hosting environment?

I am currently comparing available web frameworks to be used for my next projects. The only criterion I need are speed and portability, i.e shared hosting friendly. I have tried Ruby on Rails, but its speed/performance is not good enough for me. I am interested in Django, but I think it is not that friendly on shared hosting - correct m...

Django Admin: Alter how data is displayed

I have a model with a json field. The contents of which may or may not be pretty-printed, I don't really mind either way as long as the data is valid. However when it is displayed in django admin I would like for the contents of the field to be pretty printed so that it is easy to read. I don't mind if this means the pretty printed versi...

Using the facebook connect JavaScriptSDK redirecting to port :8000

I'm running a Django server on localhost:8000/ and have the facebook callback URL set to exactly that "http://localhost:8000/" however, when I log in, it redirects to "http://localhost/". Is there a way around this? What am I doing wrong? ...

Django: Test confusion

In the unit tests that I wrote, I provide a test fixture for each TestCase. However, I keep getting duplicate (IntegrityError) when it runs in the test suite. So, I am wondering, isn't the database supposed to be created and populated at the beginning of each TestCase and after each test has be executed in that TestCase so that I can p...

Handling race condition in model.save() (Django)

How should one handle a possible race condition in a model's save() method? For example, the following example implements a model with an ordered list of related items. When creating a new Item the current list size is used as the its position. From what I can tell, this can go wrong if multiple Items are created concurrently (will it...

Django/Satchmo - Clearing the Shopping Cart after Successful PayPal payment

After a successful Paypal payment, I receive the IPN and the payment creates a new order. However, the shopping cart does not clear. Rather than wait for the IPN I would like to alter the payment.view.checkout.success code to clear the cart after a successful payment. The code to empty the cart is: for cart in Cart.objects.filter(...

Best way to do register a user in Django

I'm trying to implement User Registration for my Django app. The book I read mentions UserCreationForm but I need more than just name, password, and email address. I could implement my own user object and use ModelForm I think, but then I lose out on some of the django conveniences for authentication. Finally, I read something about U...

Cookie sharing between sites with the same top level domain

Hi guys, web newbie here, I'm sharing cookies between two sites of mine, myserver.com and other.myserver.com, by using in Django: SESSION_COOKIE_DOMAIN = '.myserver.com' This works in most cases, but when the first site is reached through an iframe like so: <iframe src="https://myserver.com/page?data=asdsafaf"&gt;&lt;/iframe&gt; ...