I have a (pre-existing) table witha column 'foo'. I want the model to have a property 'bar' which maps to foo.
I already use
class Meta:
db_table = u'actual_table_name'
to remap classes/tables from the default table name. Is there a similar way to do this for properties/fields?
Thanks,
Chris.
P.S. This seems like a very sim...
Hi folks,
I'm serving a Python app through Django. Within the app I'm storing the classic "created" field within a few tables.
This is how the field looks like within the Django form:
created = models.DateTimeField(blank=True, default=datetime.now())
Unfortunately, datetime.now() is not accurate. In fact in the database I have set...
I am building a site where users can make changes to their publicaly displayed profile. However I need all changes to be approved by an admin before going live. Until the changes are approved their old profile will be displayed. In the admin there should be a list of profiles awaiting approval. It is preferable, but not required, to keep...
For instance, I have a model called Person, and it has a bool field called 'isAthlete'. I would like to be able to check off True for 50 of these Person records, and then hit submit, without having to go into each Person model record and make the change. Is there an easy or already provided way to set this up in Django?
...
For instance, given a model A, and a model B, where A are unique records, and B are records that have Foreign Keys to A, how would you go about getting a set of A where those in the set are referenced by B at least n or more times?
...
Hi.
Ok, i'm shit at describing. Here's a relationship diag.
In Django i've made my models like:
from django.db import models
from datetime import datetime
class Survey(models.Model):
name = models.CharField(max_length=100)
pub_date = models.DateTimeField('date published',default=datetime.now)
def __unicode__(self):
...
I've defined a User class which (ultimately) inherits from models.Model. I want to get a list of all the fields defined for this model. For example, phone_number = CharField(max_length=20). Basically, I want to retrieve anything that inherits from the Field class.
I thought I'd be able to retrieve these by taking advantage of inspect.ge...
I have such file order:
project/
app/
models.py
signals.py
I am keeping signals inside signals.py as it should be. and at the top of the signals.py file, I include myapp models as I do queries in these signals with
from myproject.myapp.models import Foo
However it doesnt seem to find it, as I run the server or ...
The following code is given:
class BaseMedium(models.Model):
title = models.CharField(max_length=40)
slug = models.SlugField()
class A(BaseMedium):
url = models.URLField()
class B(BaseMedium):
email = models.EmailField()
I now want to query every BaseMedium.
b = BaseMedium.objects.all()
How do I print every infor...
how I can accomplish this without losing data? someone know how to do that? thanks to all.
...
My model:
class Order(models.Model):
property_a = models.CharField()
property_b = models.CharField()
property_c = models.CharField()
Many users will access a given record in a short time frame via admin change page, so I am having concurrency issues:
User 1 and 2 open the change page at the same time. Assume all values a...
Here is my model
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe)
ingredient = models.ForeignKey(Ingredient)
serving_size = models.ForeignKey(ServingSize)
quantity = models.IntegerField()
order = models.IntegerField()
created = models.DateTimeField(auto_now_add = True)
updated = models...
I have two different Django projects that are meant to run in parallel and do pretty different things.
However they need to share a common database table, the Client table..
Both projects contains multiple apps that needs to contain foreign keys mapped to that Client model..
I'm not sure what would be the best approach..
...
I found this post and it was very useful, but i need put the logEntry model into read-only in the admin interface, its that possible?
thanks and sorry for my english!
...
[Update: Changed question title to be more specific]
Sorry if I didn't make the question very well, I can't figure how to do this:
class WhatEver():
number = model.IntegerField('Just a Field', default=callablefunction)
...
Where callablefunction does this query:
from myproject.app.models import WhatEver
def callablefunction():
...
I have some django models for my extended users profile. Problem is that this code does not create tables when syncdb is used (simply nothing happens. No validation errors). Why is that happening? (Also those models give import error elsewhere) :
#!/usr/bin/env python
# encoding: utf-8
from django.db import models
from django.contrib.au...
My code:
class School(models.Model): pass
class Student(models.Model):
school = models.ForeignKey(School)
TYPE_CHOICES = (
('ug', 'Undergraduate'),
('gr', 'Graduate'),
('al', 'Alumnus'),
)
type = models.CharField(max_length=2)
How do I obtain a QuerySet of Schools ordered by the number of Under...
Hi!
So, time for a newbie question but so utterly important since the documentation seems to have missed this very very basic example.
All I'm trying to do is to return a value from a model to a view in Django. Here is some code.
The model
class Page(models.Model):
def index(self):
ex = 'foo string'
return ex
The vie...
With the following code:
from django.db import models
class Blogpost(models.Model): pass
class Vote(models.Model):
question = models.ForeignKey(Blogpost)
TYPE_CHOICES = (
('up', 'Up-Votes'),
('dn', 'Down-Votes'),
)
type = models.CharField(max_length=2, choices=TYPE_CHOICES)
What is the best way to obt...
Hi,
I'm practicing on Django and using some online tutorial to build a web blog. It went smoothly with the first project, yet when I tried the 2nd one, through developing the first view, there was this statement:
categories = models.ManyToManyField(Category, related_name ="packages")
In the tutorial, validating the model gives 0 er...