django-models

Can I add a manager to a manytomany relationship?

I have two models that has a manytomany relationship with a 'through' table in some way? class Bike(models.Model): nickname = models.CharField(max_length=40) users = models.ManyToManyField(User, through='bike.BikeUser') The BikeUser class class BikeUser(models.Model): bike = models.ForeignKey(Bike) user = model...

Help with Django Query

Hi Guys: I need to make this Query using Django QuerySystem. SELECT DATE(`date`), count(*) FROM `maggie_item` GROUP BY DATE(`date`) DESC My model: Item date = DateTime title = textfield I would appreciate your help ...

Python: how to use value stored in a variable to decide which class instance to initiate?

I'm building a Django site. I need to model many different product categories such as TV, laptops, women's apparel, men's shoes, etc. Since different product categories have different product attributes, each category has its own separate Model: TV, Laptop, WomensApparel, MensShoes, etc. And for each Model I created a ModelForm. Hence ...

Select DISTINCT individual columns in django?

I'm curious if there's any way to do a query in Django that's not a "SELECT * FROM..." underneath. I'm trying to do a "SELECT DISTINCT columnName FROM ..." instead. Specifically I have a model that looks like: class ProductOrder(models.Model): Product = models.CharField(max_length=20, promary_key=True) Category = models.CharFi...

error with django model query

hi guys, I encountered an error when doing the following retrieval: class status(models.Model): pid = models.IntegerField() phase = models.TextField() rejected = models.IntegerField() accepted = models.IntegerField() type = models.IntegerField(default=1) date = models.DateTimeField(primary_key = True) time_t...

Runtime model generation using django

I have an application that needs to generate its models on runtime. This will be done according to the current database scheme. How can it be done? How can I create classes on runtime in python? Should I create a json representation and save it in a database and then unserialize it into a python object? ...

Displaying page content using django-page-cms

I would like to display some content located in my models in some of my template pages. I am using django-page cms In the documentation views are not used to display content. Instead ready made template tags are used. http://packages.python.org/django-page-cms/display-content.html I do not understand a word of this. Please Bear with ...

django project directory structure and the python path

I am trying to get the best possible set up for developing my django project from the start and I'm having trouble getting everything to play nicely in the directory structure. I have set up virtualenv's (env in this example) so that I can deploy a clean empty python environment for every django project. The basic structure is as follow...

How to write this class for Django's data model (converting from Propel's YML format)

I am converting a web project that currently uses the Propel ORM, to a django project. My first task is to 'port' the model schema to django's. I have read the django docs, but they do not appear to be in enough detail. Case in point, how may I 'port' a (contrived) table defined in the Propel YML schema as follows: demo_ref_country:...

Django Models: Subclassing approach?

Hello Stacker's & Django-ists, I'm looking for some validation on a subclassing approach. I have the following: class Person(models.Model): """ Basic person """ user = models.ForeignKey(User) # hide first_name = models.CharField(max_length=200) last_name = models.CharField(blank=True, max_length=200) class...

What are the full implications of not using the default 'id' primary_key in your Django model?

Consider the case where a CHAR field primary_key is required in order to define a ForeignKey relationship. After some initial investigation I have identified the following possibilities, each with their own drawbacks: 1) Using 'primary_key=True'. Example 1: class Collection(models.Model): code = models.CharField(primary_key=True,...

Error using a base class field in subclass unique_together meta option

Using the following code: class Organization(models.Model): name = models.CharField(max_length="100",) alias = models.SlugField() ... class Division(Organization): parent_org = models.ForeignKey(Organization) class Meta: unique_together=['parent_org', 'alias'] ... Trying to syncdb give me this err...

Django model inheritance problem. How to solve?

Hello all, I have an existing app with the following model class Contact(models.Model): lastname = models.CharField(max_length=200) firstname = models.CharField(max_length=200) ... class Journalist(Contact): pass I have a Contact in my database and I would like that it becomes a Journalist. In raw sql, it seems...

Manager isn't accessible via model instances

Hi, i'm trying to get model objects instance in another one. And i raise this error : Manager isn't accessible via topic instance Here's my model : class forum(models.Model): # Some attributs class topic(models.Model): # Some attributs class post(models.Model): # Some attributs def delete(self): forum = se...

mysql exception when synchronizing db with django's manage.py script

I am relatively new to django. I have defined my db schema and validated it with no errors (manage.py validate reports 0 errors found). Yet when I run ./manage.py syncdb I get the following stack trace: Creating table demo_foobar_one Creating table demo_foobar_two <snip>...</snip> Traceback (most recent call last): File "manage.py"...

Setting the variable 'db_table' does not include the app prefix to table names

When using 'db_table' to explicitly set the database table name, how can you preserve the naming convention of "app_table_name"? The app name is removed. ...

How do I write a Django model with ManyToMany relationsship with self through a Model

I want to have a model with a ManyToMany relationship with itself, I don't know how to write this but I'l try to write some code to illustrate what I want to do. class Person(models.Model): name = models.CharField() occupation = models.CharField() fiends = models.ManyToManyField('self', through = PersonFiends) My Model that ...

Does django grok YML ? django not loading fixtures YML file (yml is not a known serialization)

I have successfully created my first django project. I have two apps in my project foo and foobar. I have created a folder named 'fixtures' in each of the app folders. I have NOT specified a fixtures directory in my settings.yml, so (according to the docs), django should be looking in my {app}/fixtures folder. In the {app}/fixtures fo...

Django query performance using FOO_set

Hey, Does Django hit the database again when making queries following relationships backwards using the FOO_set manager? I thought I read somewhere that it does not but I can't find it in the docs anywhere. J ...

Summing on only the most recently added record

I'm having a hard time wrapping my head around this Django query. I could probably figure this out with SQL (and maybe I'll have to), but I was wondering if there is a way to do it with Django objects. The model looks something like this (simplified for clarity): class Stat(model.Models): entry_date = models.DateTimeField() qua...