I have a model:
class Person (models.Model):
name = models.CharField ()
birthday = models.DateField ()
age = models.IntegerField ()
I want to make age field to behave like a property:
def get_age (self):
return (datetime.datetime.now() - self.birthday).days // 365
age = property (get_age)
but a...
I am curious which one would be better fitting as a currency field ? I will do simple operations such as taking difference, the percentage between old and new prices. I plan to keep two digits after the zero (ie 10.50) and majority of the time if these digits are zero, I will be hiding these numbers and display it as "10"
ps: Currency i...
Say I have a model object 'Person' defined, which has a field called 'Name'. And I have a list of people:
l = ['Bob','Dave','Jane']
I would like to return a list of all Person records where the first name is not in the list of names defined in l.
What is the most pythonic way of doing this?
EDIT: After thinking about it, what I real...
I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model:
Ca...
Hi, all.
I have a model class like this:
class Note(models.Model):
author = models.ForeignKey(User, related_name='notes')
content = NoteContentField(max_length=256)
NoteContentField is a custom sub-class of CharField that override the to_python method in purpose of doing some twitter-text-conversion processing.
class NoteCon...
OK, I have the following directory structure (it's a django project):
-> project
--> app
and within the app folder, there is a scraper.py file which needs to reference a class defined within models.py
I'm trying to do the following:
import urllib2
import os
import sys
import time
import datetime
import re
import BeautifulSoup
sys...
The object user has a foreign key relationship to address. Is there a difference between samples 1 and 2? Does sample 1 run the query multiple times? Or is the address object cached?
# Sample 1
country = user.address.country
city = user.address.city
state = user.address.state
# Sample 2
address = user.address
country = address.count...
I'm writing a database of all DVDs I have at home.
One of the fields, actors, I would like it to be a set of values from an other table, which is storing actors. So for every film I want to store a list of actors, all of which selected from a list of actors, taken from a different table.
Is it possible? How do I do this? It would be a s...
I have a model name called StoreEntry. Django admin changes it to look like 'Store Entrys'. This is weird. If anything it should be Store entries. Any idea what's going on here and how to change it?
...
I'd like to create a form that includes fields from two separate models, along with some other regular (non-model) fields. The form will create an instance of each model. I don't think I can use inline formsets for this, since I don't want to include all the fields from both models.
I'd like to create the form field without hard-coding ...
I have a typical definition/instance situation in my data modeling. I'm trying to store the content_type of a GenericForeignKey in another model (the definition model) like so:
class IndicatorFieldInstance(models.Model):
definition = models.ForeignKey(IndicatorField)
object_id = models.PositiveIntegerField()
content_object =...
When trying to syncdb with the following models:
class Contact(models.Model):
user_from = models.ForeignKey(User,related_name='from_user')
user_to = models.ForeignKey(User, related_name='to_user')
class Meta:
unique_together = (('user_from', 'user_to'),)
User.add_to_class('following', models.ManyToManyField('self',...
In this topic I found a good way to prevent cascade deleting of relating objects, when it's not neccessary.
class Factures(models.Model):
idFacture = models.IntegerField(primary_key=True)
idLettrage = models.ForeignKey('Lettrage', db_column='idLettrage', null=True, blank=True)
class Paiements(models.Model):
idPaiement = mod...
Hello everybody
I am building a news app for my website. I want to use a sort of tag system. Each news article can have different and multiple tags. All tags are saved in a tag model, and i want to connect the tags to the newsarticle. Now is this possible with: tags = models.ForeignKey( TagsModel ) for one tag, but how i can do this wit...
Hello,
I am writing website and i`d like to implement profile managment. Basic thing
would be to edit some of user details by themself, like first and last name
etc. Now, i had to extend User model to add my own stuff, and email address.
I am having troubles with displaying form. Example will describe better what i
would like achi...
I have a model:
class Example(models.Model):
unique_hash = models.CharField(max_length=32,unique=True)
content = models.FileField(upload_to='source',blank=True,verbose_name="HTML Content File")
I would like to be able to set the content filename to default to a callable, but I don't see any way to have the callable reference u...
Hi all,
I have an extended userprofile with AUTH_PROFILE_MODULE (ref: http://tinyurl.com/yhracqq)
I would like to set a user.is_guru() method similar to user.is_active(). This would results for al views (or rather templates) to e.g. disable/enable certain user messages, displaying of widgets, etc. The boolean is stored in the extended ...
Has anyone else noticed performance issues using Django's F() object? I am running Windows XP SP3 and developing against the Django trunk. A snippet of the models I'm using and the query I'm building are below. When I have the F() object in place, each call to a QuerySet method (e.g. filter, exclude, order_by, distinct, etc.) takes ap...
Django's post_save signal behaves weirdly with models using multi-table inheritance
I am noticing an odd behavior in the way Django's post_save signal works when using a model that has multi-table inheritance.
I have these two models:
class Animal(models.Model):
category = models.CharField(max_length=20)
class Dog(Animal):
co...
How to query Employee to get all the address related to the employee, Employee.Add.all() does not work..
class Employee():
Add = models.ManyToManyField(Address)
parent = models.ManyToManyField(Parent, blank=True, null=True)
class Address(models.Model):
address_emp = models.CharField(max_length=512)
description = mo...