django

Django: Why don't foreign key lookups automatically use the pk?

I have class Achievement(MyBaseModel): pass class Alias(MyBaseModel): achievements = models.ManyToManyField('Achievement') >>> ach = Achievement.objects.all()[1] This works : >>> Alias.objects.all().filter(achievements__pk__contains=ach.pk).count() 77L But this doesn't : >>> Alias.objects.all().filter(achievements__cont...

Django Caching for a Blog

I have a blog written in Django, and I started using the basic Django caching middleware with the file system caching backend. Unfortunately, this led to two things being cached that shouldn't have been: admin links (e.g. "Edit this post") for logged-in users and prepopulated comment forms based on cookies. To get around that, I starte...

Django. Confirming user creation by mail.

I want to create django users from django application, and then confirming user creation by sending them e-mail with validation link. How can I safely generate this link from user details (I don't want to generate random value and store it in DB, and I don't want to use any external modules like Pinax for this) ...

Django Template Error : Template u'base.html' cannot be extended

I get this error when I run a django app (dpaste) Template error In template c:\python\projects\mycms\dpaste\templates\dpaste\base.html, error at line 1 Template u'base.html' cannot be extended, because it doesn't exist 1 {% extends "base.html" %} But the "base.html" do exist in the template directory and it has this one line in ...

How do I get the related objects In an extra().values() call in Django?

Thank to this post I'm able to easily do count and group by queries in a Django view: http://stackoverflow.com/questions/327807/django-equivalent-for-count-and-group-by What I'm doing in my app is displaying a list of coin types and face values available in my database for a country, so coins from the UK might have a face value of "1 f...

Will Django's cache modules work on Google App Engine?

I am running Django (1.0.2) on Google App Engine, and would like to know which (if any) of the following Django caching modules ought to inherently work with Google's memcache implementation: Middlewear django.middleware.cache.UpdateCacheMiddleware django.middleware.common.CommonMiddleware django.middleware.cache.FetchFromCacheMiddlew...

Setting up several Django apps on one server

Hi all...I've been trying to configure two separate Django apps on one server such that they can be accessed at different URL's...using the below config, I can access the first app, but I'm at a loss at how to include the setup for the second app. The admin media is also not being loaded at all NameVirtualHost *:8032 ServerName ...

Django - Select a random photo from each Album

Am trying to get a random photo from each album from the data created by syncr. The model (abbreviated) looks like this: class Album(models.Model): title = models.CharField(max_length=200) photos = models.ManyToManyField('Photo') class Photo(models.Model): title = models.CharField(max_length=200) I've tried lots of diff...

Google App engine template unicode decoding problem

When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp import template templatepath = os.path.join(os.path.dirname(file), 'template.html') self.response.out.write (template.render( templatepath , template_values)) I come across the following error: <type 'exceptions.UnicodeD...

What is the best django model field to use to represent a US dollar amount?

I need to store a U.S. $ dollar amount in a field of a Django model. What is the best model field type to use? I need to be able to have the user enter this value (with error checking, only want a number accurate to cents), format it for output to users in different places, and use it to calculate other numbers. ...

Best way to handle request variables in Django

I have a form 'in the wild' that takes many different variables - which may or may not be populated. try: app_version = request.REQUEST["appVersion"] except: app_version = '' try: app_name = request.REQUEST["appName"] except: app_name = '' try: app_code_name = request.REQUES...

Make Django admin use translated field names

I'm doing a localization of a Django app. The front-end website works fine and the Django admin site picks up the selected language as well. But it only applies the language settings in some places and uses the default English versions of field and column names, even though these have been translated. Why? How can I make it use the tra...

Can you find out if a Django Model instance is "dirty"?

I really like the feature of SQLAlchemy that allows you to see if an object is dirty: if it has been modified since it was retrieved from the database, or the last time it was saved. Is it possible to find this information from the Django ORM? Note this is not the same as Dirty fields in django, as I don't care about what the previous ...

Using and Installing Django Custom Field Models

I found a custom field model (JSONField) that I would like to integrate into my Django project. Where do I actually put the JSONField.py file? -- Would it reside in my Django project or would I put it in something like: /django/db/models/fields/ Since I assume it can be done multiple ways, would it then impact how JSONField (or any cu...

Extending Django commenting system

This is how I want commenting to work on my site: if the user is logged in, they are presented with an "add comments" box which has a text field for the comment text, and a checkbox that will post the comment anonymously if checked if the user is not logged in, it will present the user with everything above, plus an extra text field wh...

Django: Why some fields clashes with other

Hi! I want to create an object that contains 2 links to users. For example class GameClaim(models.Model): target = models.ForeignKey(User) claimer = models.ForeignKey(User) isAccepted = models.BooleanField() but I am getting an error when running server: Accessor for field 'target' clashes with related field 'User.gamecl...

Reverse foreign key to django-fts searchable model in template

I have a pair of Django models with a foreign key, one of which is searchable with django-fts, say: class Foo(models.Model): ... class Bar(fts.SearchableModel): foo = models.ForeignKey(Foo) When I have an instance of Foo, in view I can insert print foo.bar_set.all() and I see an array of results. However if I try to use it in...

Convert Html to Django Fixture (JSON)

We've got a couple of Django flatpages in our project, that are based on actual HTML files. These files undergo some changes once in a while and hence have to updated in the database. So i came up with the idea of simply copying the plain HTML text into a json fixture and do an manage.py loaddata . However the problem is, that there are ...

AttributeError: 'unicode' object has no attribute '_meta'

I am getting this error on "python manage.py migrate contacts". The error info does not pinpoint problem location. Here is the error description: http://dpaste.com/68162/ Hers is a sample model definition: http://dpaste.com/68173/ Can someone point me to right direction??? I got this: http://blog.e-shell.org/66 but can not figur...

Many choices in one model's field?

I have ` CATEGORY_CHOICES = ( ('A', 'B', 'C') )` and I would let field: myChoice = models.CharField(choices=CATEGORY_CHOICES) have many values from CATEGORY_CHOICES (1-3). I am just starting use Django so an example will be nice :) ...