django-models

Django model inheritance w/ custom inclusion_tags

I'm gonna try and simplify this as much as possible. Lets say i have the following: models.py class Person(models.Model): name = models.CharField(max_length=255) def getRealPerson(self): # is there a better way to do this? ret = None try: ret = self.worker except: try: ...

how to disable bulk_action in django 1.1 beta

Hi, I am using django 1.1 beta release. In my project I want to use bulk_action in some models only. How can I disable bulk_action from the remaining models? I want to totally remove action label along with the checkbox; in other words as it would look in Django 1.02. ...

Django -- I have a small app ready, Should I go on private VPS or Google App Engine?

Hi, I have my first app, not that big, but it is the first step. (next big one on the way) Now if I want to put it on my own Linode VPS, I have to configure mod_python or mod_wsgi, as well as memcache, Ngix, mySQL or Postgresql, etc. to make it work. If I put it GAE, All I have to do is convert the models to use GAE's API. What I like...

Is BigTable slow or am I dumb?

I basically have the classic many to many model. A user, an award, and a "many-to-many" table mapping between users and awards. Each user has on the order of 400 awards and each award is given to about 1/2 the users. I want to iterate over all of the user's awards and sum up their points. In SQL it would be a table join between the ma...

Django models overriding save / use a signal / or use a modelform?

I realize this has been asked before, but I wasn't able to find a question that really dealt with what I'm trying to do. I think it's pretty simple, but I'd like to know what the general population thinks is best form here. Lets say we have the following: models.py class TestClass(models.Model): user = models.ForeignKey(User) ...

Django models: how to return a default value in case of a non-existing foreign-key relationship?

I am developing a vocabulary training program with Django (German-Swedish). The app's vocabulary data consists of a large number of "vocabulary cards", each of which contains one or more German words or terms that correspond to one or more Swedish terms. Training is only available for registered users, because the app keeps track of t...

Need help with Django ModelForm: How to filter ForeignKey/ManyToManyField?

Alright, I'm having a hard time explaining this, let me know if I should fill you in on more details. My url looks like this: http://domain.com/&lt;category>/ Each <category> may have one or many sub categories. I want the category page to have a form with a select box (among other fields) containing the category sub-categories. I'...

How to pull a random record using Django's ORM?

I have a model that represents paintings I present on my site. On the main webpage I'd like to show some of them: newest, one that was not visited for most time, most popular one and a random one. I'm using Django 1.0.2. While first 3 of them are easy to pull using django models, last one (random) causes me some trouble. I can ofc cod...

bulk action in django

I am using bulk action in my model.I have switched to django1.2 beta. I want to know that when i perform a bulk action on selected data ,it is not shown on 'action list'(recent actions) displayed at the starting page of django.But if i do some changes maually means as perform in earlier versions then it shows in action list ...

Specifying Django Related Model Sort Order

I have Django models that are lists of items and I want the items on each list to have a separate sort order. Maybe list 1 will sort line items by name, list 2 by date, and list 3 by priority. The models looks more or less like this: class ListItem(models.Model): priority = models.IntegerField(choices=PRIORITY_CHOICES) name = ...

How to agnostically link any object/Model from another Django Model?

I'm writing a simple CMS based on Django. Most content management systems rely on having a fixed page, on a fixed URL, using a template that has one or many editable regions. To have an editable region, you require a Page. For the system to work out which page, you require the URL. The problem comes when you're no longer dealing with "p...

django orm, how to view (or log) the executed query?

Hi folks, Is there a way I can print the query the Django ORM is generating? Say I execute the following statement: Model.objects.filter(name='test') How do I get to see the generated SQL query? Thanks in advance! ...

Advanced search for a specific Django model

I'm aware of full text search applications like Django Solr and solango, etc. What I'm looking to built is more akin to an advanced search for a real estate site. E.g they can choose location, price, etc. similar to www.viewr.com advanced search. What I have done so far is this, under the models custom manager: def advanced_search(se...

raw_id_fields for modelforms

I have a modelform which has one field that is a ForeignKey value to a model which as 40,000 rows. The default modelform tries to create a select box with 40,000 options, which, to say the least is not ideal. Even more so when this modelform is used in a formset factory! In the admin, this is easiely avoidable by using "raw_id_fields", ...

Modifying an attribute for each object in a queryset

Hi I've been using Django for over a year, but I think I've missed out on some very fundamental thing. I have a rather large queryset (1000+ objects) and I'd like to change a single attribute for each of the objects in that queryset. Is this really the way to go? I'm sure there is something simpler? for obj in qs: obj.my_attr = True ...

Using a Django custom model method property in order_by()

I'm currently learning Django and some of my models have custom methods to get values formatted in a specific way. Is it possible to use the value of one of these custom methods that I've defined as a property in a model with order_by()? Here is an example that demonstrates how the property is implemented. class Author(models.Model): ...

Django : Timestamp string custom field

I'm trying to create a custom timestamp field. class TimestampKey(models.CharField): __metaclass__ = models.SubfieldBase def __init__(self, *args, **kwargs): import time kwargs['unique'] = True kwargs['max_length'] = 20 kwargs['auto_created'] = True kwargs['editable']=False super(TimestampKey, sel...

Efficient week statistics for a QuerySet

I am working on an open source Django time tracking app, Djime, and I'm trying to come up with a more efficient way to produce statistics. So far, we've had some rather long-winded procedural code that would get all TimeSlices for a period, and collate them together in a huge nested list/dictionary mess. What I'd like to do is to set up...

Tying in to Django Admin's Model History

The Setup: I'm working on a Django application which allows users to create an object in the database and then go back and edit it as much as they desire. Django's admin site keeps a history of the changes made to objects through the admin site. The Question: How do I hook my application in to the admin site's change...

Admin Form Integration for Custom Model Fields in Django

I need a model field composed of a numeric string for a Django app I'm working on and since one doesn't exist I need to roll my own. Now I understand how "get_db_prep_value" and such work, and how to extend the Model itself (the django documentation on custom model fields is an invaluable resource.), but for the life of me I can't seem ...