django

Figure out child type with Django MTI or specify type as field?

I'm setting up a data model in django using multiple-table inheritance (MTI) like this: class Metric(models.Model): account = models.ForeignKey(Account) date = models.DateField() value = models.FloatField() calculation_in_progress = models.BooleanField() type = models.CharField( max_length=20, choices= METRIC_TYPES )...

Maximum recursion depth exceeded when providing unique id

I wanted to provide unique ID for different categories of models in my db. So I've introduced a dummy model : class GUUID(models.Model): guuid = models.PositiveSmallIntegerField(_(u"Dummy GUUID"), default=1) and in model that I want to have unique ID: class Event(models.Model): unique = models.IntegerField(blank=False, edita...

Django - AutoField with regards to a foreign key

I have a model with a unique integer that needs to increment with regards to a foreign key, and the following code is how I currently handle it: class MyModel(models.Model): business = models.ForeignKey(Business) number = models.PositiveIntegerField() spam = models.CharField(max_length=255) class Meta: unique_to...

Django: Reading FileField Contents Immediately After Save

I have a model form with a file field on it. I have a post_save signal attached to the model so that I can then pass the uploaded file on to a 3rd-party via a web service (using Suds). The web service call is dying when I try to pass it the file contents: it throws "UnicodeDecodeError: 'ascii' codec can't decode byte . . . " (much like i...

Python import module results in NameError

I'm having a module import issue. using python 2.6 on ubuntu 10.10 I have a class that subclasses the daemon at http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ . I created a python package with a module containing code that imports some models from a django project. The code works when used from a class, no...

Is there a way to resist unnecessary joins that are only checking id existence when using Django's orm?

In example. If I have a model Person who's got a mother field, which is a foreign key.. The following is getting to me: p = Person.object.get(id=1) if p.mother_id: print "I have a mother!" In the above example, we've issued one query. I've tricked Django into not fetching the mother by using the _id field instead of mother.id. But...

Django: How to override unique_together error message?

In a model's Meta class, I define a unique_together. I have a ModelForm based on this model. When I call is_valid on this ModelForm, an error will automatically raised if unique_together validation fails. That's all good. Now my problem is that I'm not satisfied with the default unique_together error message. I want to override it. How ...

django full url in get_absolute_url

I want to have a absolute/complete url when i call my models get_absolute_url method in template. in my entry model i have below: def get_absolute_url(self): return ('blog_entry_detail', (), { 'year': self.pub_date.strftime("%Y"), 'month': self.pub_date.strftime("%b").lower(), ...

How do I update a single field, using a variable as a field name?

I want to do something like for field in field_list: my_table.field = new_value Couldn't find any documentation on how to do the above with a variable. ...

Limiting Django query results for ajax XML app

Hi all, Here is my model: class Members(models.Model): firstname = models.CharField(max_length=30) lastname = models.CharField(max_length=30) gender = models.CharField(max_length=1) email = models.EmailField() password = models.CharField(max_length=30) country_cod...

Updating Feedparser Feeds in Django

So I'm writing a basic feed aggregator/popurls clone site in Django and having trouble getting the feeds to update. For each feed source, I have a separate app to parse and return the requested info, for the sake of simplicity let's say it's just getting the feed title. eg: #feed source xyz views.py from django.http import HttpResponse...

Is there a simple example to understand django signal

Suppose a user creates his account in a website so i would like to use django signals to notify the system admins that a new user has been created. I really dont know how to do this with Django signals Thanks in advance ...

using django-jython

I have read from the django-jython wiki that 1.1.1 is not compatible with django 1.2, and that jython does not works with the default django backend. Does this means I'm unable to use django 1.2 with jython at the moment? ...

Replacing Words in TextField In Django

In django, in TextField, how to we replace, [vimeo 123456] with <iframe src="http://player.vimeo.com/video/123456" width="400" height="225" frameborder="0"></iframe> Thank you. ...

Help me understand my mod_wsgi Django config file..

I was wondering why this works: sys.path.append('/home/user/django') sys.path.append('/home/user/django/mysite') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' but this doesn't? sys.path.append('/home/user/django') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' I thought that adding the django folder would aut...

nginx + fastCGI + Django - getting data corruption in the responses sent to the client

I am running Django behind nginx using FastCGI. I have discovered that in some of the responses sent to the client, random data corruption is occurring in the middle of the responses (might be a couple hundred bytes or so in the middle). At this point I have narrowed it down to either being a bug in either nginx's FastCGI handler or Dj...

Specific Quote Issue

Hey everyone, Here is my problem. I have a model Project, that has a quote field in it. When a new instance of project is created I need to append the last 2 digits of the year plus a hyphen onto the start of the "quote" field. Ex. 2010 = "10-". Im just not quite sure how to start it? As of right now I have hard coded in "10-" in a...

use multiple CPUs on Django on Windows

I have a Django app running on Windows (via Apache + mod_wsgi) that's CPU-bound. But Apache on Windows only does MPM (multi-thread) workers, not prefork (multi-process workers), and a single Python interpreter won't take advantage of multiple CPUs. I would switch to FastCGI, but that requires Flup, which is not supported on Windows. T...

How to display a list of objects containing many-to-many relations in Django template?

I have the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model): title = models.CharField(max_length=100) date = models.DateField() tags = models.ManyToManyField(Tag) In a view I create a list of Entry object and want to show the elements in the template: {% for entry...

change list display link in django admin

I am trying to change the link for an object in the django admin list display. Here is what I have so far: class FooModelAdmin(admin.ModelAdmin): fields = ('foo','bar') list_display = ('foo_link','bar') def foo_link(self,obj): return u'<a href="/foos/%s/">%s</a>' % (obj.foo,obj) domain_link.allow_tags = True ...