django-models

Google app engine - structuring model layout with regards to parents?

How does one go about structuring his db.Models effectively? For instance, lets say I have a model for Countries, with properties like "name, northern_hemisphere(boolean), population, states (list of states), capital(boolean). And another model called State or county or something with properties "name, population, cities(list of cities...

Django Forms With foreign key

Hi, I have 2 models in django, and im also using ModelForm, my question is the second model have a froreignkey of the 1, and i want to have one page when generating the form. It's possible, how to link the two forms in one page. Class Event(models.Model): id = models.AutoField(primary_key=True) name = models.CharField() class Date(...

Django ORM: time zone support

Hi, Can you recommend any implementation of Time Zones support for Django's ORM (DateTime filed)? Ideally it has to be DB-agnostic and transparent, allowing to use all standard ORM things like __lt, __gt etc. I guess it needs to store time in UTC plus local timezone. Thanks! ...

Smarter removing objects with many-to-many relationship in Django admin interface

I'd like to remove some object with many-to-many relationship using Django admin interface. Standard removing also removes all related objects and the list of removed objects displayed on confirmation page. But I don't need to remove related objects! Assume we have ContentTopic and ContentItem: class ContentTopic(models.Model): nam...

Django Admin -> Change Order of Fields, including Inline Fields

Hi I have a "Person" Model which has a one-to-many Relations to other Models, for instance Address. I want to edit these models on the same page as Person, which I can already do via inlines. But I also want to change the order of the fields. I want the (inline) field "Address" to be the third item in the list, but for fields ('first_...

Indefinitely repeating events in django calendar

I am working on a calendar application in django and want to support events which repeat an infinite amount of times after a given start date. I will store "block events" where each block includes data about a certain event (title, description...) as well as the pattern with which it repeats and an "expiration date". This way I only stor...

What's the best way to represent many booleans in a django model?

I have a model which represents the user's display preferences. Just about all of these preferences are boolean values. Instead of having 50 boolean columns, is there a better way to go about this? In the future when I want to add a new item, I don't want to have to add a new column in my database. ...

Filtering models with inheritance in Django

I have two Django model classes that are structured similar to the following: class Build(models.Model): project = models.CharField(max_length=100) ... class CustomBuild(Build): custom_type = ... ... I want to select all Builds and CustomBuilds (each CustomBuild has a one-to-one relationship with a Build) from the data...

Google app engine ReferenceProperty relationships

Hi guys, I'm trying to get my models related using ReferenceProperty, but not have a huge amount of luck. I have 3 levels: Group, Topic, then Pros, and Cons. As in a Group houses many topics, and within each topic could be many Pros and Cons. I am able to store new Groups nice and fine, but I don't have any idea how to store topics und...

Filter and sort music info on Google App Engine

I've enjoyed building out a couple simple applications on the GAE, but now I'm stumped about how to architect a music collection organizer on the app engine. In brief, I can't figure out how to filter on multiple properties while sorting on another. Let's assume the core model is an Album that contains several properties, including: ...

Counting and filtering objects in a database with Django

I'm struggling a little to work out how to follow the relation and count fields of objects. In my Django site, I have a profile model: user = models.ForeignKey(User, unique=True) name = models.CharField(_('name'), null=True, blank=True) about = models.TextField(_('about'), null=True, blank=True) location = models.CharField(_('location'...

Django ManyToMany relation add() error

Hi all, I've got a model that looks like this, class PL(models.Model): locid = models.AutoField(primary_key=True) mentionedby = models.ManyToManyField(PRT) class PRT(models.Model): tid = .. The resulting many to many table in mysql is formed as, +------------------+------------+------+-----+---------+----------------+ |...

Django: models last mod date and mod count

I have a django model called Blog. I'd like to add a field to my current model that is for last_modified_date. I know how to set a default value, but I would like somehow for it to get automatically updated anytime I modify the blog entry via the admin interface. Is there some way to force this value to the current time on each adm...

how to overwrite User model

I don't like models.User, but I like Admin view, and I will keep admin view in my application. How to overwirte models.User ? Make it just look like following: from django.contrib.auth.models import User class ShugeUser(User) username = EmailField(uniqute=True, verbose_name='EMail as your username', ...) email = CharField(...

Django - Following a foriegn key relationship (i.e JOIN in SQL)

Busy playing with django, but one thing seems to be tripping me up is following a foreign key relationship. Now, I have a ton of experience in writing SQL, so i could prob. return the result if the ORM was not there. Basically this is the SQL query i want returned Select table1.id table1.text table1.user table2.user_name tab...

Choose the filename of an uploaded file with Django

I'm uploading images (represented by a FileField) and I need to rename those files when they are uploaded. I want them to be formated like that: "%d-%d-%s.%s" % (width, height, md5hash, original_extension) I've read the documentation but I don't know if I need to write my own FileSystemStorage class or my own FileField class or ... ? ...

Limit choices to

I have a model named Project which has a m2m field users. I have a task model with a FK project. And it has a field assigned_to. How can i limit the choices of assigned_to to only the users of the current project? ...

Django TimeField Model without seconds

Greetings, I am trying to implement a TimeField model which only consists of HH:MM (ie 16:46) format, I know it is possible to format a regular Python time object but I am lost about how to manage this with Django. Cheers ...

Django: Structure Django Model to allow Arbitrary Fieldtypes

I'd like to make a user profile app in Django (I know there are some that exist, thanks) and I'm wondering how you would structure the models to allow for an arbitrary combination fields in each sub-section. As an example, the section 'education' may have a sub-section called 'Programming Experience', and the section 'personal info' may...

Django find in joined set

When i have, say, a Datamodel named "Computer", and there are many Users for many Computers, I create a manytomany-relationship between "Computer" and "User". Now I want to select any Computer that is used by User 1. I tried this: computers = Computer.objects.filter(users__contains=1) But this does not seem to work since the __contain...