django-models

How to use schemas in Django?

I whould like to use postgreSQL schemas with django, how can I do this? ...

Duplicate django query set?

I have a simple django's query set like: qs = AModel.objects.exclude(state="F").order_by("order") I'd like to use it as follows: qs[0:3].update(state='F') expected = qs[3] # throws error here But last statement throws: "Cannot update a query once a slice has been taken." How can I duplicate the query set? ...

Iterating over model attributes when creating a template in Django

I'm using Django in Google App Engine. If I have the class class Person(): first_name = StringProperty() last_name = StringProperty() and I have an instance where Person.first_name = Bob and Person.last_name = Vance, can I create a template that iterates over the Person attributes to produce: <tr> <td>First</td> <td>Bob</td>...

unique value field based on another field in django

Preface: I am new to django and to db design. SUPEREDIT: I made some significant changes, so the answers before my changes may reference things not here. I apologize. I'll get right to the code: models.py: class Player(models.Model): name = models.CharField() class Team(models.Model): name = models.CharField() members = m...

How to store arbitrary number of fields in django model?

I'm new to python/django. I need to store an arbitrary number of fields in a django model. I'm wondering if django has something that takes care of this. Typically, I would store some XML in a column to do this. Does django offer some classes that makes this easy to do whether it be XML or some other(better) method? Thanks, Pete ...

Overriding inherited behavior

I am using Multi-table inheritance for an object, and I need to limit the choices of the parent object foreign key references to only the rules that apply the child system. from schedule.models import Event, Rule class AirShowRule(Rule): """ Inheritance of the schedule.Rule """ rule_type = models.TextField(default='onAi...

How to format dateTime in django template?

That: {{ wpis.entry.lastChangeDate|date:"D d M Y" }} gives me (why?): 2009-07-24 21:45:38.986156 and i don't know how to skip fraction part... In my model i have: addedDate = models.DateTimeField(default=datetime.now) ...

Add field to model, as annotate do

For example, I have a model Posts and Comments. Post.objects.annotate(Count('comment')) I am making such query to get count of comments for every post. But in template i should check if this value greater than 4. As I know there is no such templatetag. For now I put method in model that executes comparision operation. The question is...

how to add data into ManyToManyField?

I can't find it anywhere, so your help will be nice for me :) Here is that field: categories = models.ManyToManyField(fragmentCategory) FragmentCategory: class fragmentCategory(models.Model): CATEGORY_CHOICES = ( ('val1', 'value1'), ('val2', 'value2'), ('val3', '...

django one-to-one left join is null?

I've got models like those in django: class User(models.Model): name = models.CharField(max_length = 128) class Message(models.Model): sender = models.ForeignKey(User, related_name = 'messages_sent') recipient = models.ForeignKey(User, related_name = 'messages_recieved') subject = models.CharField(max_length = 128) body = mod...

Working with Django LocalFlavor Zip as a Model Field

What's the best way to implement the following: ### models.py >>> from django.db import models >>> from django.contrib.auth.models import User # Create the client class. >>> class Client(models.Model): ... user = models.OntToOneField(User) ... zip = ***???***() ### forms.py >>> from django.forms import ModelForm # Create the fo...

Django extra params question

Hello, Here is a table "myTable" with columns of "col1", "col2", "col3", ..., "col5". The types of these columns are all float. Now for two values from any two columns of these columns, I may need to add, or subtract, or multiply or divide these two values. With this result, I do a condition check. For example, I want to retrieve...

Google app engine tutorial problem - new datastore model

So i've just finished the google app engine greetings tutorial. All well so far. I then decided to try and add a new datastore model and then set it in the existing handler. I added a 2nd content field called "content2" and then tried to set it in the handler Guestbook(), but it keeps borking out. I'm sure it will be the silliest error, ...

Django: Easily add extra manager for child class, still use default manager from AbstractBase

Hi, this question is about the last example on Custom managers and model inheritance. I want to be able to do something similar to the following: class ExtraManagerModel(models.Model): # OtherManager class supplied by argument shall be set as manager here class Meta: abstract = True class ChildC(AbstractBase, ExtraManage...

Django FileField with upload_to determined at runtime

I'm trying to set up my uploads so that if user joe uploads a file it goes to MEDIA_ROOT/joe as opposed to having everyone's files go to MEDIA_ROOT. The problem is I don't know how to define this in the model. Here is how it currently looks: class Content(models.Model): name = models.CharField(max_length=200) user = models.Forei...

Django formsets, filtering foreignkeys

Hey there, I've been looking through the site and trying to find something to help me, but I can't find anything. I'll begin with showing the models that relate to this: class Game(models.Model): home_team = models.ForeignKey(Team, related_name='home_team') away_team = models.ForeignKey(Team, related_name='away_team') round ...

How to manage many to one relationship in Django

Hello, I am trying to make a many to one relationship and want to be able to control it (add -remove etc) via the admin panel. So this is my model.py: from django.db import models class Office(models.Model): name = models.CharField(max_length=30) class Province(models.Model): numberPlate = models.IntegerField(primary_key=True...

Most efficient way to match a certain number of items in a db.Model ListProperty

In reference to this different but not unrelated question I will borrow the example models. class Foo(db.Model): bars = db.ListProperty(db.Key) class Bar(db.Model): pass If I have a certain Foo entity and I want to get all of the other foo entities also containing a certain bar Key in its bars ListProperty, I would use the following...

Actions triggered by field change in Django

How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model: class Game(models.Model): STATE_CHOICES = ( ('S', 'Setup'), ('A', 'Active'), ('P', 'Paused'), ('F', 'Finished') ) name = models.CharField(max_length=100) owner = mode...

django one to many issue at the admin panel

Greetings, I have these 2 models: from django.db import models class Office(models.Model): name = models.CharField(max_length=30) person = models.CharField(max_length=30) phone = models.CharField(max_length=20) fax = models.CharField(max_length=20) address = models.CharField(max_length=100) def __unicode__(self)...