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...
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
...
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 ...
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...
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...
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?
...
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 ...
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...
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:...
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...
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,...
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...
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...
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...
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"...
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.
...
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 ...
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...
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
...
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...